Chapter 10. Writing a plug-in

Table of Contents

1. What is a plug-in?
2. Steps needed to write, package and deploy a plug-in

1. What is a plug-in?

Unlike all the other kinds of extensions, plug-ins are self-registering extensions. The code of a plug-in is found in a .jar file defining a service. For example, the service definition file is META-INF/services/com.xmlmind.xmledit.imagetoolkit.ImageToolkit for an image toolkit plug-in. It's this service definition file which allows the plug-in to register itself with XXE.

There are three types of plug-ins:

XSL-FO processor plug-in

Converts XSL-FO to another format. Used in process commands (see Chapter 5, Process commands in XMLmind XML Editor - Commands).

Image toolkit plug-in

Allows XMLmind XML Editor to support images formats other than built-in GIF, JPEG and PNG.

Virtual drive plug-in

Allows XMLmind XML Editor to edit documents stored in places other than the local file system. This is done by emulating a hierarchical file system.

Document format plug-in

Allows to use XMLmind XML Editor to open, edit and save files other than XML documents, for example, plain text files.

2. Steps needed to write, package and deploy a plug-in

In all cases, the steps needed to write, package and deploy a plug-in are exactly the same:

  1. Implement the interface of the plug-in:

    Plug-in typeInterface
    XSL-FO processor plug-incom.xmlmind.foprocessor.FOProcessor (or extend the com.xmlmind.foprocessor.FOProcessorBase abstract base class).
    Image toolkit plug-incom.xmlmind.xmledit.imagetoolkit.ImageToolkit
    Virtual drive plug-incom.xmlmind.xmleditapp.vdrive.DriveFactory
    Document format plug-incom.xmlmind.xmleditapp.docformat.DocumentFormat
  2. The compiled code of the plug-in (.class files) and all the associated resources must be archived in a JAR file having a special basename:

    Plug-in typeJAR basenameExample
    XSL-FO processor plug-inprefix_foprocessor.jarxfc_foprocessor.jar
    Image toolkit plug-inprefix_imagetoolkit.jarbatik_imagetoolkit.jar
    Virtual drive plug-inprefix_vdrive.jardav_vdrive.jar
    Document format plug-inprefix_docformat.jartext_docformat.jar
  3. The JAR file must define a service, that is, it must contain a file called META-INF/services/interface_name.

    This file is a text file encoded in UTF-8 containing the fully qualified name of the class which implements the interface. Examples:

    Plug-in typeService definition file
    XSL-FO processor plug-in

    META-INF/services/com.xmlmind.foprocessor.FOProcessor contains:

    Image toolkit plug-in

    META-INF/services/com.xmlmind.xmledit.imagetoolkit.ImageToolkit contains:

    Virtual drive plug-in

    META-INF/services/com.xmlmind.xmleditapp.vdrive.DriveFactory contains:

    Document format plug-in

    META-INF/services/com.xmlmind.xmleditapp.docformat.DocumentFormat contains:

  4. The JAR file containing the code of the plug-in and the JAR files of the support code must be copied to a place where XXE will find them (see Section 1, “Dynamic discovery of add-ons” in XMLmind XML Editor - Configuration and Deployment). For example, copy them to XXE_user_preferences_dir/addon/. XXE user preferences directory is:

    • $HOME/.xxe8/ on Linux.

    • $HOME/Library/Application Support/XMLmind/XMLEditor8/ on the Mac.

    • %APPDATA%\XMLmind\XMLEditor8\ on Windows XP, Vista, 7, 8 and 10.

      Example: C:\Documents and Settings\john\Application Data\XMLmind\XMLEditor8\ on Windows XP. C:\Users\john\AppData\Roaming\XMLmind\XMLEditor8\ on Windows Vista, 7, 8 and 10.

      If you cannot see the "Application Data" directory using Microsoft Windows File Manager, turn on Tools>Folder Options>View>File and Folders>Show hidden files and folders.