findNodesByXPath within resolveReference unreliable

Post here questions and problems related to oXygen frameworks/document types.
Patrik
Posts: 228
Location: Hamburg/Germany

findNodesByXPath within resolveReference unreliable

Tue May 05, 2015 8:30 am

Hi,

I implemented my own ValidatingAuthorReferenceResolver class (derived from DITAConRefResolver) and need to use findNodesByXPath inside resolveReference. In priciple this works fine but when the reference is resolved for the first time (after adding the element to be resolved or modifying in in text mode and switching to author mode) the result is wrong. A refresh always resolves it but with the increasing use of this feature also the annoyance grows.

Here is a minimized sample:

Code: Select all

public boolean hasReferences(AuthorNode node) {
   if (node.getName().equals("resolveReferenceTest")) return true;
   return super.hasReferences(node);
}

@Override
public String getDisplayName(AuthorNode node) {
   if (node.getName().equals("resolveReferenceTest")) return "resolveReferenceTest";
   return super.getDisplayName(node);
}

@Override
public String getReferenceSystemID(AuthorNode node, AuthorAccess authorAccess) {
   if (node.getName().equals("resolveReferenceTest")) return node.getXMLBaseURL().toExternalForm();
   return super.getReferenceSystemID(node, authorAccess);
}

@Override
public String getReferenceUniqueID(AuthorNode node) {
   if (node.getName().equals("resolveReferenceTest")) return "resolveReferenceTest";
   return super.getReferenceUniqueID(node);
}


@Override
public SAXSource resolveReference(AuthorNode node, String systemID, AuthorAccess authorAccess, EntityResolver entityResolver) throws ReferenceResolverException {
   if (node.getName().equals("resolveReferenceTest")) {
      try {
         AuthorNode[] results = authorAccess.getDocumentController().findNodesByXPath("parent::*", node, true, true, false, false);
         if (results.length == 1) {
            final String resultString = "<p>Parent: " + results[0].getDisplayName() + "</p>";
            logger.info("resultString: " + resultString);
            return new SAXSource(
                  authorAccess.getXMLUtilAccess().newNonValidatingXMLReader(),
                  new InputSource(new StringReader(resultString)));
         } else {
            throw new ReferenceResolverException("No parent", true, true);   
         }
      } catch (AuthorOperationException e) {
         throw new ReferenceResolverException(e.getMessage(), true, true);
      }
   }
   return super.resolveReference(node, systemID, authorAccess, entityResolver);
}

@Override
public void checkTarget(AuthorNode node, AuthorDocument targetDocument) throws ValidatingReferenceResolverException {
   if (node.getName().equals("resolveReferenceTest")) return;
   super.checkTarget(node, targetDocument);
}


Now when adding an element resolveReferenceTest within the body of a topic (as root element) the exception "No parent" is thrown. In other cases (with more content in the file) the name of another element is displayed!?

Is there anything I can do about it? Maybe automatically do a refresh on a suitable event? (I can't call DocumentController.refreshNodeReferences inside resolveReference since it results in a recursion).
alex_jitianu
Posts: 645

Re: findNodesByXPath within resolveReference unreliable

Tue May 05, 2015 11:17 am

Hello Patrik,

In this situation, the resolve references call comes before the node is fully connected in the document. Fortunately the node is linked to its parent so you can use node.getParent() instead.

Best regards,
Alex
Patrik
Posts: 228
Location: Hamburg/Germany

Re: findNodesByXPath within resolveReference unreliable

Tue May 05, 2015 11:26 am

Hi Alex,

this was just a minimized sample to demonstrate the problem. In my actual use-case I need to execute more complex xpath expressions (specified as default attributes of the element).

Patrik
Radu
Posts: 5689

Re: findNodesByXPath within resolveReference unreliable

Tue Jan 05, 2016 11:14 am

Hi Patrik,

Just to update this older forum thread, in Oxygen 17.1 you should be able to run an xpath using our API on the resolveReference callback.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests