Page 1 of 1
Accessing document content
Posted: Mon Dec 08, 2014 8:05 pm
by rcfiv
First I want to say, I know you have examples for this sort of thing. However, I can not find them. I basically downloaded all the jar files for creating the plugin and copied some code I found on the web as well as a plugin that was already installed with my version of oXygen Author (15.2).
What I am trying to figure out is how to access the xml content. Here is snippet of code that I am trying, but it's failing with incompatible types. The variable, editors, is a hashtable that I save off the editors for whatever editors are currently open in the application.
Code: Select all
// Extract the xml page editor
WSXMLTextEditorPage xmlPage = (WSXMLTextEditorPage) editors.get(currentEdit).getCurrentPage();
Object[] values = xmlPage.evaluateXPath("/topic/prolog//othermeta[@name = 'Category Codes']/@content");
I have a DITA file open in the editor. If you have a location I can go to, to find more examples... I'd be happy to go check it out. I don't think I am able to set up Maven on my current configuration of Eclipse.
Re: Accessing document content
Posted: Tue Dec 09, 2014 10:53 am
by alex_jitianu
Hello,
The API you are using (WSXMLTextEditorPage) is intended for when the text page is the active page. I suspect that in your situation the author page is active. You can handle both cases like this:
Code: Select all
String currentPageID = editorAccess.getCurrentPageID();
Object[] values = null;
if (EditorPageConstants.PAGE_TEXT.equals(currentPageID) && editorAccess.getCurrentPage() instanceof WSXMLTextEditorPage) {
WSXMLTextEditorPage textPage = (WSXMLTextEditorPage) editorAccess.getCurrentPage();
values = textPage.evaluateXPath("/topic/prolog//othermeta[@name = 'Category Codes']/@content");
} else if (EditorPageConstants.PAGE_AUTHOR.equals(currentPageID)) {
WSAuthorEditorPage authorPage = (WSAuthorEditorPage) editorAccess.getCurrentPage();
values = authorPage.getDocumentController().evaluateXPath("/topic/prolog//othermeta[@name = 'Category Codes']/@content", true, true, true);
}
If needed you can programmatically switch pages but I'm not sure if that is what you want or what you need:
Code: Select all
editorAccess.changePage(EditorPageConstants.PAGE_TEXT);
If would be good if you could create the Maven based sample SDK project because it has a lot of sample code.
Best regards,
Alex
Re: Accessing document content
Posted: Tue Dec 09, 2014 6:58 pm
by rcfiv
alex_jitianu wrote:Hello,
The API you are using (WSXMLTextEditorPage) is intended for when the text page is the active page. I suspect that in your situation the author page is active. You can handle both cases like this:
Code: Select all
String currentPageID = editorAccess.getCurrentPageID();
Object[] values = null;
if (EditorPageConstants.PAGE_TEXT.equals(currentPageID) && editorAccess.getCurrentPage() instanceof WSXMLTextEditorPage) {
WSXMLTextEditorPage textPage = (WSXMLTextEditorPage) editorAccess.getCurrentPage();
values = textPage.evaluateXPath("/topic/prolog//othermeta[@name = 'Category Codes']/@content");
} else if (EditorPageConstants.PAGE_AUTHOR.equals(currentPageID)) {
WSAuthorEditorPage authorPage = (WSAuthorEditorPage) editorAccess.getCurrentPage();
values = authorPage.getDocumentController().evaluateXPath("/topic/prolog//othermeta[@name = 'Category Codes']/@content", true, true, true);
}
If needed you can programmatically switch pages but I'm not sure if that is what you want or what you need:
Code: Select all
editorAccess.changePage(EditorPageConstants.PAGE_TEXT);
If would be good if you could create the Maven based sample SDK project because it has a lot of sample code.
Best regards,
Alex
Alex,
Thanks a ton... that seemed to do that trick. I appreciate the help. I will see if I can create a Maven based sample sdk project somewhere. So I can check other examples. Again, thank you!
--
Richard