/** * Make a LocalNameTest (*:name) * * @param nodeType the kind of node to be matched * @param localName the requred local name * @throws XPathException if the local name is invalid * @return a LocalNameTest, a pattern which matches all nodes of a given * local name, regardless of namespace */ public LocalNameTest makeLocalNameTest(short nodeType, String localName) throws XPathException { if (!nameChecker.isValidNCName(localName)) { grumble("Local name [" + localName + "] contains invalid characters"); } return new LocalNameTest(env.getNamePool(), nodeType, localName); }
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.hasLocalName(item, '" + localName + "')"; } }
/** * Make a LocalNameTest (*:name) * * @param nodeType the kind of node to be matched * @param localName the requred local name * @throws XPathException if the local name is invalid * @return a LocalNameTest, a pattern which matches all nodes of a given * local name, regardless of namespace */ public LocalNameTest makeLocalNameTest(short nodeType, String localName) throws XPathException { if (!nameChecker.isValidNCName(localName)) { grumble("Local name [" + localName + "] contains invalid characters"); } return new LocalNameTest(env.getNamePool(), nodeType, localName); }
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.hasLocalName(item, '" + localName + "')"; } }
/** * Make a LocalNameTest (*:name) * * @param nodeType the kind of node to be matched * @param localName the requred local name * @return a LocalNameTest, a pattern which matches all nodes of a given * local name, regardless of namespace * @throws XPathException if the local name is invalid */ /*@NotNull*/ public LocalNameTest makeLocalNameTest(short nodeType, String localName) throws XPathException { if (!NameChecker.isValidNCName(localName)) { grumble("Local name [" + localName + "] contains invalid characters"); } return new LocalNameTest(env.getConfiguration().getNamePool(), nodeType, localName); }
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 LocalNameTest (*:name) * * @param nodeType the kind of node to be matched * @param localName the requred local name * @return a LocalNameTest, a pattern which matches all nodes of a given * local name, regardless of namespace * @throws XPathException if the local name is invalid */ /*@NotNull*/ public LocalNameTest makeLocalNameTest(short nodeType, String localName) throws XPathException { if (!NameChecker.isValidNCName(localName)) { grumble("Local name [" + localName + "] contains invalid characters"); } return new LocalNameTest(env.getConfiguration().getNamePool(), nodeType, localName); }
if (test.getPrimitiveType() == Type.ELEMENT) { LocalNameTest nt = (LocalNameTest) test; stepper = new FollowingElementStepper<>(start, null, nt.getLocalName()); } else { stepper = new FollowingFilteredNodeStepper<>(start, test);
nt = new LocalNameTest( getNamePool(), Type.ELEMENT,
if (test.getPrimitiveType() == Type.ELEMENT) { LocalNameTest nt = (LocalNameTest) test; stepper = new FollowingElementStepper<>(start, null, nt.getLocalName()); } else { stepper = new FollowingFilteredNodeStepper<>(start, test);
nt = new LocalNameTest( 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. 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 LocalNameTest(getNamePool(), Type.ELEMENT, localname); addWildCardTest(componentTypeCode, test);
test = new LocalNameTest(getNamePool(), Type.ELEMENT, localname); addWildCardTest(componentTypeCode, test);
nt = new LocalNameTest( getNamePool(), Type.ELEMENT,