Class Attribute
- java.lang.Object
-
- org.zkoss.idom.impl.AbstractItem
-
- org.zkoss.idom.Attribute
-
- All Implemented Interfaces:
java.io.Serializable,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...
- Author:
- tomyeh
- See Also:
Element, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String_lnameThe local name.protected Namespace_nsThe namespace.protected Item_ownerThe owner item.protected java.lang.String_valueThe value.-
Fields inherited from interface org.zkoss.idom.Item
FIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVE
-
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAttribute()Constructor.Attribute(java.lang.String lname, java.lang.String value)Constructor.Attribute(java.lang.String nsURI, java.lang.String tname, java.lang.String value)Constructor.Attribute(Namespace ns, java.lang.String lname, java.lang.String value)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Clones this object (a deep cloning not including contents contained in Textual nodes).Itemdetach()Detach the attribute from its owner, if any.DocumentgetDocument()Gets the document that owns this attribute.java.lang.StringgetLocalName()Gets the local name of this item.java.lang.StringgetName()Gets the name of the item.NamespacegetNamespace()Gets the namespace.java.lang.StringgetNamespaceURI()shortgetNodeType()ItemgetOwner()Gets the item that owns this attribute.org.w3c.dom.DocumentgetOwnerDocument()org.w3c.dom.ElementgetOwnerElement()java.lang.StringgetPrefix()org.w3c.dom.TypeInfogetSchemaTypeInfo()booleangetSpecified()java.lang.StringgetTagName()Gets the tag name of this item.java.lang.StringgetText()java.lang.StringgetValue()Gets the value of this attribute.booleanisId()voidsetLocalName(java.lang.String lname)Sets the local name of this attribute.voidsetName(java.lang.String tname)Sets the name of the item.voidsetNamespace(java.lang.String prefix, java.lang.String nsURI)Sets the namespace.voidsetNamespace(Namespace ns)Sets the namespace.voidsetOwner(Item owner)Sets the item that owns this attribute.voidsetParent(Item parent)voidsetPrefix(java.lang.String prefix)Sets the namespace prefix of this attribute.voidsetTagName(java.lang.String tname)Sets the tag name.voidsetText(java.lang.String text)Sets the text of this item.voidsetValue(java.lang.String value)Sets the value of this attribute.java.lang.StringtoString()-
Methods inherited from class org.zkoss.idom.impl.AbstractItem
appendChild, cloneNode, compareDocumentPosition, equals, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocator, getNextSibling, getNodeName, getNodeValue, getParent, getParentNode, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, hashCode, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, match, normalize, removeChild, replaceChild, setLocator, setNodeValue, setParent, setTextContent, setUserData
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeValue, getParentNode, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setTextContent, setUserData
-
-
-
-
Constructor Detail
-
Attribute
public Attribute(java.lang.String nsURI, java.lang.String tname, java.lang.String value)Constructor.Note: According to W3/DOM, the namespace of attributes must have a prefix if the uri is not empty.
- Parameters:
nsURI- the namespace URItname- the tag name
-
Attribute
public Attribute(Namespace ns, java.lang.String lname, java.lang.String value)
Constructor.- Parameters:
ns- the namespacelname- the local name
-
Attribute
public Attribute(java.lang.String lname, java.lang.String value)Constructor.
-
Attribute
protected Attribute()
Constructor.
-
-
Method Detail
-
getValue
public final java.lang.String getValue()
Gets the value of this attribute.- Specified by:
getValuein interfaceorg.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:
setValuein interfaceorg.w3c.dom.Attr- Parameters:
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:
setNamespacein interfaceNamespaceable
-
getNamespace
public final Namespace getNamespace()
Description copied from interface:NamespaceableGets the namespace.- Specified by:
getNamespacein interfaceNamespaceable- Returns:
- the namespace; never null
-
getTagName
public final java.lang.String getTagName()
Description copied from interface:NamespaceableGets 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:
getTagNamein interfaceNamespaceable
-
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:
setTagNamein interfaceNamespaceable
-
getLocalName
public final java.lang.String getLocalName()
Description copied from interface:NamespaceableGets 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:
getLocalNamein interfaceNamespaceable- Specified by:
getLocalNamein interfaceorg.w3c.dom.Node- Overrides:
getLocalNamein classAbstractItem
-
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:
setLocalNamein interfaceNamespaceable
-
getName
public final java.lang.String getName()
Description copied from interface:ItemGets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as getTagName.- Specified by:
getNamein interfaceorg.w3c.dom.Attr- Specified by:
getNamein interfaceItem- See Also:
Namespaceable.getTagName()
-
setName
public final void setName(java.lang.String tname)
Description copied from interface:ItemSets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as setTagName.- Specified by:
setNamein interfaceItem- Overrides:
setNamein classAbstractItem- See Also:
Namespaceable.setTagName(java.lang.String)
-
getText
public final java.lang.String getText()
Description copied from interface:ItemGets the text of this item, or null if it is neitherTextualnorElement. 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:
getTextin interfaceItem- Overrides:
getTextin classAbstractItem
-
setText
public final void setText(java.lang.String text)
Description copied from interface:ItemSets the text of this item.- Specified by:
setTextin interfaceItem- Overrides:
setTextin classAbstractItem
-
getDocument
public final Document getDocument()
Gets the document that owns this attribute.- Specified by:
getDocumentin interfaceItem- Overrides:
getDocumentin classAbstractItem
-
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:
detachin interfaceItem- Overrides:
detachin classAbstractItem- Returns:
- this item
-
setParent
public void setParent(Item parent)
-
getNodeType
public final short getNodeType()
- Specified by:
getNodeTypein interfaceorg.w3c.dom.Node
-
getOwnerDocument
public final org.w3c.dom.Document getOwnerDocument()
- Specified by:
getOwnerDocumentin interfaceorg.w3c.dom.Node- Overrides:
getOwnerDocumentin classAbstractItem
-
getNamespaceURI
public final java.lang.String getNamespaceURI()
- Specified by:
getNamespaceURIin interfaceorg.w3c.dom.Node- Overrides:
getNamespaceURIin classAbstractItem
-
getPrefix
public final java.lang.String getPrefix()
- Specified by:
getPrefixin interfaceorg.w3c.dom.Node- Overrides:
getPrefixin classAbstractItem
-
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:
setPrefixin interfaceorg.w3c.dom.Node- Overrides:
setPrefixin classAbstractItem
-
getSchemaTypeInfo
public org.w3c.dom.TypeInfo getSchemaTypeInfo()
- Specified by:
getSchemaTypeInfoin interfaceorg.w3c.dom.Attr
-
isId
public boolean isId()
- Specified by:
isIdin interfaceorg.w3c.dom.Attr
-
getSpecified
public final boolean getSpecified()
- Specified by:
getSpecifiedin interfaceorg.w3c.dom.Attr
-
getOwnerElement
public final org.w3c.dom.Element getOwnerElement()
- Specified by:
getOwnerElementin interfaceorg.w3c.dom.Attr
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clone
public java.lang.Object clone()
Description copied from class:AbstractItemClones 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:
clonein interfaceItem- Overrides:
clonein classAbstractItem
-
-