public XdmNode loadDocument(Load load) { boolean validate = load.getOption(_dtd_validate, false); RuntimeValue href = load.getOption(_href); String base = href.getBaseURI().toASCIIString(); if (runtime.getSafeMode() && base.startsWith("file:")) { throw XProcException.dynamicError(21); } return runtime.parse(href.getString(), base, validate); }
Predicate<XdmNode> parseOption(RuntimeValue option) throws XPathException { if (!option.getString().equals("/*")) { XPathExpression matcher = SaxonHelper.compileExpression(option.getString(), option.getNamespaceBindings(), config); return n -> n.getNodeKind() == XdmNodeKind.ELEMENT && SaxonHelper.evaluateBoolean(matcher, n); } else return n -> false; }
private void setParametersOnPipeline(XPipeline pipeline, String port, Map<QName, String> parameters) { if ("*".equals(port)) { for (QName name : parameters.keySet()) { pipeline.setParameter(name, new RuntimeValue(parameters.get(name))); } } else { for (QName name : parameters.keySet()) { pipeline.setParameter(port, name, new RuntimeValue(parameters.get(name))); } } }
public void setParameter(QName name, RuntimeValue value) { params.put(name, value.getString()); }
localBindings = nsv.getNamespaceBindings(); } else if (nsbinding.getXPath() != null) { try { XdmAtomicValue avalue = new XdmAtomicValue(globals.get(varname).getString()); selector.setVariable(varname,avalue); nsBindings = val.getNamespaceBindings(); return new RuntimeValue(value,results,var.getNode(),nsBindings); } else { return new RuntimeValue(value,var.getNode(),nsBindings);
public void match(XdmNode doc, RuntimeValue match) { XdmNode node = match.getNode(); String expr = match.getString(); NamespaceResolver resolver = new MatchingNamespaceResolver(match.getNamespaceBindings()); xeval.getStaticContext().setNamespaceResolver(resolver); matcher = xeval.createPattern(match.getString()); } catch (Exception e) { if (e.getMessage() != null && e.getMessage().contains("syntax error")) { throw XProcException.dynamicError(23,node,e,"Syntax error in match pattern: \"" + match.getString() + "\""); } else { throw new XProcException(e);
public void run() throws SaxonApiException { super.run(); RuntimeValue attrNameValue = getOption(_attribute); String attrNameStr = attrNameValue.getString(); String apfx = getOption(_attribute_prefix, (String) null); String ans = getOption(_attribute_namespace, (String) null); if (apfx != null && ans == null) { throw XProcException.dynamicError(34, "You can't specify a prefix without a namespace"); } if (ans != null && attrNameStr.contains(":")) { throw XProcException.dynamicError(34, "You can't specify a namespace if the attribute name contains a colon"); } if (attrNameStr.contains(":")) { attribute = new QName(attrNameStr, attrNameValue.getNode()); } else { // For Saxon 9.4, make sure there's some sort of prefix if there's a namespace; // Saxon will take care of resolving collisions, if necessary if (apfx == null && ans != null) { apfx = "_1"; } attribute = new QName(apfx == null ? "" : apfx, ans, attrNameStr); } label = getOption(_label); replace = getOption(_replace).getBoolean(); matcher = new ProcessMatch(runtime, this); matcher.match(source.read(), getOption(_match)); result.write(matcher.getResult()); }
public void run() throws SaxonApiException { super.run(); if (getOption(_from) != null) { from = getOption(_from).getString(); } else { from = ""; } if (getOption(_to) != null) { to = getOption(_to).getString(); } else { to = ""; } applyTo = getOption(_apply_to, "all"); if (XMLConstants.XML_NS_URI.equals(from) || XMLConstants.XML_NS_URI.equals(to) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(from) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(to)) { throw XProcException.stepError(14); } if (from.equals(to)) { result.write(source.read()); } else { matcher = new ProcessMatch(runtime, this); matcher.match(source.read(), new RuntimeValue("*", step.getNode())); result.write(matcher.getResult()); } if (source.moreDocuments()) { throw XProcException.dynamicError(6, "Reading source on " + getStep().getName()); } }
public void run() throws SaxonApiException { super.run(); RuntimeValue match = getOption(_match); replace = getOption(_replace); for (String prefix : replace.getNamespaceBindings().keySet()) { rns.put(prefix, replace.getNamespaceBindings().get(prefix)); } matcher = new ProcessMatch(runtime, this); matcher.match(source.read(), match); result.write(matcher.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()); }
public int getOption(QName name, int defaultValue) { if (options == null || !options.containsKey(name)) { return defaultValue; } return options.get(name).getInt(); }
public boolean getOption(QName name, boolean defaultValue) { if (options == null || !options.containsKey(name)) { return defaultValue; } return options.get(name).getBoolean(); }
public void setParameter(QName name, RuntimeValue value) { params.put(name, value.getString()); }
localBindings = nsv.getNamespaceBindings(); } else if (nsbinding.getXPath() != null) { try { XdmAtomicValue avalue = new XdmAtomicValue(globals.get(varname).getString()); selector.setVariable(varname,avalue); nsBindings = val.getNamespaceBindings(); return new RuntimeValue(value,results,var.getNode(),nsBindings); } else { return new RuntimeValue(value,var.getNode(),nsBindings);
public void match(XdmNode doc, RuntimeValue match) { XdmNode node = match.getNode(); String expr = match.getString(); NamespaceResolver resolver = new MatchingNamespaceResolver(match.getNamespaceBindings()); xeval.getStaticContext().setNamespaceResolver(resolver); matcher = xeval.createPattern(match.getString()); } catch (Exception e) { if (e.getMessage() != null && e.getMessage().contains("syntax error")) { throw XProcException.dynamicError(23,node,e,"Syntax error in match pattern: \"" + match.getString() + "\""); } else { throw new XProcException(e);
public void run() throws SaxonApiException { super.run(); RuntimeValue attrNameValue = getOption(_attribute); String attrNameStr = attrNameValue.getString(); String apfx = getOption(_attribute_prefix, (String) null); String ans = getOption(_attribute_namespace, (String) null); if (apfx != null && ans == null) { throw XProcException.dynamicError(34, "You can't specify a prefix without a namespace"); } if (ans != null && attrNameStr.contains(":")) { throw XProcException.dynamicError(34, "You can't specify a namespace if the attribute name contains a colon"); } if (attrNameStr.contains(":")) { attribute = new QName(attrNameStr, attrNameValue.getNode()); } else { // For Saxon 9.4, make sure there's some sort of prefix if there's a namespace; // Saxon will take care of resolving collisions, if necessary if (apfx == null && ans != null) { apfx = "_1"; } attribute = new QName(apfx == null ? "" : apfx, ans, attrNameStr); } label = getOption(_label); replace = getOption(_replace).getBoolean(); matcher = new ProcessMatch(runtime, this); matcher.match(source.read(), getOption(_match)); result.write(matcher.getResult()); }
public void run() throws SaxonApiException { super.run(); if (getOption(_from) != null) { from = getOption(_from).getString(); } else { from = ""; } if (getOption(_to) != null) { to = getOption(_to).getString(); } else { to = ""; } applyTo = getOption(_apply_to, "all"); if (XMLConstants.XML_NS_URI.equals(from) || XMLConstants.XML_NS_URI.equals(to) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(from) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(to)) { throw XProcException.stepError(14); } if (from.equals(to)) { result.write(source.read()); } else { matcher = new ProcessMatch(runtime, this); matcher.match(source.read(), new RuntimeValue("*", step.getNode())); result.write(matcher.getResult()); } if (source.moreDocuments()) { throw XProcException.dynamicError(6, "Reading source on " + getStep().getName()); } }
public void run() throws SaxonApiException { super.run(); RuntimeValue match = getOption(_match); replace = getOption(_replace); for (String prefix : replace.getNamespaceBindings().keySet()) { rns.put(prefix, replace.getNamespaceBindings().get(prefix)); } matcher = new ProcessMatch(runtime, this); matcher.match(source.read(), match); result.write(matcher.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()); }
public int getOption(QName name, int defaultValue) { if (options == null || !options.containsKey(name)) { return defaultValue; } return options.get(name).getInt(); }