/** * Test whether this node test is satisfied by a given node. This method is only * fully supported for a subset of NodeTests, because it doesn't provide all the information * needed to evaluate all node tests. In particular (a) it can't be used to evaluate a node * test of the form element(N,T) or schema-element(E) where it is necessary to know whether the * node is nilled, and (b) it can't be used to evaluate a node test of the form * document-node(element(X)). This in practice means that it is used (a) to evaluate the * simple node tests found in the XPath 1.0 subset used in XML Schema, and (b) to evaluate * node tests where the node kind is known to be an attribute. * * @param nodeKind The kind of node to be matched * @param name identifies the expanded name of the node to be matched. * The value should be null for a node with no name. * @param annotation The actual content type of the node */ @Override public boolean matches(int nodeKind, NodeName name, SchemaType annotation) { if (nodeKind != this.nodeKind) { return false; } if (name.hasFingerprint()) { return name.getFingerprint() == this.fingerprint; } else { computeUriAndLocal(); return name.hasURI(uri) && name.getLocalPart().equals(localName); } }
/** * Find an attribute by node name * * @param nodeName the name of the required attribute * @return the index of the attribute, or -1 if absent */ public int findByNodeName(/*@NotNull*/ NodeName nodeName) { if (props == null || config == null) { return -1; } if (nodeName.hasFingerprint()) { return findByFingerprint(nodeName.getFingerprint()); } else { return findByName(nodeName.getURI(), nodeName.getLocalPart()); } }
/** * Get the prefix of the name of the node. This is defined only for elements and attributes. * If the node has no prefix, or for other kinds of node, return a zero-length string. * * @return The prefix of the name of the node. */ public String getPrefix() { if (nodeName == null) { return ""; } else { return nodeName.getPrefix(); } }
/** * Indicates whether some other object is "equal to" this one. */ @Override public boolean equals(/*@NotNull*/ Object obj) { return obj instanceof NodeName && ((NodeName) obj).getLocalPart().equals(localName) && ((NodeName) obj).hasURI(""); }
/** * Handle an attribute */ public void attribute(NodeName name, SimpleType type, CharSequence value, Location location, int properties) throws XPathException { checkType(type); int fp = newPool.allocateFingerprint(name.getURI(), name.getLocalPart()); nextReceiver.attribute(new CodedName(fp, name.getPrefix(), newPool), type, value, location, properties); }
NamespaceBinding binding = nodeName.getNamespaceBinding(); String nsprefix = binding.getPrefix(); } else { String prefix = getSubstitutePrefix(binding, seq); NodeName newName = new FingerprintedQName(prefix, nodeName.getURI(), nodeName.getLocalPart()); namespace(newName.getNamespaceBinding(), 0); return newName; NodeName newName = new FingerprintedQName(prefix, nodeName.getURI(), nodeName.getLocalPart()); namespace(newName.getNamespaceBinding(), 0); return newName;
private int hash(NodeName n, int sequence) { //System.err.println("hash(" + n.getLocalPart() + ") " + hash(n.getLocalPart(), sequence) + "/" + hash(n.getURI(), sequence)); return hash(n.getLocalPart(), sequence) ^ hash(n.getURI(), sequence); } }
/** * Test whether this name is in the same namespace as another name * * @return true if the two names are in the same namespace */ public boolean isInSameNamespace(NodeName other) { return other.getURI().isEmpty(); }
public boolean equals(/*@NotNull*/ Object other) { if (other instanceof NodeName) { if (fingerprint != -1 && ((NodeName) other).hasFingerprint()) { return getFingerprint() == ((NodeName) other).getFingerprint(); } else { return getLocalPart().equals(((NodeName) other).getLocalPart()) && isInSameNamespace((NodeName) other); } } else { return false; } }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * Specific treatment of attributes in XHTML, SVG and MathML namespaces forces a namespace to be emitted too, * rather than by higher level default behaviour. * * @param nameCode The name of the attribute * @param typeCode The type of the attribute * @param locationId the location of the node in the source, or of the instruction that created it * @param properties Bit significant value. The following bits are defined: * <dl> * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * </dl> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(NodeName nameCode, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { if(isSpecial(nameCode.getURI())) { super.namespace(nameCode.getNamespaceBinding(),properties); } super.attribute(nameCode, typeCode, value, locationId, properties); } }
/** * Get the local part of the name of this node. This is the name after the ":" if any. * * @return the local part of the name. For an unnamed node, returns "". */ public String getLocalPart() { if (nodeName == null) { return ""; } else { return nodeName.getLocalPart(); } }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param attName The name of the attribute * @param typeCode The type of the attribute * @param locationId location of the attribute * @param properties Bit significant value. The following bits are defined: * <dl> * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * </dl> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(NodeName attName, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { if (depth == 0) { out.startElement(resultAttribute, Untyped.getInstance(), ExplicitLocation.UNKNOWN_LOCATION, 0); if (!attName.hasURI("")) { out.namespace(attName.getNamespaceBinding(), 0); } out.attribute(attName, typeCode, value, locationId, properties); out.startContent(); out.endElement(); } else { out.attribute(attName, typeCode, value, locationId, properties); } }
@Override public int isSpacePreserving(NodeName nodeName, SchemaType schemaType) { return elementTest.test(new QName(nodeName.getStructuredQName())) ? Stripper.ALWAYS_STRIP : Stripper.ALWAYS_PRESERVE; }
/** * Output element start tag */ public void startElement(NodeName elemName, SchemaType typeCode, Location location, int properties) throws XPathException { super.startElement(elemName, typeCode, location, properties); uri = elemName.getURI(); parentElement = elementStack.peek(); if (elemName.hasURI("") && (parentElement.equalsIgnoreCase("script") || parentElement.equalsIgnoreCase("style"))) { inScript = 0; } inScript++; nodeNameStack.push(elemName); }
/** * Callback to output namespace nodes for the new element. * * @param context The execution context * @param receiver the Receiver where the namespace nodes are to be written * @param nodeName the element name * @param copiedNode the node being copied (for xsl:copy), otherwise null * @throws XPathException */ public void outputNamespaceNodes(XPathContext context, Receiver receiver, NodeName nodeName, NodeInfo copiedNode) throws XPathException { if (copyNamespaces) { NamespaceIterator.sendNamespaces(copiedNode, receiver); } else { // Always output the namespace of the element name itself receiver.namespace(nodeName.getNamespaceBinding(), 0); } }
/** * Produce a short string identifying the expression for use in error messages * * @return a short string, sufficient to identify the expression */ @Override public String toShortString() { return "attr{" + nodeName.getDisplayName() + "=...}"; } }
private boolean isRecognizedHtmlElement(NodeName name) { return name.hasURI(NamespaceConstant.XHTML); }
/** * Get the name pool name code of the attribute to be constructed * * @return the attribute's name code */ public int getAttributeFingerprint() { return nodeName.getFingerprint(); }
/** * Output element start tag */ public void startElement(NodeName name, SchemaType type, Location location, int properties) throws XPathException { checkType(type); int fp = newPool.allocateFingerprint(name.getURI(), name.getLocalPart()); nextReceiver.startElement(new CodedName(fp, name.getPrefix(), newPool), type, location, properties); }
/** * Determine whether a given attribute is a URL attribute */ private static boolean isURLAttribute(NodeName elcode, NodeName atcode) { if (!elcode.hasURI(NamespaceConstant.XHTML)) { return false; } if (!atcode.hasURI("")) { return false; } String attName = atcode.getLocalPart(); return attTable.contains(attName) && urlTable.contains(elcode.getLocalPart() + "+" + attName); }