Page 1 of 1

Customized ID Generation

Posted: Wed Feb 05, 2020 12:15 am
by kirkilj
Oxygen's UI allows us to configure a single pattern to use for all the listed elements in the ID Options dialog. According to the API docs, there's a generateUniqueIDFor method in the DefaultUniqueAttributesRecognizer class, which can be extended to override behavior. Since it's not available in the UI, we'd like to use one pattern for topic-level elements (topic,troubleshooting, reference, task, concept) to include a prefix representing the short-name for the relevant product followed by a logical name for the content. We use a constellation of Git submodules to pull in reused content that's needed for a "host" document.

For other block and inline elements, we'd prefer to leave off such a product-short-name and indicate the element name as the prefix followed by a logical name. We have a custom editor variable for this purpose, named "product-short-name", which is usually the acronym for the product. If we extend the above class, can we access any custom editor variable values within the generateUniqueIDFor method using a corresponding method?

I'd like one our devs to branch into Oxygen extension writing. They already know XSLT, Ant, Python, and Java somewhat. I'm having difficulty reaching the maven repo for the sdk for 21.1.0.2, even with maven proxies defined in my settings.xml, so it would a help if you had an existing sample or could offer a skeletal piece of code to do this. Javascript would be easier.

Re: Customized ID Generation

Posted: Wed Feb 05, 2020 12:19 pm
by Radu
Hi John,

Please see some answers below:
If we extend the above class, can we access any custom editor variable values within the generateUniqueIDFor method using a corresponding method?
Yes, you can use the following API to expand in the Java code any editor variable or any text containing editor variables:

Code: Select all

ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().expandEditorVariables("${product-short-name}", null)
https://www.oxygenxml.com/InstData/Edit ... ccess.html
I'd like one our devs to branch into Oxygen extension writing. They already know XSLT, Ant, Python, and Java somewhat. I'm having difficulty reaching the maven repo for the sdk for 21.1.0.2, even with maven proxies defined in my settings.xml, so it would a help if you had an existing sample or could offer a skeletal piece of code to do this. Javascript would be easier.
We can help your developer with source code.
So if you run in the command line this command:

Code: Select all

mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.oxygenxml.samples -DarchetypeArtifactId=oxygen-sdk-samples-archetype -DarchetypeVersion=21.1.0.2 -DgroupId=myGroup -DartifactId=mySample  -Dversion=1.0-SNAPSHOT -DarchetypeRepository=http://oxygenxml.com/maven/
what exactly is the error reported by the Maven process?
An alternative is to start a new Java project, add in its class path all the JAR libraries from the "OXYGEN_INSTALL_DIR\lib" folder plus the "OXYGEN_INSTALL_DIR\frameworks/dita/dita.jar".
Then create a Java class which extends the "DITAExtensionsBundle", it's code would look like this:

Code: Select all

public class DITA2ExtensionsBundle extends ro.sync.ecss.extensions.dita.DITAExtensionsBundle {

  private DITAUniqueAttributesRecognizer attrsRecognizer;
  
  /**
   * @see ro.sync.ecss.extensions.dita.DITAExtensionsBundle#getUniqueAttributesIdentifier()
   */
  @Override
  public UniqueAttributesRecognizer getUniqueAttributesIdentifier() {
    return attrsRecognizer;
  }
  
  /**
   * @see ro.sync.ecss.extensions.dita.DITAExtensionsBundle#createAuthorExtensionStateListener()
   */
  @Override
  public AuthorExtensionStateListener createAuthorExtensionStateListener() {
    AuthorExtensionStateListener superListener = super.createAuthorExtensionStateListener();
    AuthorExtensionStateListenerDelegator delegator = new AuthorExtensionStateListenerDelegator();
    delegator.addListener(superListener);
    
    attrsRecognizer = new DITAUniqueAttributesRecognizer() {
      /**
       * @see ro.sync.ecss.extensions.commons.id.DefaultUniqueAttributesRecognizer#generateUniqueIDFor(java.lang.String, ro.sync.ecss.extensions.api.node.AuthorElement)
       */
      @Override
      protected String generateUniqueIDFor(String idGenerationPattern, AuthorElement element) {
        //TODO your code here
        //Or call the super implementation if you want 
//        return super.generateUniqueIDFor(idGenerationPattern, element);
        return "custom";
      }
    };
    delegator.addListener(new AuthorExtensionStateListener() {
      
      @Override
      public String getDescription() {
        return attrsRecognizer.getDescription();
      }
      
      @Override
      public void deactivated(AuthorAccess authorAccess) {
        attrsRecognizer.deactivated(authorAccess);
      }
      
      @Override
      public void activated(AuthorAccess authorAccess) {
        attrsRecognizer.activated(authorAccess);
      }
    });
    return delegator;
  }
}
Package the DITA2ExtensionsBundle in a JAR library, then in the Document Type Associations page extend the DITA framework to a new framework folder, something like this:

https://blog.oxygenxml.com/2016/10/cust ... iting.html

Your new framework folder will have its own "lib" folder with the custom JAR.
Edit the framework customization so that the "Classpath" tab has a reference to this new JAR library and then in the "Extensions" tab choose the custom DITA2ExtensionsBundle implementation instead of the base DITAExtensionsBundle.

About using Javascript instead of Java, we have that for plugins but not for framework customizations.

Regards,
Radu