Edit online


I have a bunch of DITA documents that have a fixed path the image src attributes. These paths are not valid and I am trying to move away from this practice by converting it in to relative paths. When an XML document is opened, can I trigger the Java API to change the fixed path to a relative path?


The Plugins SDK contains a sample plugin type called WorkspaceAccess. Such a plugin is notified when the application starts and it can do what you want in a couple of ways:

  1. Add a listener that notifies you when the user opens an XML document. Then if the XML document is opened in the Author visual editing mode you can use the Author API to change attributes:
       pluginWorkspaceAccess.addEditorChangeListener(new  WSEditorChangeListener() {
           * @see WSEditorChangeListener#editorOpened(java.net.URL) 
          public void editorOpened(URL editorLocation) {
            WSEditor openedEditor = pluginWorkspaceAccess.getCurrentEditorAccess
            if(openedEditor.getCurrentPage() instanceof WSAuthorEditorPage) {     
            WSAuthorEditorPage authPage = (WSAuthorEditorPage)  
            AuthorDocumentController docController = 
            try {
             //All changes will be undone by pressing Undo once.            
            } finally {       
          private void fixupImageRefs
    (AuthorDocumentController docController, AuthorNode authorNode) {
              if(authorNode instanceof AuthorParentNode) {
                List<AuthorNode> contentNodes = 
                if(contentNodes != null) {
                   for (int i = 0; i < contentNodes.size(); i++) {
                     fixupImageRefs(docController, contentNodes.get(i));
              if(authorNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {   
                AuthorElement elem = (AuthorElement) authorNode;         
                if("image".equals(elem.getLocalName())) {           
                   if(elem.getAttribute("href") != null) {
                     String originalHref = elem.getAttribute("href").getValue();
        URL currentLocation = docController.getAuthorDocumentNode().getXMLBaseURL();
                    //TODO here you compute the new href.
                    String newHref = null;   
                  docController.setAttribute("href", new AttrValue(newHref), elem); 
  2. An API to open XML documents in the application:
    So you can create a plugin that automatically opens XML documents one at a time from a certain folder in the application, makes modifications to them, and saves the content by calling:
    then closes the editor by calling: