Permalink
Browse files

Fix issue #101 allow the XProcURIResolver to function as a Saxon XQue…

…ry ModuleURIResolver
  • Loading branch information...
ndw committed Jul 25, 2013
1 parent e9a763f commit fbcc769d5b178a5db27abeba122accdb9e4acaf9
@@ -214,6 +214,7 @@ public void run() throws SaxonApiException {
Processor qtproc = runtime.getProcessor();
XQueryCompiler xqcomp = qtproc.newXQueryCompiler();
+ xqcomp.setModuleURIResolver(runtime.getResolver());
XQueryExecutable xqexec = xqcomp.compile(queryexpr);
XQueryEvaluator xqeval = xqexec.load();
xqeval.setContextItem(srcDoc);
@@ -114,6 +114,7 @@ public void run() throws SaxonApiException {
Processor qtproc = runtime.getProcessor();
XQueryCompiler xqcomp = qtproc.newXQueryCompiler();
xqcomp.setBaseURI(root.getBaseURI());
+ xqcomp.setModuleURIResolver(runtime.getResolver());
XQueryExecutable xqexec = xqcomp.compile(queryString);
XQueryEvaluator xqeval = xqexec.load();
if (document != null) {
@@ -153,6 +153,7 @@ public static void serialize(XProcRuntime xproc, XdmNode node, Serializer serial
public static void serialize(XProcRuntime xproc, Vector<XdmNode> nodes, Serializer serializer) throws SaxonApiException {
Processor qtproc = xproc.getProcessor();
XQueryCompiler xqcomp = qtproc.newXQueryCompiler();
+ xqcomp.setModuleURIResolver(xproc.getResolver());
// Patch suggested by oXygen to avoid errors that result from attempting to serialize
// a schema-valid document with a schema-naive query
@@ -1,5 +1,7 @@
package com.xmlcalabash.util;
+import net.sf.saxon.lib.ModuleURIResolver;
+import net.sf.saxon.lib.StandardModuleURIResolver;
import net.sf.saxon.lib.UnparsedTextURIResolver;
import net.sf.saxon.trans.XPathException;
import org.xml.sax.InputSource;
@@ -14,6 +16,7 @@
import javax.xml.transform.sax.SAXSource;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.SaxonApiException;
@@ -42,9 +45,10 @@
* Time: 4:04:27 PM
* To change this template use File | Settings | File Templates.
*/
-public class XProcURIResolver implements URIResolver, EntityResolver, UnparsedTextURIResolver {
+public class XProcURIResolver implements URIResolver, EntityResolver, ModuleURIResolver, UnparsedTextURIResolver {
private URIResolver uriResolver = null;
private EntityResolver entityResolver = null;
+ private ModuleURIResolver moduleURIResolver = null;
private UnparsedTextURIResolver unparsedTextResolver = null;
private XProcRuntime runtime = null;
private Hashtable<String,XdmNode> cache = new Hashtable<String,XdmNode> ();
@@ -66,6 +70,10 @@ public void setUnderlyingUnparsedTextURIResolver(UnparsedTextURIResolver resolve
unparsedTextResolver = resolver;
}
+ public void setUnderlyingModuleURIResolver(ModuleURIResolver resolver) {
+ moduleURIResolver = resolver;
+ }
+
public void cache(XdmNode doc, URI baseURI) {
XdmNode root = S9apiUtils.getDocumentElement(doc);
@@ -244,6 +252,15 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc
}
}
+ @Override
+ public StreamSource[] resolve(String moduleURI, String baseURI, String[] locations)
+ throws XPathException {
+ if (moduleURIResolver != null) {
+ return moduleURIResolver.resolve(moduleURI, baseURI, locations);
+ }
+ return StandardModuleURIResolver.getInstance().resolve(moduleURI, baseURI, locations);
+ }
+
@Override
public Reader resolve(URI uri, String s, Configuration configuration) throws XPathException {
if (unparsedTextResolver != null) {

0 comments on commit fbcc769

Please sign in to comment.