4.4.3. Editor Plug-ins

As an example of creating an editor plug-in, we'll extend the viewer plug-in created in Section 4.4.2, “Viewer Plug-ins”. In addition to viewing, the editor plug-in shall also allow editing of text files and content nodes (XHTML). The steps for creating an editor plug-in are the same as for creating a viewer plug-in, except that additionally the content handler methods getSupportedEditExtensions and openEditor have to be implemented as required. Furthermore, in case of an XHTML editor, if the encoding of special characters as defined in the Docmenta configuration has to be supported, then the setCharEntities method needs to be implemented accordingly.
We start by creating a class that implements the org.docma.plugin.web.ContentAppHandler interface. You can either create a new class from scratch, or you can extend the org.docma.plugin.web.DefaultContentAppHandler class, which provides a default implementation.
For this example, we'll create a class from scratch. The class name shall be myexample.MyTextEditor: If you have already created the example from Section 4.4.2, “Viewer Plug-ins”, then you can create a copy of MyTextViewer.java and rename it to MyTextEditor.java:
package myexample;

import java.io.File;
import org.docma.plugin.web.ContentAppHandler;

public class MyTextEditor implements ContentAppHandler
    private File relativePath;
    private String relativeURL;
    private String applicationId;

    // To do: implement the interface methods
In the class fragment given above, three private fields are declared that are used in the method implementations. The methods initialize, getApplicationId, getApplicationName, getSupportedViewExtensions, getPreviewURL, openViewer and setCharEntities are identical to the implementations given in Section 4.4.2, “Viewer Plug-ins”. Following a description of the remaining methods. The complete source code of the class is given afterwards.