CentraSite 10.7 | CentraSite Developer's Guide | Importing Objects Using API | Writing Your Own Importer | The Plug-In Environment
 
The Plug-In Environment
The master file of the plug-in is plugin.xml:
<plugin id="com.importer.myfile" order="101">
<requiredPlugin id="com.centrasite.control" />
<requiredPlugin id="com.softwareag.cis.plugin" />
 
<!-- Import extension (point to command execution class) -->
<extension point="com.centrasite.control.import"
id="importMyFileCommand"
class="com.importer.myfile.control.ImportMyFileCommand">
</extension>
</plugin>
This file specifies the command class, which is used to select the user's import function. It must be derived from com.centrasite.control.extpt.AbstractImport.
Note:
This topic does not explain all the details of the Java source file, its purpose is to indicate the code that must be modified to suit your environment.
Here is src/com/importer/myfile/control/ImportMyFileCommand.java:
package com.importer.myfile.control;
 
import com.centrasite.control.extpt.AbstractImport;
import com.centrasite.control.ActionContext;
public class ImportMyFileCommand extends AbstractImport
{
static final String
IMPORT_NAME = "Import MyFile"; // Appears in the import list
static final String
HTML_PAGE = "/ImportMyFile/ImportMyFile.html";
static final String
MY_IMAGE = "../ImportMyFile/images/importMyFile.gif";
static final String
CALLING_ADAPTER = "com.importer.myfile.control.ImportMyFileAdapter";
// point to the adapter class
 
public ImportMyFileCommand() {
}
 
public String getName() {
return IMPORT_NAME;
}
 
public String getImageURL() {
return MY_IMAGE;
}
 
public String getLayout() {
return HTML_PAGE;
}
 
public String getPageDescription() {
return "XPDL v.1 Importer";
}
 
public void execute(ActionContext actionContext) {
actionContext.showPage(HTML_PAGE, getName(), CALLING_ADAPTER);
}
}
This class defines the paths of the image file for your private icon, the HTML file used and the class of the import adapter.
Here is the frame of an import adapter (this is src/com/importer/myfile/control/ImportMyFileAdapter.java):
package com.importer.myfile.control;
 
import java.util.Collection;
import javax.xml.registry.JAXRException;
import com.centrasite.control.AbstractBrowseCommand;
import com.centrasite.control.ActionContext;
import com.centrasite.control.Connector;
import com.centrasite.control.adapters.BaseAdapter;
import com.centrasite.control.adapters.util.ImportAdapter;
import com.centrasite.control.discovery.PromptYesNoHandler;
import com.centrasite.control.logged.action.LoggedExecutor;
import com.centrasite.control.logged.action.LoggedSchemaImport;
import com.centrasite.control.interfaces.Initializable;
import com.centrasite.jaxr.JAXRAccessor;
import com.softwareag.cis.plugin.interfaces.RunnableDeferred;
 
/**
* Import adapter
*/
public class ImportMyFileAdapter extends BaseAdapter
implements Initializable,ImportAdapter
{
private static final String TITLE = "Import MyFile";
 
private String fileTmpUrl;
private String fileAtServer;
private String fileAtClient;
 
public ImportMyFileAdapter() {
fileAtServer = fileAtClient = fileTmpUrl = null;
}
public void initialize(Collection<Object> objs){}
 
public void setOrganization(String org){}
 
public boolean execute() {
callFinish();
return true;
}
 
public String getFileClientUrl() {
return fileAtClient;
}
 
public void setFileClientUrl(String value) {
fileAtClient = value;
}
 
public String getFileServerUrl() {
return fileTmpUrl;
}
 
public void setFileServerUrl(String value) {
fileTmpUrl = value;
}
 
public void fileLoaded() {
fileAtServer = fileTmpUrl;
}
 
public void callCancel() {
super.endProcess();
}
 
private static boolean isWhiteSpace(String s)
{
if (s == null || s.length() == 0) return true;
for (int i=0 ; i < s.length() ; ++i) {
if (!Character.isWhitespace(s.charAt(i))) return false;
}
return true;
}
 
/**
* Called if "OK" button has been pressed
*/
public void callFinish() {
if (isWhiteSpace(fileAtServer))
{
outputMessage(MT_ERROR, "no file entered");
}
else
{
ImportMyFile ie = new ImportMyFile(getConnector(),
fileAtServer, fileAtClient);
ie.doImport();
}
}
 
/**
* Class for importing specific files
*/
private class ImportMyFile extends AbstractBrowseCommand
implements RunnableDeferred, PromptYesNoHandler
{
private Connector connector;
private JAXRAccessor jaxr;
 
public ImportMyFile(Connector connector, String fileAtServer,
String fileAtClient){
// fileAtClient is the filename you can access
this.connector = connector;
this.jaxr = null;
}
 
public void doImport() {
JAXRAccessor jaxr = null;
try {
LoggedSchemaImport lsi =
new LoggedSchemaImport(getActionContext());
jaxr = getJAXR();
// write here your import code to registry and repository
//setEventCallback( lsi.getEventCallback() );
// for event logging
 
// your import code can use the methods
// accept(javax.xml.registry.infomodel.RegistryObject ro)
// warning(javax.xml.registry.infomodel.RegistryObject ro)
// reject(javax.xml.registry.infomodel.RegistryObject ro)
// of the LoggedEventCallback class,
// to log the status of your import
 
new LoggedExecutor(lsi).execute();
}
catch (Exception e) {
throw new RuntimeException(e);
}
finally {
if (jaxr != null)
jaxr.close();
}
}
 
private JAXRAccessor getJAXR() throws JAXRException {
if (jaxr == null) {
jaxr = new JAXRAccessor(connector.getRegistryUrl(),
connector.getUserName(),
connector.getPassword());
}
return jaxr;
}
public void run() throws Exception {
doImport();
}
 
public void handleYes(ActionContext actionContext) {
doImport();
}
 
public void handleNo(ActionContext actionContext) {}
 
public void executeCommand(ActionContext actionContext,
String clientPath) {}
 
public void executeCommand(ActionContext actionContext,
String clientPath, String serverPath) {
actionContext.executeDeferred(this);
}
 
public int getCategory() {
return CATEGORY_MISC;
}
 
public String getImageURL() {
return null;
}
 
public String getTitle() {
return TITLE;
}
 
public String getName() {
return "";
}
 
public String getLabel() {
return "";
}
}
}
Assuming that you have set up all the Java files correctly in the directory src, you should be able to build with the build.xml command.
The syntax for the command is:
ant -f build.xml jar all
This creates the plug-in-specific JAR file in the subdirectory lib and archives the necessary plugin files into the file ImportMyFile.zip.