Class AbstractItem
- java.lang.Object
-
- org.zkoss.idom.impl.AbstractItem
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,org.w3c.dom.Node
,Item
- Direct Known Subclasses:
AbstractGroup
,AbstractTextual
,Attribute
,DocType
,ProcessingInstruction
public abstract class AbstractItem extends java.lang.Object implements Item, org.w3c.dom.Node, java.io.Serializable, java.lang.Cloneable
A semi-implemented item for leaf vertices. A leaf item is a item without any children. For cores having child cores, use Group.Important methods that the deriving might want to override.
- Item.getName
- It must be overridden to provide a local name.
- Item.setName
- Override it if it allows to change the name. Default: throws an exception.
- Item.getText
- Override it if it has a text representation. Default: returns null.
- Item.setText
- Override it if it allows to change the text. Default: throws an exception.
- Node.getNodeType
- It must be overridden to provide the type.
- Item.clone
- Override it if any other members to handle specially. Note: by definition, we do deep clone only.
- Object.toString
- Override if you want a representation other than XMLOutputter does.
- Author:
- tomyeh
- See Also:
Item
, Serialized Form
-
-
Field Summary
-
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 protected
AbstractItem()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.w3c.dom.Node
appendChild(org.w3c.dom.Node newChild)
java.lang.Object
clone()
Clones this object (a deep cloning not including contents contained in Textual nodes).org.w3c.dom.Node
cloneNode(boolean deep)
short
compareDocumentPosition(org.w3c.dom.Node other)
Item
detach()
Detach this item from its parent.boolean
equals(java.lang.Object o)
Overriding this method is prohibited.org.w3c.dom.NamedNodeMap
getAttributes()
java.lang.String
getBaseURI()
org.w3c.dom.NodeList
getChildNodes()
Document
getDocument()
Gets the document that owns this item.java.lang.Object
getFeature(java.lang.String feature, java.lang.String version)
org.w3c.dom.Node
getFirstChild()
org.w3c.dom.Node
getLastChild()
java.lang.String
getLocalName()
Locator
getLocator()
Gets the locator of this item.java.lang.String
getNamespaceURI()
org.w3c.dom.Node
getNextSibling()
java.lang.String
getNodeName()
java.lang.String
getNodeValue()
org.w3c.dom.Document
getOwnerDocument()
Group
getParent()
Gets the parent item.org.w3c.dom.Node
getParentNode()
java.lang.String
getPrefix()
org.w3c.dom.Node
getPreviousSibling()
java.lang.String
getText()
java.lang.String
getTextContent()
java.lang.Object
getUserData(java.lang.String key)
boolean
hasAttributes()
boolean
hasChildNodes()
int
hashCode()
Overriding this method is prohibited.org.w3c.dom.Node
insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
boolean
isDefaultNamespace(java.lang.String namespaceURI)
boolean
isEqualNode(org.w3c.dom.Node arg)
boolean
isSameNode(org.w3c.dom.Node other)
boolean
isSupported(java.lang.String feature, java.lang.String version)
java.lang.String
lookupNamespaceURI(java.lang.String prefix)
java.lang.String
lookupPrefix(java.lang.String namespaceURI)
protected static boolean
match(Namespaceable vtx, java.lang.String namespace, java.lang.String name, java.util.regex.Pattern ptn, int mode)
Tests whether a namespaceable item matches the criteria.void
normalize()
org.w3c.dom.Node
removeChild(org.w3c.dom.Node oldChild)
org.w3c.dom.Node
replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
void
setLocator(Locator loc)
Sets the locator of this item.void
setName(java.lang.String name)
Sets the name of the item.void
setNodeValue(java.lang.String nodeValue)
void
setParent(Group parent)
Sets the parent item.void
setPrefix(java.lang.String prefix)
void
setText(java.lang.String text)
Sets the text of this item.void
setTextContent(java.lang.String textContent)
java.lang.Object
setUserData(java.lang.String key, java.lang.Object data, org.w3c.dom.UserDataHandler handler)
-
-
-
Method Detail
-
match
protected static boolean match(Namespaceable vtx, java.lang.String namespace, java.lang.String name, java.util.regex.Pattern ptn, int mode)
Tests whether a namespaceable item matches the criteria. If mode don't contain FIND_BY_REGEX, ptn is ignored.
-
setName
public void setName(java.lang.String name)
Description copied from interface:Item
Sets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as setTagName.- Specified by:
setName
in interfaceItem
- See Also:
Namespaceable.setTagName(java.lang.String)
-
getText
public java.lang.String getText()
Description copied from interface:Item
Gets the text of this item, or null if it is neitherTextual
norElement
. 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.
-
setText
public void setText(java.lang.String text)
Description copied from interface:Item
Sets the text of this item.
-
getDocument
public Document getDocument()
Description copied from interface:Item
Gets the document that owns this item. The owning document is the first document in its ancestor. For DOM, the document can only be the root, so the owning documents of vertices in a DOM tree are all the same.- Specified by:
getDocument
in interfaceItem
-
detach
public Item detach()
Description copied from interface:Item
Detach this item from its parent.Because each item can belong to at most one parent at a time, it is important to detach it first, before added to another tree -- even if it is the same tree/parent.
It has the similar effect as:
getParent().getChildren().remove(this).Naming reason: we don't call this method as getChildren() to be compatible with the naming style of Attributable.attributes -- which is limited to org.w3c.dom.Attr.getAttributes. Also, it doesn't have the setter and it is "live", so it 'seem' better to call it getChildren().
-
getParent
public final Group getParent()
Description copied from interface:Item
Gets the parent item.
-
setParent
public void setParent(Group parent)
Description copied from interface:Item
Sets the parent item.DO NOT call this method. It is used internally. Instead, use detach or thru getChildren().
-
getLocator
public final Locator getLocator()
Description copied from interface:Item
Gets the locator of this item.- Specified by:
getLocator
in interfaceItem
- Returns:
- the locator; null if not available (default)
-
setLocator
public final void setLocator(Locator loc)
Description copied from interface:Item
Sets the locator of this item.Unlike other methods, it won't change the modification flag.
- Specified by:
setLocator
in interfaceItem
- Parameters:
loc
- the locator; null if not available
-
getNodeName
public java.lang.String getNodeName()
- Specified by:
getNodeName
in interfaceorg.w3c.dom.Node
-
getNodeValue
public java.lang.String getNodeValue()
- Specified by:
getNodeValue
in interfaceorg.w3c.dom.Node
-
setNodeValue
public void setNodeValue(java.lang.String nodeValue)
- Specified by:
setNodeValue
in interfaceorg.w3c.dom.Node
-
getOwnerDocument
public org.w3c.dom.Document getOwnerDocument()
- Specified by:
getOwnerDocument
in interfaceorg.w3c.dom.Node
-
cloneNode
public final org.w3c.dom.Node cloneNode(boolean deep)
- Specified by:
cloneNode
in interfaceorg.w3c.dom.Node
-
getParentNode
public final org.w3c.dom.Node getParentNode()
- Specified by:
getParentNode
in interfaceorg.w3c.dom.Node
-
getPreviousSibling
public final org.w3c.dom.Node getPreviousSibling()
- Specified by:
getPreviousSibling
in interfaceorg.w3c.dom.Node
-
getNextSibling
public final org.w3c.dom.Node getNextSibling()
- Specified by:
getNextSibling
in interfaceorg.w3c.dom.Node
-
getChildNodes
public org.w3c.dom.NodeList getChildNodes()
- Specified by:
getChildNodes
in interfaceorg.w3c.dom.Node
-
getFirstChild
public org.w3c.dom.Node getFirstChild()
- Specified by:
getFirstChild
in interfaceorg.w3c.dom.Node
-
getLastChild
public org.w3c.dom.Node getLastChild()
- Specified by:
getLastChild
in interfaceorg.w3c.dom.Node
-
hasChildNodes
public boolean hasChildNodes()
- Specified by:
hasChildNodes
in interfaceorg.w3c.dom.Node
-
insertBefore
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
- Specified by:
insertBefore
in interfaceorg.w3c.dom.Node
-
replaceChild
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
- Specified by:
replaceChild
in interfaceorg.w3c.dom.Node
-
removeChild
public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
- Specified by:
removeChild
in interfaceorg.w3c.dom.Node
-
appendChild
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
- Specified by:
appendChild
in interfaceorg.w3c.dom.Node
-
normalize
public final void normalize()
- Specified by:
normalize
in interfaceorg.w3c.dom.Node
-
isSupported
public final boolean isSupported(java.lang.String feature, java.lang.String version)
- Specified by:
isSupported
in interfaceorg.w3c.dom.Node
-
getNamespaceURI
public java.lang.String getNamespaceURI()
- Specified by:
getNamespaceURI
in interfaceorg.w3c.dom.Node
-
getPrefix
public java.lang.String getPrefix()
- Specified by:
getPrefix
in interfaceorg.w3c.dom.Node
-
getLocalName
public java.lang.String getLocalName()
- Specified by:
getLocalName
in interfaceorg.w3c.dom.Node
-
setPrefix
public void setPrefix(java.lang.String prefix)
- Specified by:
setPrefix
in interfaceorg.w3c.dom.Node
-
getAttributes
public org.w3c.dom.NamedNodeMap getAttributes()
- Specified by:
getAttributes
in interfaceorg.w3c.dom.Node
-
hasAttributes
public boolean hasAttributes()
- Specified by:
hasAttributes
in interfaceorg.w3c.dom.Node
-
getBaseURI
public java.lang.String getBaseURI()
- Specified by:
getBaseURI
in interfaceorg.w3c.dom.Node
-
compareDocumentPosition
public short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException
- Specified by:
compareDocumentPosition
in interfaceorg.w3c.dom.Node
- Throws:
DOMException
-
getTextContent
public java.lang.String getTextContent() throws DOMException
- Specified by:
getTextContent
in interfaceorg.w3c.dom.Node
- Throws:
DOMException
-
setTextContent
public void setTextContent(java.lang.String textContent) throws DOMException
- Specified by:
setTextContent
in interfaceorg.w3c.dom.Node
- Throws:
DOMException
-
isSameNode
public boolean isSameNode(org.w3c.dom.Node other)
- Specified by:
isSameNode
in interfaceorg.w3c.dom.Node
-
lookupPrefix
public java.lang.String lookupPrefix(java.lang.String namespaceURI)
- Specified by:
lookupPrefix
in interfaceorg.w3c.dom.Node
-
isDefaultNamespace
public boolean isDefaultNamespace(java.lang.String namespaceURI)
- Specified by:
isDefaultNamespace
in interfaceorg.w3c.dom.Node
-
lookupNamespaceURI
public java.lang.String lookupNamespaceURI(java.lang.String prefix)
- Specified by:
lookupNamespaceURI
in interfaceorg.w3c.dom.Node
-
isEqualNode
public boolean isEqualNode(org.w3c.dom.Node arg)
- Specified by:
isEqualNode
in interfaceorg.w3c.dom.Node
-
getFeature
public java.lang.Object getFeature(java.lang.String feature, java.lang.String version)
- Specified by:
getFeature
in interfaceorg.w3c.dom.Node
-
setUserData
public java.lang.Object setUserData(java.lang.String key, java.lang.Object data, org.w3c.dom.UserDataHandler handler)
- Specified by:
setUserData
in interfaceorg.w3c.dom.Node
-
getUserData
public java.lang.Object getUserData(java.lang.String key)
- Specified by:
getUserData
in interfaceorg.w3c.dom.Node
-
equals
public final boolean equals(java.lang.Object o)
Overriding this method is prohibited.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
Overriding this method is prohibited.- Overrides:
hashCode
in classjava.lang.Object
-
clone
public java.lang.Object clone()
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).
-
-