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:
- 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>
- 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 aro.sync.ecss.dita.ContextKeyManagerProvider
parameter. - Create a
MyDITAExtensionsBundle
Java source file that extendsro.sync.ecss.extensions.dita.DITAExtensionsBundle
. Override thecreateAuthorReferenceResolver
method to return an instance ofMyConrefResolver
passing thekeyManagerProvider
field of the base class to the constructor.Note: TheMyConrefResolver
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 theDITAConRefResolver
, this causes keys to not be resolved in Web Author. - Create a JAR file with your compiled Java classes and add it to your framework's classpath using the Document Type Configuration dialog box.