Edit online

Writing Java Extensions for DITA

Although most of the editor configuration for a specific document type can be done using configuration files, for some of the most advanced customization requirements, you need to write Java extensions.

Such Java extensions can be registered using the Document Type Configuration dialog box. When extending a framework that already has Java extensions registered (such as DITA), you want to inherit the behavior of the extensions from the base framework.

Suppose you want to register an AuthorReferenceResolver subclass called MyConrefResolver. Here are the required steps:

  1. Create a Maven project for your Java extension and add the following dependencies:
    <dependency>
          <groupId>com.oxygenxml</groupId>
          <artifactId>oxygen-sdk</artifactId>
          <version>${oxygen.version}</version>
    </dependency>
    <dependency>
          <groupId>com.oxygenxml</groupId>
          <artifactId>oxygen-dita-extensions</artifactId>
          <version>${oxygen.version}</version>
    </dependency>
  2. Create a MyConrefResolver.java Java source file that contains your reference resolver implementation. To inherit the default behavior for resolving references, this class should extend the default reference resolver implementation for DITA: ro.sync.ecss.extensions.dita.conref.DITAConRefResolver. You can then override some of the methods according to your needs.
    Note: DITAConRefResolver has only one non-deprecated constructor, which receives a ro.sync.ecss.dita.ContextKeyManagerProvider parameter.
  3. Create a MyDITAExtensionsBundle Java source file that extends ro.sync.ecss.extensions.dita.DITAExtensionsBundle. Override the createAuthorReferenceResolver method to return an instance of MyConrefResolver passing the keyManagerProvider field of the base class to the constructor.
    Note: The MyConrefResolver can also be specified as an extension directly in the Document Type Configuration dialog box. However, if specified directly, the default constructor will be used. In the case of the DITAConRefResolver, this causes keys to not be resolved in Web Author.
  4. Create a JAR file with your compiled Java classes and add it to your framework's classpath using the Document Type Configuration dialog box.