How to set a root map programmatically ?

Post here questions and problems related to editing and publishing DITA content.
Vince
Posts: 64
Joined: Wed Dec 03, 2014 11:25 am

How to set a root map programmatically ?

Post by Vince »

Hi,

Is there any easy way to set a root map programmatically to a loaded map in the DITA map manager ?

Something like :

Code: Select all

URL url = new URL("...");
PluginWorkspaceProvider.getPluginWorkspace().open(url, "PAGE_DITA_ROOT_MAP");
Thank in advance for your help.

Vince
adrian_sorop
Posts: 73
Joined: Wed Jun 22, 2016 2:48 pm

Re: How to set a root map programmatically ?

Post by adrian_sorop »

Hi Vince,

The easiest way to set the root map from API is to use the KEYS_CONTEXT_MAP option.

Something like:

Code: Select all

URL contextMapToSet = new URL("");
PluginWorkspaceProvider.getPluginWorkspace().getOptionsStorage().setOption(APIAccessibleOptionTags.KEYS_CONTEXT_MAP, contextMapToSet.toExternalForm());
Regards,
Adrian

Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
Vince
Posts: 64
Joined: Wed Dec 03, 2014 11:25 am

Re: How to set a root map programmatically ?

Post by Vince »

Thanks for your reply Adrian

But, using this method, nothing appends on currently loaded map.
The specified root map is not selected in DITA MAP Manager combo box.
And any opened topic in the editor reports that the definition of keys are not found.

Any other help would be welcome.

Regards,
Vince
adrian_sorop
Posts: 73
Joined: Wed Jun 22, 2016 2:48 pm

Re: How to set a root map programmatically ?

Post by adrian_sorop »

Hello again,

Yes, you are right. Using the getOptionsStorage().setOption() doesn't work.

I've made a small sample and used setGlobalObjectProperty(). It changes the value of the Contex combo and loads the keys from the map.

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty(APIAccessibleOptionTags.KEYS_CONTEXT_MAP, contextMapToSet.toExternalForm());
Here's a sample code

Code: Select all

import java.net.URL;

import ro.sync.exml.options.APIAccessibleOptionTags;
import ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension;
import ro.sync.exml.workspace.api.PluginWorkspace;
import ro.sync.exml.workspace.api.listeners.WSEditorChangeListener;
import ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace;

public class MyPluginExtension implements WorkspaceAccessPluginExtension {

  @Override
  public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
    pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
      @Override
      public void editorOpened(URL editorLocation) {
        if (foo()) {
          URL contextMapToSet = new URL("...");
          pluginWorkspaceAccess.setGlobalObjectProperty(APIAccessibleOptionTags.KEYS_CONTEXT_MAP, 
              contextMapToSet.toExternalForm());
        }
      }
      private boolean foo() {
        return true;
      }
      
    },PluginWorkspace.DITA_MAPS_EDITING_AREA);
  }
 
  @Override
  public boolean applicationClosing() {
    return true;
  }
}
Regards,
Adrian
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
Vince
Posts: 64
Joined: Wed Dec 03, 2014 11:25 am

Re: How to set a root map programmatically ?

Post by Vince »

Great ! It works !

Thanks you very much for your help.

Regards,
Vincent
Post Reply