findNodesByXPath within resolveReference unreliable
Post here questions and problems related to oXygen frameworks/document types.
findNodesByXPath within resolveReference unreliable
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:
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).
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);
}
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).
-
- Posts: 1008
- Joined: Wed Nov 16, 2005 11:11 am
Re: findNodesByXPath within resolveReference unreliable
Post by alex_jitianu »
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
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
Re: findNodesByXPath within resolveReference unreliable
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
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
Re: findNodesByXPath within resolveReference unreliable
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service