common interface for accessing context
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 34
- Joined: Thu Nov 12, 2020 12:24 pm
common interface for accessing context
Hi,
when writing author mode operations I can use AuthorAccess.getDocumentController().evaluateXPath(...) for evaluating an XPath expression on the current document. When writing a schema manager filter I can use context.executeXPath(...) from ro.sync.contentcompletion.xml.Context for evaluating expressions.
Is there an interface, I can use from both ends? I'd like to share more code between author mode operations and cc for text mode.
Using ro.sync.contentcompletion.xml.Context is not as convenient as the interfaces for writing author mode actions, but it would nevertheless be cool to be able to access it from AuthorAccess.
Regards,
Chris
when writing author mode operations I can use AuthorAccess.getDocumentController().evaluateXPath(...) for evaluating an XPath expression on the current document. When writing a schema manager filter I can use context.executeXPath(...) from ro.sync.contentcompletion.xml.Context for evaluating expressions.
Is there an interface, I can use from both ends? I'd like to share more code between author mode operations and cc for text mode.
Using ro.sync.contentcompletion.xml.Context is not as convenient as the interfaces for writing author mode actions, but it would nevertheless be cool to be able to access it from AuthorAccess.
Regards,
Chris
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: common interface for accessing context
Hi Chris,
As you sensed the Schema Manager Filter is designed to work with both the Text and Author editing modes. So it does not have references to the AuthorAccess.
The "Context" API has this method "ro.sync.contentcompletion.xml.Context.executeXPath(String, String[], boolean)" and then the AuthorDocumentController has this API "ro.sync.ecss.extensions.api.AuthorDocumentController.evaluateXPath(String, boolean, boolean, boolean)" which would both return DOM nodes so you may try to use these methods to reuse code.
Regards,
Radu
As you sensed the Schema Manager Filter is designed to work with both the Text and Author editing modes. So it does not have references to the AuthorAccess.
The "Context" API has this method "ro.sync.contentcompletion.xml.Context.executeXPath(String, String[], boolean)" and then the AuthorDocumentController has this API "ro.sync.ecss.extensions.api.AuthorDocumentController.evaluateXPath(String, boolean, boolean, boolean)" which would both return DOM nodes so you may try to use these methods to reuse code.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 34
- Joined: Thu Nov 12, 2020 12:24 pm
Re: common interface for accessing context
Hi Radu!
Thanks for the clearance. I see.
I was wondering about the return type of "ro.sync.contentcompletion.xml.Context.executeXPath(String, String[], boolean)" which according to the API docs (and my IDE) is an non-parametrized "java.util.List".
So I use "java.util.List<Object>" as usual for results of DOM operations. It's much clearer now.
Thanks and regards,
Chris
Thanks for the clearance. I see.
I was wondering about the return type of "ro.sync.contentcompletion.xml.Context.executeXPath(String, String[], boolean)" which according to the API docs (and my IDE) is an non-parametrized "java.util.List".
So I use "java.util.List<Object>" as usual for results of DOM operations. It's much clearer now.
Thanks and regards,
Chris
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: common interface for accessing context
Hi Chris,
The list of items returns by the XPath (which we run using the Saxon XSLT engine) are usually DOM nodes but they can also be strings for example if you run XPaths which return simple strings.
Regards,
Radu
The list of items returns by the XPath (which we run using the Saxon XSLT engine) are usually DOM nodes but they can also be strings for example if you run XPaths which return simple strings.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 34
- Joined: Thu Nov 12, 2020 12:24 pm
Re: common interface for accessing context
Hi Radu,
your hint in the first answer, to use the returned DOM nodes, is very instructive. I now pass the document node and an xpath expression for identifying the current node over to a PluginLoader class, which is called from both sides (the schema manager filter and the author mode operation). In that PluginLoader class, Saxon's XPath implementation is used to evaluate expressions on the passed in document node.
However, that only works with the document node passed in from the author mode action. Evaluating the same expression on the document node passed in from the schema manager filter (Context.executeXPath("/", namespaces, true)), fails with an exception:
The document node I get from Context.executeXPath("/", namespaces, true) is of type net.sf.saxon.dom.DocumentOverNodeInfo while the one returned by AuthorAccess.getDocumentController().evaluateXPath(...) is of type ro.sync.ecss.dom.wrappers.AuthorDocumentDomWrapper
I already tried to pass a configuration to Saxon XPathFactoryImpl, but that failed to:
where document is an org.w3c.dom.Document and net.sf.saxon.xpath.XPathFactoryImpl is used.
How can Saxon be used to evaluate XPath expressions on DocumentOverNodeInfo? Is there a Configuration object, I can get e.g. from some utility?
I would also be fine, if Saxon's trees where passed to my PluginLoader class instead of DOM nodes.
Kind Regards,
Chris
your hint in the first answer, to use the returned DOM nodes, is very instructive. I now pass the document node and an xpath expression for identifying the current node over to a PluginLoader class, which is called from both sides (the schema manager filter and the author mode operation). In that PluginLoader class, Saxon's XPath implementation is used to evaluate expressions on the passed in document node.
However, that only works with the document node passed in from the author mode action. Evaluating the same expression on the document node passed in from the schema manager filter (Context.executeXPath("/", namespaces, true)), fails with an exception:
Code: Select all
javax.xml.xpath.XPathExpressionException: Supplied node must be built using the same or a compatible Configuration
I already tried to pass a configuration to Saxon XPathFactoryImpl, but that failed to:
Code: Select all
// setup XPath 2.0 from Saxon
XPathFactoryImpl xpathFactoryImpl = new XPathFactoryImpl();
xpathFactoryImpl.setConfiguration((Configuration) document.getDomConfig());
XPath xpath = xpathFactoryImpl.newXPath();
Code: Select all
java.lang.NullPointerException: Cannot invoke "net.sf.saxon.Configuration.setProcessor(net.sf.saxon.Configuration$ApiProvider)" because "config" is null
at net.sf.saxon.xpath.XPathFactoryImpl.setConfiguration(XPathFactoryImpl.java:61) ~[oxygen-patched-saxon-9.jar:?]
I would also be fine, if Saxon's trees where passed to my PluginLoader class instead of DOM nodes.
Kind Regards,
Chris
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: common interface for accessing context
Post by alex_jitianu »
Hi Chris,
net.sf.saxon.dom.DocumentOverNodeInfo.getDomConfig() returns null by design and is not the configuration you need anyway. Thy using net.sf.saxon.dom.NodeOverNodeInfo.getUnderlyingNodeInfo() and net.sf.saxon.om.NodeInfo.getConfiguration() instead to get teh Saxon configuration object.
Best regards,
Alex
net.sf.saxon.dom.DocumentOverNodeInfo.getDomConfig() returns null by design and is not the configuration you need anyway. Thy using net.sf.saxon.dom.NodeOverNodeInfo.getUnderlyingNodeInfo() and net.sf.saxon.om.NodeInfo.getConfiguration() instead to get teh Saxon configuration object.
Best regards,
Alex
-
- Posts: 34
- Joined: Thu Nov 12, 2020 12:24 pm
Re: common interface for accessing context
Hi Alex,
Nice! That works. Thanks!
It's time to share the code with the community now:
https://github.com/SCDH/oxbytei
Regards,
Chris
Nice! That works. Thanks!
It's time to share the code with the community now:
https://github.com/SCDH/oxbytei
Regards,
Chris
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: common interface for accessing context
Post by alex_jitianu »
Hi Chris,
We have a blog page that presents various third party frameworks and I can add an entry for oxbytei, if it's O.K. with you.
https://blog.oxygenxml.com/topics/Oxyge ... works.html
Best regards,
Alex
We have a blog page that presents various third party frameworks and I can add an entry for oxbytei, if it's O.K. with you.
https://blog.oxygenxml.com/topics/Oxyge ... works.html
Best regards,
Alex
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