Permalink
Browse files

Replaced RelevantNodes with AxisNodes. This is an intentionally

backwards incompatible API change. If you were using RelevantNodes,
you were almost certainly not getting the results you expected
(even if it didn't matter most of the time).
  • Loading branch information...
ndw committed Aug 17, 2014
1 parent 21b035c commit b6eadf1a1e80548e35bbc6dda95e6f1871ee6113
@@ -1,9 +1,7 @@
package com.xmlcalabash.core;
import com.xmlcalabash.piperack.PipelineSource;
-import com.xmlcalabash.util.Input;
-import com.xmlcalabash.util.JSONtoXML;
-import com.xmlcalabash.util.Output;
+import com.xmlcalabash.util.*;
import net.sf.saxon.Configuration;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.DocumentBuilder;
@@ -33,10 +31,6 @@
import com.xmlcalabash.io.ReadablePipe;
import com.xmlcalabash.io.DocumentSequence;
import com.xmlcalabash.runtime.XAtomicStep;
-import com.xmlcalabash.util.URIUtils;
-import com.xmlcalabash.util.S9apiUtils;
-import com.xmlcalabash.util.RelevantNodes;
-import com.xmlcalabash.util.LogOptions;
import com.xmlcalabash.model.Step;
import javax.xml.transform.sax.SAXSource;
@@ -409,7 +403,7 @@ public void parse(XdmNode doc) {
doc = S9apiUtils.getDocumentElement(doc);
}
- for (XdmNode node : new RelevantNodes(null, doc, Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(null, doc, Axis.CHILD, AxisNodes.PIPELINE)) {
String uri = node.getNodeName().getNamespaceURI();
String localName = node.getNodeName().getLocalName();
@@ -779,7 +773,8 @@ private void parseInput(XdmNode node) {
Vector<XdmValue> docnodes = new Vector<XdmValue> ();
boolean sawElement = false;
- for (XdmNode child : new RelevantNodes(null, node, Axis.CHILD)) {
+ // FIXME: shouldn't this test for a "document" that doesn't have any document element?
+ for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.ALL)) {
if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
if (sawElement) {
throw new XProcException(node, "Invalid configuration value for input '" + port + "': content is not a valid XML document.");
@@ -817,7 +812,7 @@ private void parsePipeline(XdmNode node) {
Vector<XdmValue> docnodes = new Vector<XdmValue> ();
boolean sawElement = false;
- for (XdmNode child : new RelevantNodes(null, node, Axis.CHILD)) {
+ for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) {
if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
if (sawElement) {
throw new XProcException(node, "Content of pipeline is not a valid XML document.");
@@ -842,7 +837,7 @@ private void parseOutput(XdmNode node) {
String port = node.getAttributeValue(_port);
String href = node.getAttributeValue(_href);
- for (XdmNode child : new RelevantNodes(null, node, Axis.CHILD)) {
+ for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) {
if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
throw new XProcException(node, "Output must be empty.");
}
@@ -981,7 +976,7 @@ private void parseSerialization(XdmNode node) {
serializationOptions.put(name, value);
}
- for (XdmNode snode : new RelevantNodes(null, node, Axis.CHILD)) {
+ for (XdmNode snode : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) {
throw new XProcException(node, "Configuration error: serialization must be empty");
}
}
@@ -997,7 +992,7 @@ private void parseSerialization(XdmNode node) {
}
HashSet<String> options = null;
- for (XdmNode attr : new RelevantNodes(null, node, Axis.ATTRIBUTE)) {
+ for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) {
QName aname = attr.getNodeName();
if ("".equals(aname.getNamespaceURI())) {
if (hash.contains(aname.getLocalName())) {
@@ -33,8 +33,8 @@
import com.xmlcalabash.core.XProcConfiguration;
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.io.ReadablePipe;
+import com.xmlcalabash.util.AxisNodes;
import com.xmlcalabash.util.S9apiUtils;
-import com.xmlcalabash.util.RelevantNodes;
import org.xml.sax.InputSource;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
@@ -50,10 +50,6 @@
import net.sf.saxon.s9api.XdmAtomicValue;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.XdmValue;
-import net.sf.saxon.s9api.Processor;
-import net.sf.saxon.s9api.XQueryCompiler;
-import net.sf.saxon.s9api.XQueryExecutable;
-import net.sf.saxon.s9api.XQueryEvaluator;
import net.sf.saxon.s9api.Serializer;
import javax.xml.transform.sax.SAXSource;
@@ -680,7 +676,7 @@ public XProcTest(XdmNode root) {
}
private void scan(XdmNode pipeline) throws SaxonApiException {
- for (XdmNode node : new RelevantNodes(runtime, pipeline,Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(runtime, pipeline,Axis.CHILD, AxisNodes.PIPELINE)) {
if (t_title.equals(node.getNodeName())) {
title = node;
continue;
@@ -725,7 +721,7 @@ private void scanio(XdmNode input) throws SaxonApiException {
if (href != null) {
add(input, port, href);
} else {
- for (XdmNode node : new RelevantNodes(input,Axis.CHILD,false)) {
+ for (XdmNode node : new AxisNodes(input, Axis.CHILD, AxisNodes.ALL)) {
if (node.getNodeKind() != XdmNodeKind.ELEMENT) {
continue;
}
@@ -764,7 +760,7 @@ private void scanpipe(XdmNode input) throws SaxonApiException {
add(input, null, baseURI.resolve(href).toASCIIString());
} else {
XdmNode docroot = null;
- for (XdmNode node : new RelevantNodes(input,Axis.CHILD,true)) {
+ for (XdmNode node : new AxisNodes(runtime, input, Axis.CHILD, AxisNodes.PIPELINE)) {
if (node.getNodeKind() == XdmNodeKind.ELEMENT) {
docroot = node;
}
@@ -808,7 +804,7 @@ private void scanop(XdmNode input) {
}
}
- for (XdmNode node : new RelevantNodes(runtime, input,Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(runtime, input, Axis.CHILD, AxisNodes.PIPELINE)) {
throw new IllegalArgumentException("Options and parameters must be empty.");
}
}
@@ -858,7 +854,7 @@ private void add(XdmNode node, String port, XdmNode root) {
public XProcPipeline (XdmNode root) {
pipeline = root;
- for (XdmNode node : new RelevantNodes(runtime, root,Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.PIPELINE)) {
if (XProcConstants.p_input.equals(node.getNodeName())) {
inputPorts.add(node.getAttributeValue(_port));
}
@@ -13,9 +13,9 @@
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.model.Input;
import com.xmlcalabash.model.DeclareStep;
+import com.xmlcalabash.util.AxisNodes;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TreeWriter;
-import com.xmlcalabash.util.RelevantNodes;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
@@ -219,7 +219,7 @@ public void run() throws SaxonApiException {
}
- for (XdmNode opt : new RelevantNodes(runtime, root, Axis.CHILD)) {
+ for (XdmNode opt : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if (opt.getNodeKind() != XdmNodeKind.ELEMENT || !cx_option.equals(opt.getNodeName())) {
throw new XProcException(step.getNode(), "A cx:options document must only contain cx:option elements");
}
@@ -1,32 +1,12 @@
package com.xmlcalabash.extensions;
-import com.hp.hpl.jena.graph.Node;
-import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.query.DatasetFactory;
-import com.hp.hpl.jena.rdf.model.Literal;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
-import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.core.XProcException;
import com.xmlcalabash.core.XProcRuntime;
-import com.xmlcalabash.io.ReadablePipe;
-import com.xmlcalabash.io.WritablePipe;
-import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.runtime.XAtomicStep;
-import com.xmlcalabash.util.RelevantNodes;
-import com.xmlcalabash.util.S9apiUtils;
-import com.xmlcalabash.util.TreeWriter;
-import net.sf.saxon.s9api.Axis;
-import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import org.apache.jena.riot.Lang;
-import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RiotReader;
import org.apache.jena.riot.lang.LangRIOT;
import org.apache.jena.riot.system.ErrorHandler;
@@ -40,10 +20,7 @@
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
-import java.util.Calendar;
import java.util.Iterator;
-import java.util.Random;
-import java.util.regex.Pattern;
/**
* Created by IntelliJ IDEA.
@@ -17,30 +17,18 @@
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.runtime.XAtomicStep;
-import com.xmlcalabash.util.RelevantNodes;
+import com.xmlcalabash.util.AxisNodes;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TreeWriter;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import org.apache.jena.riot.Lang;
-import org.apache.jena.riot.RiotReader;
-import org.apache.jena.riot.lang.LangRIOT;
import org.apache.jena.riot.system.ErrorHandler;
-import org.apache.jena.riot.system.ParserProfile;
-import org.apache.jena.riot.system.RiotLib;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.riot.system.StreamRDFLib;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
+
import java.util.Calendar;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Random;
import java.util.regex.Pattern;
@@ -346,7 +334,7 @@ protected void loadRdf(Dataset dataset, XdmNode doc) {
XdmNode root = S9apiUtils.getDocumentElement(doc);
if (root.getNodeName().equals(sem_triples)) {
- for (XdmNode node : new RelevantNodes(null, root, Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(root, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if (node.getNodeName().equals(cx_graph_name)) {
graphName = node.getStringValue();
model = dataset.getNamedModel(graphName);
@@ -356,7 +344,7 @@ protected void loadRdf(Dataset dataset, XdmNode doc) {
XdmNode pred = null;
XdmNode obj = null;
- for (XdmNode child : new RelevantNodes(null, node, Axis.CHILD)) {
+ for (XdmNode child : new AxisNodes(node, Axis.CHILD)) {
if (child.getNodeName().equals(sem_subject)) {
subj = child;
} else if (child.getNodeName().equals(sem_predicate)) {
@@ -5,6 +5,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
+import com.xmlcalabash.util.AxisNodes;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
@@ -20,7 +21,6 @@
import com.xmlcalabash.io.ReadablePipe;
import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.runtime.XAtomicStep;
-import com.xmlcalabash.util.RelevantNodes;
import com.xmlcalabash.util.S9apiUtils;
/**
@@ -72,7 +72,7 @@ public void run() throws SaxonApiException {
throw new XProcException(step.getNode(), "The input to cx:set-cookies must be a c:cookies document.");
}
- for (XdmNode node : new RelevantNodes(null, root, Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(root, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if (node.getNodeKind() == XdmNodeKind.ELEMENT) {
if (!c_cookie.equals(node.getNodeName())) {
throw new XProcException(step.getNode(), "A c:cookies document must contain only c:cookie elements.");
@@ -114,11 +114,8 @@ public void run() throws SaxonApiException {
runtime.getCookieStore(cookieKey).addCookie(cookie);
} else if (node.getNodeKind() == XdmNodeKind.TEXT) {
- if ("".equals(node.getStringValue().trim())) {
- // nop
- } else {
- throw new XProcException(step.getNode(), "A c:cookies document must not contain non-whitespace text nodes.");
- }
+ // AxisNodes will filter out empty whitespace nodes for us
+ throw new XProcException(step.getNode(), "A c:cookies document must not contain non-whitespace text nodes.");
}
}
}
@@ -8,9 +8,9 @@
import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.model.RuntimeValue;
+import com.xmlcalabash.util.AxisNodes;
import com.xmlcalabash.util.TreeWriter;
import com.xmlcalabash.util.S9apiUtils;
-import com.xmlcalabash.util.RelevantNodes;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
@@ -177,7 +177,7 @@ public void run() throws SaxonApiException {
tree.addAttribute(_exists, status >= 400 && status < 500 ? "false" : "true");
tree.addAttribute(_uri, uri.toASCIIString());
- for (XdmNode node : new RelevantNodes(runtime, result, Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(result, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if ("Last-Modified".equals(node.getAttributeValue(_name))) {
String months[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };
@@ -214,7 +214,7 @@ public void run() throws SaxonApiException {
tree.startContent();
- for (XdmNode node : new RelevantNodes(runtime, result, Axis.CHILD)) {
+ for (XdmNode node : new AxisNodes(result, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
tree.addSubtree(node);
}
@@ -5,8 +5,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
@@ -29,6 +27,7 @@
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
+import com.xmlcalabash.util.*;
import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
@@ -42,28 +41,12 @@
import com.xmlcalabash.io.DataStore;
import com.xmlcalabash.io.DataStore.DataInfo;
import com.xmlcalabash.io.DataStore.DataReader;
-import com.xmlcalabash.core.XProcConstants;
-import com.xmlcalabash.model.RuntimeValue;
-import com.xmlcalabash.util.Base64;
-import com.xmlcalabash.util.JSONtoXML;
-import com.xmlcalabash.util.TreeWriter;
-import com.xmlcalabash.util.S9apiUtils;
-import com.xmlcalabash.util.RelevantNodes;
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.io.ReadablePipe;
-import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.library.DefaultStep;
import com.xmlcalabash.runtime.XAtomicStep;
-import com.xmlcalabash.util.RelevantNodes;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TreeWriter;
-import com.xmlcalabash.util.XMLtoJSON;
-import net.sf.saxon.s9api.SaxonApiException;
-import net.sf.saxon.s9api.QName;
-import net.sf.saxon.s9api.XdmNode;
-import net.sf.saxon.s9api.Axis;
-import net.sf.saxon.s9api.XdmNodeKind;
-import net.sf.saxon.s9api.Serializer;
/**
*
@@ -278,7 +261,7 @@ void read(URI id, InputStream stream, final DatatypeFactory dfactory)
}
private void parseManifest(XdmNode man) {
- for (XdmNode child : new RelevantNodes(runtime, man, Axis.CHILD)) {
+ for (XdmNode child : new AxisNodes(man, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
if (XdmNodeKind.ELEMENT == child.getNodeKind()) {
if (c_entry.equals(child.getNodeName())) {
String name = child.getAttributeValue(_name);
Oops, something went wrong.

0 comments on commit b6eadf1

Please sign in to comment.