Skip to content
Permalink
Browse files

Replace deprecated CollectionResolver with CollectionFinder

  • Loading branch information
ndw committed Dec 15, 2016
1 parent ad09356 commit 4a3159d99e91a8fb56ce7708b1239aa75329dfe4
@@ -28,11 +28,11 @@
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.Base64;
import com.xmlcalabash.util.CollectionResolver;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TreeWriter;
import com.xmlcalabash.util.XProcCollectionFinder;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.CollectionURIResolver;
import net.sf.saxon.lib.CollectionFinder;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
@@ -121,10 +121,10 @@ public void run() throws SaxonApiException {

runtime.getConfigurer().getSaxonConfigurer().configXQuery(config);

CollectionURIResolver collectionResolver = config.getCollectionURIResolver();
CollectionFinder collectionFinder = config.getCollectionFinder();

config.setDefaultCollection(CollectionResolver.DEFAULT);
config.setCollectionURIResolver(new CollectionResolver(runtime, defaultCollection, collectionResolver));
config.setDefaultCollection(XProcCollectionFinder.DEFAULT);
config.setCollectionFinder(new XProcCollectionFinder(runtime, defaultCollection, collectionFinder));

try {
Processor qtproc = runtime.getProcessor();
@@ -209,7 +209,7 @@ public void run() throws SaxonApiException {
result.write(node);
}
} finally {
config.setCollectionURIResolver(collectionResolver);
config.setCollectionFinder(collectionFinder);
}
}
}
@@ -19,58 +19,58 @@

package com.xmlcalabash.library;

import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Hashtable;
import java.util.Vector;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;

import com.xmlcalabash.core.XMLCalabash;
import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.core.XProcException;
import com.xmlcalabash.core.XProcRuntime;
import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.io.ReadablePipe;
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.MessageFormatter;
import com.xmlcalabash.util.TreeWriter;
import com.xmlcalabash.util.CollectionResolver;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TreeWriter;
import com.xmlcalabash.util.XProcCollectionFinder;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.CollectionURIResolver;
import net.sf.saxon.event.PipelineConfiguration;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.expr.parser.Location;
import net.sf.saxon.lib.CollectionFinder;
import net.sf.saxon.lib.OutputURIResolver;
import net.sf.saxon.lib.UnparsedTextURIResolver;
import net.sf.saxon.om.NamespaceBinding;
import net.sf.saxon.om.NodeName;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.MessageListener;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.ValidationMode;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import net.sf.saxon.s9api.MessageListener;
import net.sf.saxon.s9api.ValidationMode;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.event.Receiver;
import com.xmlcalabash.runtime.XAtomicStep;
import net.sf.saxon.event.PipelineConfiguration;
import net.sf.saxon.expr.parser.Location;
import net.sf.saxon.om.NamespaceBinding;
import net.sf.saxon.om.NodeName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.SchemaType;
import net.sf.saxon.type.SimpleType;
import org.xml.sax.InputSource;

import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Hashtable;
import java.util.Vector;

