/** * Make a NamespaceTest (name:*) * * @param nodeType integer code identifying the type of node required * @param prefix the namespace prefix * @return the NamespaceTest, a pattern that matches all nodes in this * namespace * @throws XPathException if the namespace prefix is not declared */ /*@NotNull*/ public NamespaceTest makeNamespaceTest(short nodeType, String prefix) throws XPathException { NamePool pool = env.getConfiguration().getNamePool(); if (scanOnly) { // return an arbitrary namespace if we're only doing a syntax check return new NamespaceTest(pool, nodeType, NamespaceConstant.SAXON); } if (prefix.startsWith("Q{")) { String uri = prefix.substring(2, prefix.length() - 2); return new NamespaceTest(pool, nodeType, uri); } try { StructuredQName sq = qNameParser.parse(prefix + ":dummy"); return new NamespaceTest(pool, nodeType, sq.getURI()); } catch (XPathException err) { grumble(err.getMessage(), err.getErrorCodeLocalPart()); return null; } }
private static void exportRuleJS(Rule rule, FastStringBuffer fsb) { String which = rule.getAction() == Stripper.STRIP ? "true" : "false"; NodeTest test = (NodeTest)rule.getPattern().getItemType(); if (test instanceof NodeKindTest) { // elements="*" fsb.append("return " + which + ";"); } else if (test instanceof NameTest) { fsb.append("if (uri=='" + test.getMatchingNodeName().getURI() + "' && local=='" + test.getMatchingNodeName().getLocalPart() + "') return " + which + ";" ); } else if (test instanceof NamespaceTest) { fsb.append("if (uri=='" + ((NamespaceTest)test).getNamespaceURI() + "') return " + which + ";"); } else if (test instanceof LocalNameTest) { fsb.append("if (local=='" + ((LocalNameTest) test).getLocalName() + "') return " + which + ";"); } else { throw new IllegalStateException("Cannot export " + test.getClass()); } } }
/** * Generate Javascript code to test whether an item conforms to this item type * * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns a boolean indication whether the value of the * variable "item" is an instance of this item type. * @param knownToBe An item type that the supplied item is known to conform to; the generated code * can assume that the item is an instance of this type. * @param targetVersion The version of Saxon-JS for which code is being generated. Currently either 1 or 2. */ @Override public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) { if (targetVersion == 1) { return "var q=SaxonJS.U.nameOfNode(item); return SaxonJS.U.isNode(item) && item.nodeType===" + nodeKind + "&&" + generateJavaScriptNameTest(targetVersion); } else { return "return SaxonJS.U.isNode(item) && item.nodeType===" + nodeKind + " && SaxonJS.U.hasURI(item, '" + ExpressionPresenter.jsEscape(uri) + "');"; } }
/** * Make a NamespaceTest (name:*) * * @param nodeType integer code identifying the type of node required * @param prefix the namespace prefix * @return the NamespaceTest, a pattern that matches all nodes in this * namespace * @throws XPathException if the namespace prefix is not declared */ /*@NotNull*/ public NamespaceTest makeNamespaceTest(short nodeType, String prefix) throws XPathException { NamePool pool = env.getConfiguration().getNamePool(); if (scanOnly) { // return an arbitrary namespace if we're only doing a syntax check return new NamespaceTest(pool, nodeType, NamespaceConstant.SAXON); } if (prefix.startsWith("Q{")) { String uri = prefix.substring(2, prefix.length() - 2); return new NamespaceTest(pool, nodeType, uri); } try { StructuredQName sq = qNameParser.parse(prefix + ":dummy"); return new NamespaceTest(pool, nodeType, sq.getURI()); } catch (XPathException err) { grumble(err.getMessage(), err.getErrorCodeLocalPart()); return null; } }
private static void exportRuleJS(Rule rule, FastStringBuffer fsb) { String which = rule.getAction() == Stripper.STRIP ? "true" : "false"; NodeTest test = (NodeTest)rule.getPattern().getItemType(); if (test instanceof NodeKindTest) { // elements="*" fsb.append("return " + which + ";"); } else if (test instanceof NameTest) { fsb.append("if (uri=='" + test.getMatchingNodeName().getURI() + "' && local=='" + test.getMatchingNodeName().getLocalPart() + "') return " + which + ";" ); } else if (test instanceof NamespaceTest) { fsb.append("if (uri=='" + ((NamespaceTest)test).getNamespaceURI() + "') return " + which + ";"); } else if (test instanceof LocalNameTest) { fsb.append("if (local=='" + ((LocalNameTest) test).getLocalName() + "') return " + which + ";"); } else { throw new IllegalStateException("Cannot export " + test.getClass()); } } }
/** * Generate Javascript code to test whether an item conforms to this item type * * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns a boolean indication whether the value of the * variable "item" is an instance of this item type. * @param knownToBe An item type that the supplied item is known to conform to; the generated code * can assume that the item is an instance of this type. * @param targetVersion The version of Saxon-JS for which code is being generated. Currently either 1 or 2. */ @Override public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) { if (targetVersion == 1) { return "var q=SaxonJS.U.nameOfNode(item); return SaxonJS.U.isNode(item) && item.nodeType===" + nodeKind + "&&" + generateJavaScriptNameTest(targetVersion); } else { return "return SaxonJS.U.isNode(item) && item.nodeType===" + nodeKind + " && SaxonJS.U.hasURI(item, '" + ExpressionPresenter.jsEscape(uri) + "');"; } }
/** * Make a NamespaceTest (name:*) * * @param nodeType integer code identifying the type of node required * @param prefix the namespace prefix * @throws XPathException if the namespace prefix is not declared * @return the NamespaceTest, a pattern that matches all nodes in this * namespace */ public NamespaceTest makeNamespaceTest(short nodeType, String prefix) throws XPathException { if (scanOnly) { // return an arbitrary namespace if we're only doing a syntax check return new NamespaceTest(env.getNamePool(), nodeType, NamespaceConstant.SAXON); } try { return new NamespaceTest(env.getNamePool(), nodeType, env.getURIForPrefix(prefix)); } catch (XPathException e) { // env.getURIForPrefix can return a dynamic error grumble(e.getMessage(), "XPST0081"); return null; } }
private lux.xpath.NodeTest nodeTestFor (NodeTest nodeTest) { if (nodeTest == null) { return new lux.xpath.NodeTest(ValueType.NODE); } if (nodeTest instanceof DocumentNodeTest) { return nodeTestFor ((DocumentNodeTest) nodeTest); } int nameCode = nodeTest.getFingerprint(); ValueType nodeType = valueTypeForItemType(nodeTest); if (nameCode >= 0) { // matches a single node name return new lux.xpath.NodeTest (nodeType, qnameForNameCode(nameCode)); } else { // matches multiple node names if (nodeTest instanceof LocalNameTest) { return new lux.xpath.NodeTest (nodeType, new QName(null, ((LocalNameTest)nodeTest).getLocalName(), "*")); } if (nodeTest instanceof NamespaceTest) { NamespaceTest namespaceTest = (NamespaceTest) nodeTest; String namespace = namespaceTest.getNamespaceURI(); String prefix = getPrefixForNamespace (namespace); QName qname = new QName(namespace, "*", prefix); addNamespaceDeclaration(qname); return new lux.xpath.NodeTest (nodeType, qname); } IntSet nameCodes = nodeTest.getRequiredNodeNames(); if (nameCodes == IntUniversalSet.getInstance()) { return new lux.xpath.NodeTest (nodeType); } throw new IllegalArgumentException("Unsupported node test: " + nodeTest.toString()); } }
/** * Make a NamespaceTest (name:*) * * @param nodeType integer code identifying the type of node required * @param prefix the namespace prefix * @throws XPathException if the namespace prefix is not declared * @return the NamespaceTest, a pattern that matches all nodes in this * namespace */ public NamespaceTest makeNamespaceTest(short nodeType, String prefix) throws XPathException { if (scanOnly) { // return an arbitrary namespace if we're only doing a syntax check return new NamespaceTest(env.getNamePool(), nodeType, NamespaceConstant.SAXON); } try { return new NamespaceTest(env.getNamePool(), nodeType, env.getURIForPrefix(prefix)); } catch (XPathException e) { // env.getURIForPrefix can return a dynamic error grumble(e.getMessage(), "XPST0081"); return null; } }
if (test.getPrimitiveType() == Type.ELEMENT) { NamespaceTest nt = (NamespaceTest) test; stepper = new FollowingElementStepper<>(start, nt.getNamespaceURI(), null); } else { stepper = new FollowingFilteredNodeStepper<>(start, test);
nt = new NamespaceTest( getNamePool(), Type.ELEMENT,
if (test.getPrimitiveType() == Type.ELEMENT) { NamespaceTest nt = (NamespaceTest) test; stepper = new FollowingElementStepper<>(start, nt.getNamespaceURI(), null); } else { stepper = new FollowingFilteredNodeStepper<>(start, test);
/** * Helper method to construct a NodeTest for use with the {@link NodeInfo#iterateAxis} method * @param pool the NamePool. The relevant NamePool can be obtained by calling the method * {@link NodeInfo#getNamePool}. * @param nodeKind The kind of node required, for example {@link Type#ELEMENT} or {@link Type#ATTRIBUTE}. * To select nodes of any kind, use {@link Type#NODE}. * @param uri The namespace URI of the nodes to be selected. Supply null to selects nodes from any * namespace or none. Supply "" to select nodes that are not in a namespace. * @param localName The local name of the nodes to be selected. Supply null to select nodes irrespective * of their local name. * @return a NodeTest that matches the requested nodes * @since 9.0 */ public static NodeTest makeNodeTest(NamePool pool, int nodeKind, String uri, String localName) { if (uri == null && localName == null) { return NodeKindTest.makeNodeKindTest(nodeKind); } else if (uri == null) { return new LocalNameTest(pool, nodeKind, localName); } else if (localName == null) { return new NamespaceTest(pool, nodeKind, uri); } else { int fp = pool.allocate("", uri, localName); return new NameTest(nodeKind, fp, pool); } }
nt = new NamespaceTest( getNamePool(), Type.ELEMENT,
/** * Helper method to construct a NodeTest for use with the {@link NodeInfo#iterateAxis} method * @param pool the NamePool. The relevant NamePool can be obtained by calling the method * {@link NodeInfo#getNamePool}. * @param nodeKind The kind of node required, for example {@link Type#ELEMENT} or {@link Type#ATTRIBUTE}. * To select nodes of any kind, use {@link Type#NODE}. * @param uri The namespace URI of the nodes to be selected. Supply null to selects nodes from any * namespace or none. Supply "" to select nodes that are not in a namespace. * @param localName The local name of the nodes to be selected. Supply null to select nodes irrespective * of their local name. * @return a NodeTest that matches the requested nodes * @since 9.0 */ public static NodeTest makeNodeTest(NamePool pool, int nodeKind, String uri, String localName) { if (uri == null && localName == null) { return NodeKindTest.makeNodeKindTest(nodeKind); } else if (uri == null) { return new LocalNameTest(pool, nodeKind, localName); } else if (localName == null) { return new NamespaceTest(pool, nodeKind, uri); } else { int fp = pool.allocate("", uri, localName); return new NameTest(nodeKind, fp, pool); } }
/** * Helper method to construct a NodeTest for use with the {@link NodeInfo#iterateAxis} method * * @param pool the NamePool. * @param nodeKind The kind of node required, for example {@link Type#ELEMENT} or {@link Type#ATTRIBUTE}. * To select nodes of any kind, use {@link Type#NODE}. * @param uri The namespace URI of the nodes to be selected. Supply null to selects nodes from any * namespace or none. Supply "" to select nodes that are not in a namespace. * @param localName The local name of the nodes to be selected. Supply null to select nodes irrespective * of their local name. * @return a NodeTest that matches the requested nodes * @since 9.0 */ /*@Nullable*/ public static NodeTest makeNodeTest(/*@NotNull*/ NamePool pool, int nodeKind, /*@Nullable*/ String uri, /*@Nullable*/ String localName) { if (uri == null && localName == null) { return NodeKindTest.makeNodeKindTest(nodeKind); } else if (uri == null) { return new LocalNameTest(pool, nodeKind, localName); } else if (localName == null) { return new NamespaceTest(pool, nodeKind, uri); } else { int fp = pool.allocateFingerprint(uri, localName); return new NameTest(nodeKind, fp, pool); } }
/** * Helper method to construct a NodeTest for use with the {@link NodeInfo#iterateAxis} method * * @param pool the NamePool. * @param nodeKind The kind of node required, for example {@link Type#ELEMENT} or {@link Type#ATTRIBUTE}. * To select nodes of any kind, use {@link Type#NODE}. * @param uri The namespace URI of the nodes to be selected. Supply null to selects nodes from any * namespace or none. Supply "" to select nodes that are not in a namespace. * @param localName The local name of the nodes to be selected. Supply null to select nodes irrespective * of their local name. * @return a NodeTest that matches the requested nodes * @since 9.0 */ /*@Nullable*/ public static NodeTest makeNodeTest(/*@NotNull*/ NamePool pool, int nodeKind, /*@Nullable*/ String uri, /*@Nullable*/ String localName) { if (uri == null && localName == null) { return NodeKindTest.makeNodeKindTest(nodeKind); } else if (uri == null) { return new LocalNameTest(pool, nodeKind, localName); } else if (localName == null) { return new NamespaceTest(pool, nodeKind, uri); } else { int fp = pool.allocateFingerprint(uri, localName); return new NameTest(nodeKind, fp, pool); } }
test = new NamespaceTest(getNamePool(), Type.ELEMENT, uri); addWildCardTest(componentTypeCode, test); } else if (tok.startsWith("Q{") && tok.endsWith("}*")) { final String uri = tok.substring(2, tok.length() - 2); test = new NamespaceTest(getNamePool(), Type.ELEMENT, uri); wildcardComponentTests.add(new ComponentTest(componentTypeCode, test, -1)); } else if (tok.startsWith("*:")) {
test = new NamespaceTest(getNamePool(), Type.ELEMENT, uri); addWildCardTest(componentTypeCode, test); } else if (tok.startsWith("Q{") && tok.endsWith("}*")) { final String uri = tok.substring(2, tok.length() - 2); test = new NamespaceTest(getNamePool(), Type.ELEMENT, uri); wildcardComponentTests.add(new ComponentTest(componentTypeCode, test, -1)); } else if (tok.startsWith("*:")) {
nt = new NamespaceTest( getNamePool(), Type.ELEMENT,