Class Attribute

  • All Implemented Interfaces:, java.lang.Cloneable, org.w3c.dom.Attr, org.w3c.dom.Node, Item, Namespaceable

    public class Attribute
    extends AbstractItem
    implements Namespaceable, org.w3c.dom.Attr
    The iDOM attribute.

    Design decision: Attribute is also a item. The reason is it simplifies the use of XPath. An XPath might return either elements or attributes, so...

    See Also:
    Element, Serialized Form
    • Field Detail

      • _ns

        protected Namespace _ns
        The namespace.
      • _owner

        protected Item _owner
        The owner item.
      • _lname

        protected java.lang.String _lname
        The local name.
      • _value

        protected java.lang.String _value
        The value.
    • Constructor Detail

      • Attribute

        public Attribute​(java.lang.String nsURI,
                         java.lang.String tname,
                         java.lang.String value)

        Note: According to W3/DOM, the namespace of attributes must have a prefix if the uri is not empty.

        nsURI - the namespace URI
        tname - the tag name
      • Attribute

        public Attribute​(Namespace ns,
                         java.lang.String lname,
                         java.lang.String value)
        ns - the namespace
        lname - the local name
      • Attribute

        public Attribute​(java.lang.String lname,
                         java.lang.String value)
      • Attribute

        protected Attribute()
    • Method Detail

      • getValue

        public final java.lang.String getValue()
        Gets the value of this attribute.
        Specified by:
        getValue in interface org.w3c.dom.Attr
      • setValue

        public final void setValue​(java.lang.String value)
        Sets the value of this attribute. According to Section 3.3.3 of XML 1.0 spec, the value is always normalized. Whether to trim depends on whether an attribute is CDATA (default). In this version, we don't normalize or trim (i.e., consider it as CDATA).
        Specified by:
        setValue in interface org.w3c.dom.Attr
        value - the new value; null is considered as empty
      • getOwner

        public final Item getOwner()
        Gets the item that owns this attribute.
      • setOwner

        public final void setOwner​(Item owner)
        Sets the item that owns this attribute.

        DO NOT call this method. It is used internally. For user's point of view, the owner item is maintained automatically, so user never needs to update it.

      • setNamespace

        public final void setNamespace​(java.lang.String prefix,
                                       java.lang.String nsURI)
        Sets the namespace.
      • setNamespace

        public final void setNamespace​(Namespace ns)
        Sets the namespace.

        According W3C/DOM, unlike element, an attribute doesn't allow a namespace that has an URI but without a prefix.

        Specified by:
        setNamespace in interface Namespaceable
      • getTagName

        public final java.lang.String getTagName()
        Description copied from interface: Namespaceable
        Gets the tag name of this item. The tag name is also called the fully qualified name -- the name with the namespace prefix, e.g., prefix:name.

        To get the local name (the name without prefix), Namespaceable.getLocalName could be used.

        Specified by:
        getTagName in interface Namespaceable
      • setTagName

        public final void setTagName​(java.lang.String tname)
        Sets the tag name.

        Changing a name improperly might cause replicated attribute names which won't be detected by this method.

        Specified by:
        setTagName in interface Namespaceable
      • getLocalName

        public final java.lang.String getLocalName()
        Description copied from interface: Namespaceable
        Gets the local name of this item. The local name is the name without prefix.

        To get the tag name (the name with prefix), Namespaceable.getTagName could be used.

        Specified by:
        getLocalName in interface Namespaceable
        Specified by:
        getLocalName in interface org.w3c.dom.Node
        getLocalName in class AbstractItem
      • setLocalName

        public final void setLocalName​(java.lang.String lname)
        Sets the local name of this attribute.

        Changing a name improperly might cause replicated attribute names which won't be detected by this method.

        Specified by:
        setLocalName in interface Namespaceable
      • getName

        public final java.lang.String getName()
        Description copied from interface: Item
        Gets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as getTagName.
        Specified by:
        getName in interface org.w3c.dom.Attr
        Specified by:
        getName in interface Item
        See Also:
      • getText

        public final java.lang.String getText()
        Description copied from interface: Item
        Gets the text of this item, or null if it is neither Textual nor Element. For Element, the text is the concatenation of all its textual children, including Text, CDATA, and Binary.

        Besides String-type value, some item, e.g., Binary, allows any type of objects. Caller could test whether a item implements the Binable interface, and use Binable.getValue instead. For binable vertices, getText is actually getValue().toString().

        The returned value is neither trimmed nor normalized.

        Specified by:
        getText in interface Item
        getText in class AbstractItem
      • setText

        public final void setText​(java.lang.String text)
        Description copied from interface: Item
        Sets the text of this item.
        Specified by:
        setText in interface Item
        setText in class AbstractItem
      • detach

        public Item detach()
        Detach the attribute from its owner, if any. Only attributes that belongs to no item or the same item are allowed to be added to a item. So, detach is useful to move an attribute out from a item (and then you might add it to another item).
        Specified by:
        detach in interface Item
        detach in class AbstractItem
        this item
      • setParent

        public void setParent​(Item parent)
      • getNodeType

        public final short getNodeType()
        Specified by:
        getNodeType in interface org.w3c.dom.Node
      • getOwnerDocument

        public final org.w3c.dom.Document getOwnerDocument()
        Specified by:
        getOwnerDocument in interface org.w3c.dom.Node
        getOwnerDocument in class AbstractItem
      • getNamespaceURI

        public final java.lang.String getNamespaceURI()
        Specified by:
        getNamespaceURI in interface org.w3c.dom.Node
        getNamespaceURI in class AbstractItem
      • getPrefix

        public final java.lang.String getPrefix()
        Specified by:
        getPrefix in interface org.w3c.dom.Node
        getPrefix in class AbstractItem
      • setPrefix

        public final void setPrefix​(java.lang.String prefix)
        Sets the namespace prefix of this attribute.

        Changing a prefix improperly might cause replicated attribute names which won't be detected by this method.

        Specified by:
        setPrefix in interface org.w3c.dom.Node
        setPrefix in class AbstractItem
      • getSchemaTypeInfo

        public org.w3c.dom.TypeInfo getSchemaTypeInfo()
        Specified by:
        getSchemaTypeInfo in interface org.w3c.dom.Attr
      • isId

        public boolean isId()
        Specified by:
        isId in interface org.w3c.dom.Attr
      • getSpecified

        public final boolean getSpecified()
        Specified by:
        getSpecified in interface org.w3c.dom.Attr
      • getOwnerElement

        public final org.w3c.dom.Element getOwnerElement()
        Specified by:
        getOwnerElement in interface org.w3c.dom.Attr
      • toString

        public final java.lang.String toString()
        toString in class java.lang.Object
      • clone

        public java.lang.Object clone()
        Description copied from class: AbstractItem
        Clones this object (a deep cloning not including contents contained in Textual nodes). Note: after cloning, the read-only flag always becomes false, and the parent becomes null (i.e., detached).
        Specified by:
        clone in interface Item
        clone in class AbstractItem