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 protectedAbstractItem()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.w3c.dom.NodeappendChild(org.w3c.dom.Node newChild)java.lang.Objectclone()Clones this object (a deep cloning not including contents contained in Textual nodes).org.w3c.dom.NodecloneNode(boolean deep)shortcompareDocumentPosition(org.w3c.dom.Node other)Itemdetach()Detach this item from its parent.booleanequals(java.lang.Object o)Overriding this method is prohibited.org.w3c.dom.NamedNodeMapgetAttributes()java.lang.StringgetBaseURI()org.w3c.dom.NodeListgetChildNodes()DocumentgetDocument()Gets the document that owns this item.java.lang.ObjectgetFeature(java.lang.String feature, java.lang.String version)org.w3c.dom.NodegetFirstChild()org.w3c.dom.NodegetLastChild()java.lang.StringgetLocalName()LocatorgetLocator()Gets the locator of this item.java.lang.StringgetNamespaceURI()org.w3c.dom.NodegetNextSibling()java.lang.StringgetNodeName()java.lang.StringgetNodeValue()org.w3c.dom.DocumentgetOwnerDocument()GroupgetParent()Gets the parent item.org.w3c.dom.NodegetParentNode()java.lang.StringgetPrefix()org.w3c.dom.NodegetPreviousSibling()java.lang.StringgetText()java.lang.StringgetTextContent()java.lang.ObjectgetUserData(java.lang.String key)booleanhasAttributes()booleanhasChildNodes()inthashCode()Overriding this method is prohibited.org.w3c.dom.NodeinsertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)booleanisDefaultNamespace(java.lang.String namespaceURI)booleanisEqualNode(org.w3c.dom.Node arg)booleanisSameNode(org.w3c.dom.Node other)booleanisSupported(java.lang.String feature, java.lang.String version)java.lang.StringlookupNamespaceURI(java.lang.String prefix)java.lang.StringlookupPrefix(java.lang.String namespaceURI)protected static booleanmatch(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.voidnormalize()org.w3c.dom.NoderemoveChild(org.w3c.dom.Node oldChild)org.w3c.dom.NodereplaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)voidsetLocator(Locator loc)Sets the locator of this item.voidsetName(java.lang.String name)Sets the name of the item.voidsetNodeValue(java.lang.String nodeValue)voidsetParent(Group parent)Sets the parent item.voidsetPrefix(java.lang.String prefix)voidsetText(java.lang.String text)Sets the text of this item.voidsetTextContent(java.lang.String textContent)java.lang.ObjectsetUserData(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:ItemSets the name of the item. For vertices that support namespace (implements Namespaceable), it is the same as setTagName.- Specified by:
setNamein interfaceItem- See Also:
Namespaceable.setTagName(java.lang.String)
-
getText
public 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.
-
setText
public void setText(java.lang.String text)
Description copied from interface:ItemSets the text of this item.
-
getDocument
public Document getDocument()
Description copied from interface:ItemGets 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:
getDocumentin interfaceItem
-
detach
public Item detach()
Description copied from interface:ItemDetach 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:ItemGets the parent item.
-
setParent
public void setParent(Group parent)
Description copied from interface:ItemSets 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:ItemGets the locator of this item.- Specified by:
getLocatorin interfaceItem- Returns:
- the locator; null if not available (default)
-
setLocator
public final void setLocator(Locator loc)
Description copied from interface:ItemSets the locator of this item.Unlike other methods, it won't change the modification flag.
- Specified by:
setLocatorin interfaceItem- Parameters:
loc- the locator; null if not available
-
getNodeName
public java.lang.String getNodeName()
- Specified by:
getNodeNamein interfaceorg.w3c.dom.Node
-
getNodeValue
public java.lang.String getNodeValue()
- Specified by:
getNodeValuein interfaceorg.w3c.dom.Node
-
setNodeValue
public void setNodeValue(java.lang.String nodeValue)
- Specified by:
setNodeValuein interfaceorg.w3c.dom.Node
-
getOwnerDocument
public org.w3c.dom.Document getOwnerDocument()
- Specified by:
getOwnerDocumentin interfaceorg.w3c.dom.Node
-
cloneNode
public final org.w3c.dom.Node cloneNode(boolean deep)
- Specified by:
cloneNodein interfaceorg.w3c.dom.Node
-
getParentNode
public final org.w3c.dom.Node getParentNode()
- Specified by:
getParentNodein interfaceorg.w3c.dom.Node
-
getPreviousSibling
public final org.w3c.dom.Node getPreviousSibling()
- Specified by:
getPreviousSiblingin interfaceorg.w3c.dom.Node
-
getNextSibling
public final org.w3c.dom.Node getNextSibling()
- Specified by:
getNextSiblingin interfaceorg.w3c.dom.Node
-
getChildNodes
public org.w3c.dom.NodeList getChildNodes()
- Specified by:
getChildNodesin interfaceorg.w3c.dom.Node
-
getFirstChild
public org.w3c.dom.Node getFirstChild()
- Specified by:
getFirstChildin interfaceorg.w3c.dom.Node
-
getLastChild
public org.w3c.dom.Node getLastChild()
- Specified by:
getLastChildin interfaceorg.w3c.dom.Node
-
hasChildNodes
public boolean hasChildNodes()
- Specified by:
hasChildNodesin interfaceorg.w3c.dom.Node
-
insertBefore
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)- Specified by:
insertBeforein interfaceorg.w3c.dom.Node
-
replaceChild
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)- Specified by:
replaceChildin interfaceorg.w3c.dom.Node
-
removeChild
public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
- Specified by:
removeChildin interfaceorg.w3c.dom.Node
-
appendChild
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
- Specified by:
appendChildin interfaceorg.w3c.dom.Node
-
normalize
public final void normalize()
- Specified by:
normalizein interfaceorg.w3c.dom.Node
-
isSupported
public final boolean isSupported(java.lang.String feature, java.lang.String version)- Specified by:
isSupportedin interfaceorg.w3c.dom.Node
-
getNamespaceURI
public java.lang.String getNamespaceURI()
- Specified by:
getNamespaceURIin interfaceorg.w3c.dom.Node
-
getPrefix
public java.lang.String getPrefix()
- Specified by:
getPrefixin interfaceorg.w3c.dom.Node
-
getLocalName
public java.lang.String getLocalName()
- Specified by:
getLocalNamein interfaceorg.w3c.dom.Node
-
setPrefix
public void setPrefix(java.lang.String prefix)
- Specified by:
setPrefixin interfaceorg.w3c.dom.Node
-
getAttributes
public org.w3c.dom.NamedNodeMap getAttributes()
- Specified by:
getAttributesin interfaceorg.w3c.dom.Node
-
hasAttributes
public boolean hasAttributes()
- Specified by:
hasAttributesin interfaceorg.w3c.dom.Node
-
getBaseURI
public java.lang.String getBaseURI()
- Specified by:
getBaseURIin interfaceorg.w3c.dom.Node
-
compareDocumentPosition
public short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException- Specified by:
compareDocumentPositionin interfaceorg.w3c.dom.Node- Throws:
DOMException
-
getTextContent
public java.lang.String getTextContent() throws DOMException- Specified by:
getTextContentin interfaceorg.w3c.dom.Node- Throws:
DOMException
-
setTextContent
public void setTextContent(java.lang.String textContent) throws DOMException- Specified by:
setTextContentin interfaceorg.w3c.dom.Node- Throws:
DOMException
-
isSameNode
public boolean isSameNode(org.w3c.dom.Node other)
- Specified by:
isSameNodein interfaceorg.w3c.dom.Node
-
lookupPrefix
public java.lang.String lookupPrefix(java.lang.String namespaceURI)
- Specified by:
lookupPrefixin interfaceorg.w3c.dom.Node
-
isDefaultNamespace
public boolean isDefaultNamespace(java.lang.String namespaceURI)
- Specified by:
isDefaultNamespacein interfaceorg.w3c.dom.Node
-
lookupNamespaceURI
public java.lang.String lookupNamespaceURI(java.lang.String prefix)
- Specified by:
lookupNamespaceURIin interfaceorg.w3c.dom.Node
-
isEqualNode
public boolean isEqualNode(org.w3c.dom.Node arg)
- Specified by:
isEqualNodein interfaceorg.w3c.dom.Node
-
getFeature
public java.lang.Object getFeature(java.lang.String feature, java.lang.String version)- Specified by:
getFeaturein 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:
setUserDatain interfaceorg.w3c.dom.Node
-
getUserData
public java.lang.Object getUserData(java.lang.String key)
- Specified by:
getUserDatain interfaceorg.w3c.dom.Node
-
equals
public final boolean equals(java.lang.Object o)
Overriding this method is prohibited.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
Overriding this method is prohibited.- Overrides:
hashCodein 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).
-
-