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; } }
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; } }
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)); } } } }
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 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 DocumentBinding readDocument(XdmNode node) { checkAttributes(node, new String[] { "href" }, false); String href = node.getAttributeValue(new QName("href")); DocumentBinding doc = new DocumentBinding(runtime, node); doc.setHref(href); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Unexpected in document: " + snode.getNodeName()); } checkExtensionAttributes(node, doc); return doc; }
private DocumentBinding readDocument(XdmNode node) { checkAttributes(node, new String[] { "href" }, false); String href = node.getAttributeValue(new QName("href")); DocumentBinding doc = new DocumentBinding(runtime, node); doc.setHref(href); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Unexpected in document: " + snode.getNodeName()); } checkExtensionAttributes(node, doc); return doc; }
public void run() throws SaxonApiException { super.run(); String uris = getOption(_uri, (String) null); if (uris == null) { throw new XProcException("URI is required"); } baseURI = getOption(_uri).getBaseURI().resolve(uris); XdmNode doc = source.read(); tree = new TreeWriter(runtime); tree.startDocument(baseURI); for (XdmNode node : new AxisNodes(doc, Axis.CHILD)) { write(node,false); } tree.endDocument(); result.write(tree.getResult()); }
public void run() throws SaxonApiException { super.run(); String uris = getOption(_uri, (String) null); if (uris == null) { throw new XProcException("URI is required"); } baseURI = getOption(_uri).getBaseURI().resolve(uris); XdmNode doc = source.read(); tree = new TreeWriter(runtime); tree.startDocument(baseURI); for (XdmNode node : new AxisNodes(doc, Axis.CHILD)) { write(node,false); } tree.endDocument(); result.write(tree.getResult()); }
private Log readLog(XdmNode node) { checkAttributes(node, new String[] { "port", "href" }, false); String port = checkNCName(node.getAttributeValue(new QName("port"))); String href = node.getAttributeValue(new QName("href")); URI hrefURI = null; if (href != null) { hrefURI = node.getBaseURI().resolve(href); } Log log = new Log(runtime, node); log.setPort(port); log.setHref(hrefURI); checkExtensionAttributes(node, log); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw XProcException.staticError(44, node, "p:log must be empty"); } checkExtensionAttributes(node, log); return log; }
private Log readLog(XdmNode node) { checkAttributes(node, new String[] { "port", "href" }, false); String port = checkNCName(node.getAttributeValue(new QName("port"))); String href = node.getAttributeValue(new QName("href")); URI hrefURI = null; if (href != null) { hrefURI = node.getBaseURI().resolve(href); } Log log = new Log(runtime, node); log.setPort(port); log.setHref(hrefURI); checkExtensionAttributes(node, log); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw XProcException.staticError(44, node, "p:log must be empty"); } checkExtensionAttributes(node, log); return log; }
private PipeNameBinding readPipe(XdmNode node) { checkAttributes(node, new String[] { "port", "step" }, false); String step = checkNCName(node.getAttributeValue(new QName("step"))); String port = checkNCName(node.getAttributeValue(new QName("port"))); if (step == null || port == null) { if (step == null) { throw XProcException.staticError(38, node, "Missing step attribute."); } else { throw XProcException.staticError(38, node, "Missing port attribute."); } } PipeNameBinding pipe = new PipeNameBinding(runtime, node); pipe.setStep(step); pipe.setPort(port); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Unexpected in pipe: " + snode.getNodeName()); } checkExtensionAttributes(node, pipe); return pipe; }
private PipeNameBinding readPipe(XdmNode node) { checkAttributes(node, new String[] { "port", "step" }, false); String step = checkNCName(node.getAttributeValue(new QName("step"))); String port = checkNCName(node.getAttributeValue(new QName("port"))); if (step == null || port == null) { if (step == null) { throw XProcException.staticError(38, node, "Missing step attribute."); } else { throw XProcException.staticError(38, node, "Missing port attribute."); } } PipeNameBinding pipe = new PipeNameBinding(runtime, node); pipe.setStep(step); pipe.setPort(port); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { throw new IllegalArgumentException("Unexpected in pipe: " + snode.getNodeName()); } checkExtensionAttributes(node, pipe); return pipe; }
private Output readOutput(Step parent, XdmNode node) { checkAttributes(node, new String[] { "port", "primary", "sequence" }, false); String port = checkNCName(node.getAttributeValue(new QName("port"))); if (port == null) { throw XProcException.staticError(38, node, "You must specify a port name for all p:output ports."); } String primary = node.getAttributeValue(new QName("primary")); String sequence = node.getAttributeValue(new QName("sequence")); Output output = new Output(runtime, node); output.setPort(port); output.setSequence(sequence); output.setPrimary(primary); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { Binding binding = readBinding(parent, snode); if (binding != null) { output.addBinding(binding); } } checkExtensionAttributes(node, output); return output; }
private Output readOutput(Step parent, XdmNode node) { checkAttributes(node, new String[] { "port", "primary", "sequence" }, false); String port = checkNCName(node.getAttributeValue(new QName("port"))); if (port == null) { throw XProcException.staticError(38, node, "You must specify a port name for all p:output ports."); } String primary = node.getAttributeValue(new QName("primary")); String sequence = node.getAttributeValue(new QName("sequence")); Output output = new Output(runtime, node); output.setPort(port); output.setSequence(sequence); output.setPrimary(primary); for (XdmNode snode : new AxisNodes(runtime, node, Axis.CHILD, AxisNodes.PIPELINE)) { Binding binding = readBinding(parent, snode); if (binding != null) { output.addBinding(binding); } } checkExtensionAttributes(node, output); return output; }
@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); }