/** * It is possible for a single output element to use the same prefix to refer to different * namespaces. In this case we have to generate an alternative prefix for uniqueness. The * one we generate is based on the sequential position of the element/attribute: this is * designed to ensure both uniqueness (with a high probability) and repeatability * @param nscode the namespace code of the proposed element or attribute name * @param seq sequence number of attribute, used for generating distinctive prefixes * @return the actual allocated name, which may be different. */ private String getSubstitutePrefix(int nscode, int seq) { String prefix = getNamePool().getPrefixFromNamespaceCode(nscode); return prefix + '_' + seq; }
/** * It is possible for a single output element to use the same prefix to refer to different * namespaces. In this case we have to generate an alternative prefix for uniqueness. The * one we generate is based on the sequential position of the element/attribute: this is * designed to ensure both uniqueness (with a high probability) and repeatability * @param nscode the namespace code of the proposed element or attribute name * @param seq sequence number of attribute, used for generating distinctive prefixes * @return the actual allocated name, which may be different. */ private String getSubstitutePrefix(int nscode, int seq) { String prefix = getNamePool().getPrefixFromNamespaceCode(nscode); return prefix + '_' + seq; }
/** * Get an iterator over all the prefixes declared in this namespace context. This will include * the default namespace (prefix="") and the XML namespace where appropriate */ public Iterator iteratePrefixes() { NamePool pool = getNamePool(); List prefixes = new ArrayList(namespacesSize); for (int i=namespacesSize-1; i>=0; i--) { String prefix = pool.getPrefixFromNamespaceCode(namespaces[i]); if (!prefixes.contains(prefix)) { prefixes.add(prefix); } } prefixes.add("xml"); return prefixes.iterator(); }
/** * Get an iterator over all the prefixes declared in this namespace context. This will include * the default namespace (prefix="") and the XML namespace where appropriate */ public Iterator iteratePrefixes() { NamePool pool = getNamePool(); List prefixes = new ArrayList(namespacesSize); for (int i=namespacesSize-1; i>=0; i--) { String prefix = pool.getPrefixFromNamespaceCode(namespaces[i]); if (!prefixes.contains(prefix)) { prefixes.add(prefix); } } prefixes.add("xml"); return prefixes.iterator(); }
public void setPipelineConfiguration(PipelineConfiguration config) { super.setPipelineConfiguration(config); bufferedAttributes = new AttributeCollectionImpl(getNamePool()); }
/** * Get the namespace URI corresponding to a given prefix. Return null * if the prefix is not in scope. * * @param prefix the namespace prefix * @param useDefault true if the default namespace is to be used when the * prefix is "" * @return the uri for the namespace, or null if the prefix is not in scope */ public String getURIForPrefix(String prefix, boolean useDefault) { NamePool pool = getNamePool(); if ((prefix==null || prefix.length()==0) && !useDefault) { return ""; } else if ("xml".equals(prefix)) { return NamespaceConstant.XML; } else { short prefixCode = pool.getCodeForPrefix(prefix); short uriCode = getURICode(prefixCode); if (uriCode == -1) { return null; } return pool.getURIFromURICode(uriCode); } }
/** * Get the namespace URI corresponding to a given prefix. Return null * if the prefix is not in scope. * * @param prefix the namespace prefix * @param useDefault true if the default namespace is to be used when the * prefix is "" * @return the uri for the namespace, or null if the prefix is not in scope */ public String getURIForPrefix(String prefix, boolean useDefault) { NamePool pool = getNamePool(); if ((prefix==null || prefix.length()==0) && !useDefault) { return ""; } else if ("xml".equals(prefix)) { return NamespaceConstant.XML; } else { short prefixCode = pool.getCodeForPrefix(prefix); short uriCode = getURICode(prefixCode); if (uriCode == -1) { return null; } return pool.getURIFromURICode(uriCode); } }
/** * startElement */ public void startElement(int nameCode, int typeCode, int locationId, int properties) throws XPathException { elementNameCode = nameCode; elementTypeCode = typeCode; elementLocationId = locationId; elementProperties = properties; bufferedAttributes.clear(); // Record the current height of the namespace list so it can be reset at endElement time countStack[depth] = 0; if (++depth >= countStack.length) { int[] newstack = new int[depth*2]; System.arraycopy(countStack, 0, newstack, 0, depth); countStack = newstack; } // Ensure that the element namespace is output, unless this is done // automatically by the caller (which is true, for example, for a literal // result element). acceptAttributes = true; inDocument = false; if ((properties & ReceiverOptions.NAMESPACE_OK) == 0) { namespace(getNamePool().allocateNamespaceCode(nameCode), 0); } attCount = 0; }
/** * startElement */ public void startElement(int nameCode, int typeCode, int locationId, int properties) throws XPathException { elementNameCode = nameCode; elementTypeCode = typeCode; elementLocationId = locationId; elementProperties = properties; bufferedAttributes.clear(); // Record the current height of the namespace list so it can be reset at endElement time countStack[depth] = 0; if (++depth >= countStack.length) { int[] newstack = new int[depth*2]; System.arraycopy(countStack, 0, newstack, 0, depth); countStack = newstack; } // Ensure that the element namespace is output, unless this is done // automatically by the caller (which is true, for example, for a literal // result element). acceptAttributes = true; inDocument = false; if ((properties & ReceiverOptions.NAMESPACE_OK) == 0) { namespace(getNamePool().allocateNamespaceCode(nameCode), 0); } attCount = 0; elementNode = null; }
public void namespace(int namespaceCode, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, getNamePool().getPrefixFromNamespaceCode(namespaceCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // avoid duplicates for (int n=0; n<countStack[depth - 1]; n++) { if (namespaces[namespacesSize - 1 - n] == namespaceCode) { return; } } addToStack(namespaceCode); countStack[depth - 1]++; }
public void namespace(int namespaceCode, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, getNamePool().getPrefixFromNamespaceCode(namespaceCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // avoid duplicates for (int n=0; n<countStack[depth - 1]; n++) { if (namespaces[namespacesSize - 1 - n] == namespaceCode) { return; } } addToStack(namespaceCode); countStack[depth - 1]++; }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute, as held in the name pool * @param typeCode The type of the attribute, as held in the name pool * @param properties Bit significant value. The following bits are defined: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.ATTRIBUTE, getNamePool().getDisplayName(nameCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // Perform namespace fixup for the attribute if (((properties & ReceiverOptions.NAMESPACE_OK) == 0) && NamePool.getPrefixIndex(nameCode) != 0) { // non-null prefix nameCode = checkProposedPrefix(nameCode, attCount++); } bufferedAttributes.addAttribute(nameCode, typeCode, value.toString(), locationId, properties); // Note: we're relying on the fact that AttributeCollection can hold two attributes of the same name // and maintain their order, because the check for duplicate attributes is not done until later in the // pipeline. We validate both the attributes (see Bugzilla #4600 which legitimizes this.) }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute, as held in the name pool * @param typeCode The type of the attribute, as held in the name pool * @param properties Bit significant value. The following bits are defined: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.ATTRIBUTE, getNamePool().getDisplayName(nameCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // Perform namespace fixup for the attribute if (((properties & ReceiverOptions.NAMESPACE_OK) == 0) && NamePool.getPrefixIndex(nameCode) != 0) { // non-null prefix nameCode = checkProposedPrefix(nameCode, attCount++); } bufferedAttributes.addAttribute(nameCode, typeCode, value.toString(), locationId, properties); // Note: we're relying on the fact that AttributeCollection can hold two attributes of the same name // and maintain their order, because the check for duplicate attributes is not done until later in the // pipeline. We validate both the attributes (see Bugzilla #4600 which proposes to legitimize this.) }
NamePool namePool = getNamePool(); int nscode = namePool.getNamespaceCode(nameCode); if (nscode == -1) {
NamePool namePool = getNamePool(); int nscode = namePool.getNamespaceCode(nameCode); if (nscode == -1) {