public static XdmNode getDocumentElement(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { for (XdmNode node : new AxisNodes(doc, Axis.CHILD, AxisNodes.SIGNIFICANT)) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { return node; // There can be only one, this is an XML document } } return null; } else { return doc; } }
@Test public void testPIPELINE() { AxisNodes an = new AxisNodes(null, root, Axis.CHILD, AxisNodes.PIPELINE); XdmNode n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.TEXT); assertEquals(n.toString(), " some text "); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); assertEquals(an.iterator().hasNext(), false); } }
@Test public void testSIGNIFICANT() { AxisNodes an = new AxisNodes(root, Axis.CHILD, AxisNodes.SIGNIFICANT); XdmNode n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.TEXT); assertEquals(n.toString(), " some text "); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("http://www.w3.org/ns/xproc", "documentation")); assertEquals(an.iterator().hasNext(), false); }
public static XdmNode getDocumentElement(XdmNode doc) { if (doc.getNodeKind() == XdmNodeKind.DOCUMENT) { for (XdmNode node : new AxisNodes(doc, Axis.CHILD, AxisNodes.SIGNIFICANT)) { if (node.getNodeKind() == XdmNodeKind.ELEMENT) { return node; // There can be only one, this is an XML document } } return null; } else { return doc; } }
@Test public void testALL() { AxisNodes an = new AxisNodes(root, Axis.CHILD, AxisNodes.ALL); XdmNode n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.PROCESSING_INSTRUCTION); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.TEXT); assertEquals(n.toString(), " "); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.TEXT); assertEquals(n.toString(), " some text "); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("", "p")); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.COMMENT); n = an.iterator().next(); assertEquals(n.getNodeKind(), XdmNodeKind.ELEMENT); assertEquals(n.getNodeName(), new QName("http://www.w3.org/ns/xproc", "documentation")); assertEquals(an.iterator().hasNext(), false); }
private void parseOutput(XdmNode node) { String port = node.getAttributeValue(_port); String href = node.getAttributeValue(_href); for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) { if (child.getNodeKind() == XdmNodeKind.ELEMENT) { throw new XProcException(node, "Output must be empty."); } } if (firstOutput) { outputs.clear(); firstOutput = false; } href = node.getBaseURI().resolve(href).toASCIIString(); if ("-".equals(href) || href.startsWith("http:") || href.startsWith("https:") || href.startsWith("file:")) { outputs.put(port, href); } else { File f = new File(href); String fn = URIUtils.encode(f.getAbsolutePath()); // FIXME: HACK! if ("\\".equals(System.getProperty("file.separator"))) { fn = "/" + fn; } outputs.put(port, "file://" + fn); } }
private void parseOutput(XdmNode node) { String port = node.getAttributeValue(_port); String href = node.getAttributeValue(_href); for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) { if (child.getNodeKind() == XdmNodeKind.ELEMENT) { throw new XProcException(node, "Output must be empty."); } } if (firstOutput) { outputs.clear(); firstOutput = false; } href = node.getBaseURI().resolve(href).toASCIIString(); if ("-".equals(href) || href.startsWith("http:") || href.startsWith("https:") || href.startsWith("file:")) { outputs.put(port, href); } else { File f = new File(href); String fn = URIUtils.encode(f.getAbsolutePath()); // FIXME: HACK! if ("\\".equals(System.getProperty("file.separator"))) { fn = "/" + fn; } outputs.put(port, "file://" + fn); } }
private void scanop(XdmNode input) { String namestr = input.getAttributeValue(_name); String value = input.getAttributeValue(_value); if (namestr == null || value == null) { throw new IllegalArgumentException("Each option and parameter must specify a name and a value"); } QName name = new QName(namestr, input); if (t_option.equals(input.getNodeName())) { if (options.containsKey(name)) { throw new IllegalArgumentException("Attempt to redefine option: " + name); } else { options.put(name, value); } } else { if (parameters.containsKey(name)) { throw new IllegalArgumentException("Attempt to redefine parameter: " + name); } else { parameters.put(name, value); } } for (XdmNode node : new AxisNodes(runtime, input, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Options and parameters must be empty."); } }
private void scanop(XdmNode input) { String namestr = input.getAttributeValue(_name); String value = input.getAttributeValue(_value); if (namestr == null || value == null) { throw new IllegalArgumentException("Each option and parameter must specify a name and a value"); } QName name = new QName(namestr, input); if (t_option.equals(input.getNodeName())) { if (options.containsKey(name)) { throw new IllegalArgumentException("Attempt to redefine option: " + name); } else { options.put(name, value); } } else { if (parameters.containsKey(name)) { throw new IllegalArgumentException("Attempt to redefine parameter: " + name); } else { parameters.put(name, value); } } for (XdmNode node : new AxisNodes(runtime, input, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Options and parameters must be empty."); } }
private EmptyBinding readEmpty(XdmNode node) { checkAttributes(node, new String[] { }, false); EmptyBinding empty = new EmptyBinding(runtime, node); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Unexpected in empty: " + snode.getNodeName()); } checkExtensionAttributes(node, empty); return empty; }
private EmptyBinding readEmpty(XdmNode node) { checkAttributes(node, new String[] { }, false); EmptyBinding empty = new EmptyBinding(runtime, node); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Unexpected in empty: " + snode.getNodeName()); } checkExtensionAttributes(node, empty); return empty; }
public XProcPipeline (XdmNode root) { pipeline = root; for (XdmNode node : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.PIPELINE)) { if (XProcConstants.p_input.equals(node.getNodeName())) { inputPorts.add(node.getAttributeValue(_port)); } if (XProcConstants.p_output.equals(node.getNodeName())) { outputPorts.add(node.getAttributeValue(_port)); } } } }
public XProcPipeline (XdmNode root) { pipeline = root; for (XdmNode node : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.PIPELINE)) { if (XProcConstants.p_input.equals(node.getNodeName())) { inputPorts.add(node.getAttributeValue(_port)); } if (XProcConstants.p_output.equals(node.getNodeName())) { outputPorts.add(node.getAttributeValue(_port)); } } } }
for (XdmNode snode : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new XProcException(node, "Configuration error: serialization must be empty");
for (XdmNode snode : new AxisNodes(null, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new XProcException(node, "Configuration error: serialization must be empty");
private void checkExtensionAttributes(XdmNode node, SourceArtifact src) { for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); if ("".equals(aname.getNamespaceURI())) { // nop } else if (XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { runtime.error(null, node, "Attribute \"" + aname + "\" not allowed on " + node.getNodeName(), XProcConstants.staticError(8)); } else { src.addExtensionAttribute(attr); } } }
for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.ALL)) { if (child.getNodeKind() == XdmNodeKind.ELEMENT) { if (sawElement) {
for (XdmNode child : new AxisNodes(null, node, Axis.CHILD, AxisNodes.ALL)) { if (child.getNodeKind() == XdmNodeKind.ELEMENT) { if (sawElement) {
private void checkExtensionAttributes(XdmNode node, SourceArtifact src) { for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); if ("".equals(aname.getNamespaceURI())) { // nop } else if (XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { runtime.error(null, node, "Attribute \"" + aname + "\" not allowed on " + node.getNodeName(), XProcConstants.staticError(8)); } else { src.addExtensionAttribute(attr); } } }
private HashSet<String> checkAttributes(XdmNode node, String[] attrs, boolean optionShortcutsOk) { HashSet<String> hash = null; if (attrs != null) { hash = new HashSet<String> (); for (String attr : attrs) { hash.add(attr); } } HashSet<String> options = null; for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); if ("".equals(aname.getNamespaceURI())) { if (hash.contains(aname.getLocalName())) { // ok } else if (optionShortcutsOk) { if (options == null) { options = new HashSet<String> (); } options.add(aname.getLocalName()); } else { throw new XProcException(node, "Configuration error: attribute \"" + aname + "\" not allowed on " + node.getNodeName()); } } else if (XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { throw new XProcException(node, "Configuration error: attribute \"" + aname + "\" not allowed on " + node.getNodeName()); } // Everything else is ok } return options; }