Find the name of a parent node/tag in EditorPage

Post here questions and problems related to oXygen frameworks/document types.
wmaclean
Posts: 48
Joined: Sat Jan 04, 2020 1:17 am

Find the name of a parent node/tag in EditorPage

Post by wmaclean »

Hello,
We are working on a function that inserts a tag, but we want to validate the parent node, to make sure it is
valid.

For AuthorPage, we got this to work:

Code: Select all

AuthorAccess authorAccess = authorPage.getAuthorAccess();                   
AuthorElement nodeAtCaret = (AuthorElement) authorAccess.getEditorAccess().getFullySelectedNode();
  if (nodeAtCaret == null) {
try {
nodeAtCaret = (AuthorElement) authorAccess.getDocumentController().getNodeAtOffset(offset);
} catch (BadLocationException e) {
e.printStackTrace();
}
System.out.println(nodeAtCaret.getDisplayName()); // it will display the parent tag name and using this we can validate the our condition.
}
How can we do the same thing for EditorPage?

Thank you,
Will
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: Find the name of a parent node/tag in EditorPage

Post by alex_jitianu »

Hello Will,

Here is how you can do that for the Text page:

Code: Select all

WSEditorPage currentPage = wsEditor.getCurrentPage();
    if (currentPage instanceof WSXMLTextEditorPage) {
      WSXMLTextEditorPage xmlTextPage = (WSXMLTextEditorPage) currentPage;
      
      try {
        Object[] evaluateXPath = xmlTextPage.evaluateXPath("local-name()");
        
        if (evaluateXPath != null && evaluateXPath.length == 1 && evaluateXPath[0] instanceof String) {
          String localName = (String)evaluateXPath[0];
        }
        
      } catch (XPathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
The Grid page doesn't have an API though which to do that...

Best regards,
Alex
wmaclean
Posts: 48
Joined: Sat Jan 04, 2020 1:17 am

Re: Find the name of a parent node/tag in EditorPage

Post by wmaclean »

Hello Alex,
Thank you very much!

Stay safe,
Will
Post Reply