Page 1 of 1

Find the name of a parent node/tag in EditorPage

Posted: Wed Apr 29, 2020 5:58 pm
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

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

Posted: Thu Apr 30, 2020 11:19 am
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

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

Posted: Mon May 04, 2020 2:55 pm
by wmaclean
Hello Alex,
Thank you very much!

Stay safe,
Will