Class XMLAttributesImpl

java.lang.Object
org.htmlunit.cyberneko.xerces.util.XMLAttributesImpl
All Implemented Interfaces:
XMLAttributes, Attributes, Attributes2
Direct Known Subclasses:
XMLAttributesImpl.EmptyXMLAttributesImpl

public class XMLAttributesImpl extends Object implements XMLAttributes
The XMLAttributesImpl class is an implementation of the XMLAttributes interface which defines a collection of attributes for an element. In the parser, the document source scans the entire start element and collects the attributes, communicating them to the document handler via the startElement method.

The attributes are read-write so that subsequent stages in the document pipeline can modify values or change attributes propagated to the next stage.

Author:
Andy Clark, IBM, Elena Litani, IBM, Michael Glavassevich, IBM, Ronald Brill
See Also:
  • Constructor Details

    • XMLAttributesImpl

      public XMLAttributesImpl()
      Constructs a default XMLAttributesImpl instance with an initial capacity.
    • XMLAttributesImpl

      public XMLAttributesImpl(XMLAttributesImpl attributes)
      Constructs a copy of the specified attribute collection.
      Parameters:
      attributes - the attribute collection to copy from
  • Method Details

    • addAttribute

      public int addAttribute(QName name, String type, String value)
      Adds an attribute. The attribute's non-normalized value will have the same value as the attribute value. Also, the added attribute will be marked as specified in the XML instance document unless set otherwise using the setSpecified(int, boolean) method.

      Note: This implementation does not check whether an attribute of the same name already exists. If duplicate prevention is required, the caller must verify uniqueness before calling this method.

      Specified by:
      addAttribute in interface XMLAttributes
      Parameters:
      name - the attribute name
      type - the attribute type. The type name is determined by the type specified for this attribute in the DTD (e.g., "CDATA", "ID", "NMTOKEN", etc.). Enumeration types will have the type value specified as a pipe-separated list enclosed in parentheses, for example: "(true|false)".
      value - the attribute value
      Returns:
      the zero-based attribute index
      See Also:
    • addAttribute

      public void addAttribute(QName name, String type, String value, boolean specified)
      Adds an attribute. The attribute's non-normalized value will have the same value as the attribute value. Also, the added attribute will be marked as specified in the XML instance document unless set otherwise using the setSpecified(int, boolean) method.

      This method differs from other addAttribute variants in that it does not check if an attribute of the same name already exists in the list before adding it. To improve performance of namespace processing, this method allows uniqueness checks to be deferred until all namespace information is available after the entire attribute specification has been read.

      Caution: If this method is called, it should not be mixed with standard addAttribute calls unless it has been determined that all attribute names are unique.

      Parameters:
      name - the attribute name
      type - the attribute type
      value - the attribute value
      specified - true if the attribute was specified in the instance document
    • addAttribute

      public void addAttribute(QName name, String type, String value, String nonNormalizedValue, boolean specified)
      Adds an attribute together with its non-normalized (plain) value.

      This variant stores both the normalized value and the original nonNormalizedValue so that downstream consumers can access the raw attribute text via getNonNormalizedValue(int).

      Like other addAttribute overloads, this method does not check for duplicate attribute names.

      Parameters:
      name - the attribute name
      type - the attribute type (e.g., "CDATA")
      value - the normalized attribute value
      nonNormalizedValue - the original, non-normalized attribute value
      specified - true if the attribute was specified in the instance document
    • removeAllAttributes

      public void removeAllAttributes()
      Removes all attributes from the collection. This method also removes all entities associated with the attributes.
      Specified by:
      removeAllAttributes in interface XMLAttributes
    • removeAttributeAt

      public void removeAttributeAt(int attrIndex)
      Removes the attribute at the specified index.

      Note: This operation shifts the indices of all attributes following the specified index.

      Specified by:
      removeAttributeAt in interface XMLAttributes
      Parameters:
      attrIndex - the zero-based attribute index
    • setName

      public void setName(int attrIndex, QName attrName)
      Sets the name of the attribute at the specified index.
      Specified by:
      setName in interface XMLAttributes
      Parameters:
      attrIndex - the zero-based attribute index
      attrName - the new attribute name
    • getName

      public void getName(int attrIndex, QName attrName)
      Populates the fields of the given QName structure with the values of the attribute name at the specified index.
      Specified by:
      getName in interface XMLAttributes
      Parameters:
      attrIndex - the zero-based attribute index
      attrName - the attribute name structure to fill in
    • setValue

      public void setValue(int attrIndex, String attrValue)
      Sets the value of the attribute at the specified index. This method also overwrites the non-normalized value of the attribute.
      Specified by:
      setValue in interface XMLAttributes
      Parameters:
      attrIndex - the zero-based attribute index
      attrValue - the new attribute value
    • setSpecified

      public void setSpecified(int attrIndex, boolean specified)
      Sets whether an attribute was specified in the instance document.
      Specified by:
      setSpecified in interface XMLAttributes
      Parameters:
      attrIndex - the zero-based attribute index
      specified - true if the attribute is specified in the instance document
    • isSpecified

      public boolean isSpecified(int attrIndex)
      Returns whether the attribute at the specified index was specified in the instance document.
      Specified by:
      isSpecified in interface Attributes2
      Parameters:
      attrIndex - the zero-based attribute index
      Returns:
      true if specified, false otherwise
    • getLength

      public int getLength()
      Returns the number of attributes in the list.

      Once you know the number of attributes, you can iterate through the list.

      Specified by:
      getLength in interface Attributes
      Returns:
      the number of attributes in the list
    • getType

      public String getType(int index)
      Looks up an attribute's type by index.

      The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case).

      If the parser has not read a declaration for the attribute, or if it does not report attribute types, it must return "CDATA" as stated in the XML 1.0 Recommendation (clause 3.3.3, "Attribute-Value Normalization").

      Specified by:
      getType in interface Attributes
      Parameters:
      index - the zero-based attribute index
      Returns:
      the attribute's type as a string, or null if out of range
      See Also:
    • getType

      public String getType(String qname)
      Looks up an attribute's type by XML 1.0 qualified name.

      See getType(int) for a description of possible types.

      Specified by:
      getType in interface Attributes
      Parameters:
      qname - the XML 1.0 qualified name
      Returns:
      the attribute type as a string, or null if not found
    • getValue

      public String getValue(int index)
      Looks up an attribute's value by index.

      If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), tokens are concatenated into a single string separated by a single space.

      Specified by:
      getValue in interface Attributes
      Parameters:
      index - the zero-based attribute index
      Returns:
      the attribute's value as a string, or null if out of range
      See Also:
    • getValue

      public String getValue(String qname)
      Looks up an attribute's value by XML 1.0 qualified name.

      See getValue(int) for a description of possible values.

      Specified by:
      getValue in interface Attributes
      Parameters:
      qname - the XML 1.0 qualified name
      Returns:
      the attribute value as a string, or null if not found
    • getNameRawName

      public String getNameRawName(int index)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

      Returns the raw (prefixed) name of the attribute at the given index. This is a convenience shortcut equivalent to getName(index).getRawname() with bounds checking.

      Parameters:
      index - the zero-based attribute index
      Returns:
      the raw name of the indexed attribute, or null if out of range
      See Also:
    • getName

      public QName getName(int index)
      Returns the full QName structure of the attribute at the specified index.
      Specified by:
      getName in interface XMLAttributes
      Parameters:
      index - the zero-based attribute index
      Returns:
      the attribute's full QName
    • getIndex

      public int getIndex(String qName)
      Looks up the index of an attribute by XML 1.0 qualified name.
      Specified by:
      getIndex in interface Attributes
      Parameters:
      qName - the qualified (prefixed) name
      Returns:
      the attribute index, or -1 if it does not appear in the list
    • getIndex

      public int getIndex(String uri, String localPart)
      Looks up the index of an attribute by Namespace name.
      Specified by:
      getIndex in interface Attributes
      Parameters:
      uri - the Namespace URI, or null if none
      localPart - the attribute's local name
      Returns:
      the attribute index, or -1 if it does not appear in the list
    • getLocalName

      public String getLocalName(int index)
      Looks up an attribute's local name by index.
      Specified by:
      getLocalName in interface Attributes
      Parameters:
      index - the zero-based attribute index
      Returns:
      the local name, empty string if namespaces are disabled, or null if out of range
      See Also:
    • getQName

      public String getQName(int index)
      Looks up an attribute's XML 1.0 qualified name by index.
      Specified by:
      getQName in interface Attributes
      Parameters:
      index - the zero-based attribute index
      Returns:
      the qualified name, empty string if none available, or null if out of range
      See Also:
    • getType

      public String getType(String uri, String localName)
      Looks up an attribute's type by Namespace name.

      See getType(int) for a description of possible types.

      Specified by:
      getType in interface Attributes
      Parameters:
      uri - the Namespace URI, or null if none
      localName - the local name of the attribute
      Returns:
      the attribute type, or null if not found
    • getURI

      public String getURI(int index)
      Looks up an attribute's Namespace URI by index.
      Specified by:
      getURI in interface Attributes
      Parameters:
      index - the zero-based attribute index
      Returns:
      the Namespace URI, or null if out of range
      See Also:
    • getValue

      public String getValue(String uri, String localName)
      Looks up an attribute's value by Namespace name.

      See getValue(int) for a description of possible values.

      Specified by:
      getValue in interface Attributes
      Parameters:
      uri - the Namespace URI, or null if none
      localName - the local name of the attribute
      Returns:
      the attribute value, or null if not found
    • getNonNormalizedValue

      public String getNonNormalizedValue(int index)
      Returns the non-normalized value of the attribute at the specified index. If no non-normalized value is set, this method returns the same value as the Attributes.getValue(int) method.
      Specified by:
      getNonNormalizedValue in interface XMLAttributes
      Parameters:
      index - the zero-based index of the attribute
      Returns:
      the non-normalized value of the attribute at the specified index
    • isDeclared

      public boolean isDeclared(int index)
      Specified by:
      isDeclared in interface Attributes2
    • isDeclared

      public boolean isDeclared(String qName)
      Specified by:
      isDeclared in interface Attributes2
    • isDeclared

      public boolean isDeclared(String uri, String localName)
      Specified by:
      isDeclared in interface Attributes2
    • isSpecified

      public boolean isSpecified(String qName)
      Specified by:
      isSpecified in interface Attributes2
    • isSpecified

      public boolean isSpecified(String uri, String localName)
      Specified by:
      isSpecified in interface Attributes2
    • getAttributes

      public ArrayList<XMLAttributesImpl.Attribute> getAttributes()
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Returns:
      the internal attributes ArrayList to allow performance optimizations