Version 9.6
 —  Importing Objects Using the API  —

Writing Your Own Importer

You can write your own plug-in for CentraSite Control to incorporate your own importer. The prepared plug-in is a collection of files in a specific directory structure. After implementing the plug-in, the files must be copied into the CentraSite Control webapps folder under:

<RuntimeWebAppsDir>/PluggableUI/<MyPluginFolder>

(The location of the <RuntimeWebAppsDir> folder is described in the document Basic Operations).

The folder <MyPluginFolder> must contain the following files and folders:

Name of File or Folder Description
plugin.xml Top plug-in description file
*.html Files generated for the GUI (see build.xml)
*_SWT.xml Files generated for the GUI (see build.xml)
images Directory for icons (GIF files)
lib Directory for JAR files provided by the plug-in
accesspath Directory created by HTML generation (see build.xml)

In the following sections, we demonstrate a framework named ImportMyFile that illustrates how an import plug-in may be set up. The example extends the import selection list and presents a screen that prompts for the file to be imported. After confirming the file, the appropriate adapter classes are called.

You may use this example as a guideline, adapting it and renaming it to suit your individual requirements. The templates indicate where customization is required.

The following topics are discussed in this document:


The Build Environment

This section explains the build environment for generating the HTML files that are used for the GUI and for compiling the necessary Java source files. It assumes the use of Ant (http://ant.apache.org/), the Java-based build tool.

The following file system structure under the plug-in directory is assumed:

Name of File or Folder Description
src The directory that holds the Java source files
xml The directory that holds the XML file that specifies your import window
plugin.xml Top plugin description file that specifies the extension point and the command class
build.xml The Ant input file for building the destination files

The Ant file shown below, named build.xml, can be used to establish an import plug-in. Look for the properties with the following names:

plugin.name
plugin.provider
tomcat.dir
tomcat.ver.dir

and modify them as required to suit your installation.

build.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="./ant2html.xsl"?>
<!--
  Build an Import plugin
-->

<project name="Import Plugin Example" default="all" basedir=".">

  <description> Build file for an Importer plugin </description>

  <!-- environment -->
  <property environment="env"/>

  <property name="plugin.name" value="ImportMyFile" />
  <property name="plugin.provider" value="Software AG" />

  <!-- tomcat home directory -->
  <!-- <property name="tomcat.dir" value="tomcat directory of installation" /> -->
  <property name="tomcat.dir" value="C:/SoftwareAG/profiles/CTP" />
  <property name="tomcat.ver.dir" value="${tomcat.dir}/workspace"/>

  <!-- point to the root of the pluggableUI to get the cis environment -->
  <property name="pluggable.ui.root" value="${tomcat.ver.dir}/webapps/PluggableUI"/>

  <!-- the directory containing source code -->
  <property name="plugin.dir" value="../${plugin.name}" />
  <property name="src.dir"    value="${plugin.dir}/src" />
  <property name="xml.dir"    value="${plugin.dir}/xml" />
  <property name="classes"    value="${plugin.dir}/classes" />
  <property name="lib"        value="${plugin.dir}/lib" />

  <!-- classpath -->
  <path id="plugin.class.path">
    <fileset dir="${pluggable.ui.root}/CentraSiteControl/lib">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${pluggable.ui.root}/WEB-INF/lib">
      <include name="*.jar"/>
    </fileset>
  </path>


  <!-- default target, build all -->
  <target name="all" description="all" depends="jar, zip"/>

  <!-- establish jar file of plugin -->
  <target name="jar" depends="compile" description="jar">
    <mkdir dir="${lib}" />
    <jar destfile="${lib}/${plugin.name}.jar">
      <fileset dir="${classes}"/>
      <fileset dir="${src.dir}" includes="**/*.properties"/>
      <manifest>
        <section name="com/centrasite/control">
          <attribute name="Implementation-Title" value="${plugin.name}"/>
          <attribute name="Implementation-Version" value="1.0.0.0"/>
          <attribute name="Implementation-Vendor" value="${plugin.provider}"/>
        </section>
      </manifest>
    </jar>
  </target>

  <!-- compile java sources -->
  <target name="compile" description="compile" depends="">
    <mkdir dir="${plugin.dir}/accesspath" />
    <mkdir dir="${classes}" />
    <javac srcdir="${src.dir}" destdir="${classes}" debug="on"
           classpathref="plugin.class.path" />
  </target>
  
  <!-- Create plugin archive -->
  <target name="zip" description="package the plugin" depends="">
     <zip destfile="${plugin.name}.zip" basedir="${plugin.dir}/.." 
                                        includes="${plugin.name}/lib/**,
                    ${plugin.name}/accesspath/**, ${plugin.name}/plugin.xml,
                                                  ${plugin.name}/*_SWT.xml,
                    ${plugin.name}/xml/** ${plugin.name}/*.html" />
  </target>


  <!-- Install plugin zip to PluggableUI -->
  <target name="install" description="Install plugin zip to PluggableUI">
      <java classname="com.softwareag.cis.plugin.ext.plugins.command.InstallPlugInCommand"
            fork="true">
            <arg value="-t" />
            <arg value="${pluggable.ui.root}" />
            <arg value="-z" />
            <arg value="${plugin.name}.zip" />      
            <classpath>
                <fileset dir="${pluggable.ui.root}/WEB-INF/lib">
                    <include name="*.jar"/>
                </fileset>
            </classpath>
      </java>
  </target>
    
  <!-- Uninstall plugin zip from PluggableUI -->
  <target name="uninstall" description="Uninstall plugin zip from PluggableUI">
    <delete dir="${pluggable.ui.root}/${plugin.name}" />
  </target>

  <!-- Cleanup objects -->
  <target name="clean" description="clean classes lib and generated files">
    <delete dir="${classes}" />
    <delete dir="${plugin.dir}/accesspath" />
    <delete dir="${lib}" />
    <delete file="${plugin.name}.zip" />
  </target>
  
</project>

The classpath for the build step must comprise all JAR files used by the UI. Add these JAR files to the build path of your java project also.

As mentioned above, in order to present a user-defined screen when the plug-in's import button is clicked, an XML file that describes the GUI must be located in the subdirectory xml. The example XML file simply prompts for a filename:

xml/ImportMyFile.xml
<?xml version="1.0" encoding="UTF-8"?>
<page model="com.importer.myfile.control.ImportMyFileAdapter">
    <pagebody>
        <rowarea withleftborder="false" withtopborder="false"
                 withrightborder="false" withbottomborder="false"
                 withtoppadding="false"
                 paddingleft="10" paddingright="10">
            <vdist height="30"></vdist>
            <itr>
                <label name="File:" width="100" asplaintext="true"></label>
                <fileupload2 width="100%" cfileprop="fileClientUrl"
                             fileprop="fileServerUrl"
                             method="fileLoaded"></fileupload2>
            </itr>
            <vdist height="30"></vdist>
        </rowarea>
    </pagebody>
    <statusbar></statusbar>
</page>

Top of page

The Plug-In Environment

The master file of the plug-in is plugin.xml:

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 section 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.

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:

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 command:

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.

Top of page

Propagating the Plug-In

Having generated the plugin files, they must be propagated into the directory PluggableUI of the installed CentraSite Control. Thus, for example, the plug-in "ImportMyFile" (shown above) should have the following directory/file structure:

.../PluggableUI/ImportMyFile /
    accesspath /
        ImportMyFile.access
    images /
        ImportMyFile.gif
    lib /
        ImportMyFile.jar
    ImportMyFile.html
    ImportMyFile_JLIBS.html
    ImportMyFile_SWT.xml
    plugin.xml

You can do this by executing the following command, which installs ImportMyFile.zip into the PluggableUI folder:

ant -f build.xml install

Top of page

Generating all additionally needed files

You only need this step if you are not able to install the necessary files directly in the <RuntimeWebAppsDir>/PluggableUI/ directory. In this case, you have to build the structure shown above by yourself. You can automatically generate the .html files as well as the _SWT.xml and the .accesspath file using the Software AG Application Designer.

First edit the file stored in the following directory: <TomcatWebAppsDir>/PluggableUI/cis/config/cisconfig.xml.

Insert the statement: plugindevelopment="true" in the following part:

designtimeclassloader="com.softwareag.cis.plugin.registry.loader.AdapterPluginClassLoader"
  enableadapterpreload="true"
  framebuffersize="3"
  plugindevelopment="true"
  loglevel=""
  logtoscreen="false"	
  maxitemsinfieldcombo="100"

After that, restart the Software AG Runtime. Now you can start the Application Designer with the following URL: http://localhost:53307/PluggableUI/HTMLBasedGUI/workplace/ide.html.

Navigate to "Tools & Documentation > Layout Manager" and choose the "ImportMyFile" Plugin as Application Project. It appears in the Layout Definitions List. Click on it and generate all additionally needed files using the button "Operations on multiple Items > (Re)Generate HTML pages".

Top of page

Activating the Plug-In

Start of instruction setTo activate the plug-in

  1. Restart the Software AG Runtime.

  2. Start CentraSite Control.

  3. Choose the Import function. You will see the name of your plug-in in the Import as selection list.

    Select the name of your plug-in and click Next.

  4. Enter the name of the file to be imported, then click Finish.

Top of page

Deactivating the Plug-In

Start of instruction setTo deactivate the plug-in

  1. Run the command:

    ant -f build.xml uninstall
  2. Restart the Software AG Runtime.

  3. Start CentraSite Control.

Top of page