Page 1 of 1

prettyPrint with oXygen settings

Posted: Fri May 13, 2016 10:07 pm
by msklvsk
Documentation states that pluginWorkspaceAccess.getXMLUtilAccess().prettyPrint() will print with oXygen settings, however for me it doesn't. Particularly, it line-breaks elements which have no whitespace in between, while Format and Indent action behaves as expected. I tried null and "http://www.tei-c.org/Lite/DTD/teixlite.dtd" as systemId parameter. How can I simulate Format and Indent action? And more generally, what is the proper way to programmatically invoke oXygen's action?

Re: prettyPrint with oXygen settings

Posted: Mon May 16, 2016 11:02 am
by Radu
Hi,

There indeed seems to be a difference between the API and the "Format and Indent" action. The "Format and indent" action also looks at the schema (RNG or DTD) referenced by the XML while the API method ignores it. I will add an issue to see if we can fix this on our side.
But you seem to want to actually call the toolbar action on the current opened file contents. Do you use a workspace access plugin extension? For example if you want to format and indent the file on open you could use some code like:

Code: Select all

      @Override
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener(){
public void editorOpened(URL editorLocation) {
WSEditor editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
WSEditorPage edPage = editor.getCurrentPage();
if(edPage instanceof WSXMLTextEditorPage){
WSXMLTextEditorPage tp = (WSXMLTextEditorPage)edPage;
Object formatAndIndentAction = tp.getActionsProvider().getTextActions().get("Source/Pretty_print_tooltip");
tp.getActionsProvider().invokeAction(formatAndIndentAction);
}
}
}, PluginWorkspace.MAIN_EDITING_AREA);
}
Regards,
Radu

Re: prettyPrint with oXygen settings

Posted: Mon May 16, 2016 1:01 pm
by msklvsk
Hi Radu!

Yes, I am using workspace access plugin extension.
Invoking actions in your snippet's way works, but now the question is where can I get actions' ID strings, like that "Source/Pretty_print_tooltip"?

Re: prettyPrint with oXygen settings

Posted: Mon May 16, 2016 1:10 pm
by Radu
Hi,

We do not have particular documentation for each action ID but you can use System.err to print to console the entire map tp.getActionsProvider().getTextActions(). If you start Oxygen using the command line startup script you should see in the console messages from your plugins.

Regards,
Radu

Re: prettyPrint with oXygen settings

Posted: Mon May 16, 2016 3:33 pm
by msklvsk
Oh, I see, It's just a Map. Thanks, it works.