/**
*
* @author ndw
@@ -199,12 +199,12 @@ public void run() throws SaxonApiException {
runtime.getConfigurer().getSaxonConfigurer().configXSLT(config);

OutputURIResolver uriResolver = config.getOutputURIResolver();
CollectionURIResolver collectionResolver = config.getCollectionURIResolver();
CollectionFinder collectionFinder = config.getCollectionFinder();
UnparsedTextURIResolver unparsedTextURIResolver = runtime.getResolver();

config.setOutputURIResolver(new OutputResolver());
config.setDefaultCollection(CollectionResolver.DEFAULT);
config.setCollectionURIResolver(new CollectionResolver(runtime, defaultCollection, collectionResolver));
config.setDefaultCollection(XProcCollectionFinder.DEFAULT);
config.setCollectionFinder(new XProcCollectionFinder(runtime, defaultCollection, collectionFinder));

XdmDestination result = null;
try {
@@ -252,7 +252,7 @@ public void run() throws SaxonApiException {
transformer.transform();
} finally {
config.setOutputURIResolver(uriResolver);
config.setCollectionURIResolver(collectionResolver);
config.setCollectionFinder(collectionFinder);
}

XdmNode xformed = result.getXdmNode();

This file was deleted.

@@ -0,0 +1,133 @@
package com.xmlcalabash.util;

import com.xmlcalabash.core.XProcRuntime;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.CollectionFinder;
import net.sf.saxon.lib.Resource;
import net.sf.saxon.lib.ResourceCollection;
import net.sf.saxon.om.Item;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.trans.XPathException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Vector;

/**
* Created by IntelliJ IDEA.
* User: ndw
* Date: Nov 3, 2008
* Time: 5:44:12 PM
* To change this template use File | Settings | File Templates.
*/
public class XProcCollectionFinder implements CollectionFinder {
public static final String DEFAULT = "http://xmlcalabash.com/saxon-default-collection";
protected Logger logger = LoggerFactory.getLogger(XProcCollectionFinder.class);

XProcRuntime runtime = null;
Vector<XdmNode> docs = null;
CollectionFinder chainedFinder = null;

public XProcCollectionFinder(XProcRuntime runtime, Vector<XdmNode> docs, CollectionFinder chainedFinder) {
this.runtime = runtime;
this.docs = docs;
this.chainedFinder = chainedFinder;
}

@Override
public ResourceCollection findCollection(XPathContext context, String collectionURI) throws XPathException {
logger.trace("Collection: " + collectionURI);

if (collectionURI == null) {
collectionURI = DEFAULT;
}

if (collectionURI.equals(DEFAULT)) {
return new DocumentResourceCollection(collectionURI, docs);
} else {
try {
URI cURI = new URI(collectionURI);
Vector<XdmNode> docs = runtime.getCollection(cURI);
if (docs != null) {
return new DocumentResourceCollection(collectionURI, docs);
}
} catch (URISyntaxException use) {
logger.trace("URI Syntax exception resolving collection URI: " + collectionURI);
}

return chainedFinder.findCollection(context, collectionURI);
}
}

private class DocumentResourceCollection implements ResourceCollection {
private Vector<XdmNode> docs = null;
private Vector<String> uris = null;
private Vector<Resource> rsrcs = null;
private String collectionURI = null;

public DocumentResourceCollection(String collectionURI, Vector<XdmNode> docs) {
this.collectionURI = collectionURI;
this.docs = docs;
}

@Override
public String getCollectionURI() {
return collectionURI;
}

@Override
public Iterator<String> getResourceURIs(XPathContext context) throws XPathException {
if (uris == null) {
uris = new Vector<String> ();
for (XdmNode doc : docs) {
uris.add(doc.getBaseURI().toASCIIString());
}
}
return uris.iterator();
}

@Override
public Iterator<? extends Resource> getResources(XPathContext context) throws XPathException {
if (rsrcs == null) {
rsrcs = new Vector<Resource> ();
for (XdmNode doc : docs) {
rsrcs.add(new DocumentResource(doc));
}
}

return rsrcs.iterator();
}

@Override
public boolean isStable(XPathContext context) {
return true;
}
}

private class DocumentResource implements Resource {
private XdmNode doc = null;

public DocumentResource(XdmNode doc) {
this.doc = doc;
}

@Override
public String getResourceURI() {
return doc.getBaseURI().toASCIIString();
}

@Override
public Item getItem(XPathContext context) throws XPathException {
return doc.getUnderlyingValue().head();
}

@Override
public String getContentType() {
return null;
}
}

}
@@ -1,31 +1,23 @@
package com.xmlcalabash.drivers;

import net.sf.saxon.Configuration;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.XdmAtomicValue;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.XdmSequenceIterator;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.OutputURIResolver;
import net.sf.saxon.lib.CollectionURIResolver;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import org.xml.sax.InputSource;

import javax.xml.transform.sax.SAXSource;
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;

import com.xmlcalabash.util.CollectionResolver;
import com.xmlcalabash.model.RuntimeValue;
import org.xml.sax.InputSource;

import javax.xml.transform.sax.SAXSource;

/**
* Created by IntelliJ IDEA.
* User: ndw

0 comments on commit 4a3159d

Please sign in to comment.
You can’t perform that action at this time.