Class AbstractGroup
- All Implemented Interfaces:
Serializable,Cloneable,Node,Group,Item
- Direct Known Subclasses:
Document,Element,EntityReference
The default implementation of newChildren is for the semantic of Element. A deriving class has to re-implement it, if it is not applicable. Example, Document.
- Author:
- tomyeh
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe array to hold children.protected static classStores a 'cached' map of child elements to speed up the access. -
Field Summary
FieldsFields inherited from interface org.zkoss.idom.Item
FIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVEFields 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 -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal NodeappendChild(Node newChild) clone()Clones this object (a deep cloning not including contents contained in Textual nodes).final intcoalesce(boolean recursive) Coalesces children if they are siblings with the same type instances of Textual, Textual.isCoalesceable returns true.Detaches all children and returns them in a list.final NodeListGets all children.final ElementgetElement(String tname) Gets the first Element-type child with the tag name.final ElementgetElement(String namespace, String name, int mode) Gets the first Element-type child that matches the giving criteria.final intgetElementIndex(int indexFrom, String tname) Gets the index of the first Element-type child with the specified name.final intgetElementIndex(int indexFrom, String namespace, String name, int mode) Gets the index of the Element-type first child that match the specified criteria.Returns a readonly set of names of element children.Returns a cloned copy of all element childrengetElements(String tname) Gets a readonly list of children with the tag name.getElements(String namespace, String name, int mode) Gets a readonly list of Element-type children that match the giving criteria.final StringgetElementValue(String tname, boolean trim) Gets the text of the first Element-type child with the tag name, with a trimming option.final StringgetElementValue(String namespace, String name, int mode, boolean trim) Gets the value of the first Element-type child that matches the giving criteria, with a trimming option.final Nodefinal Nodefinal booleanfinal NodeinsertBefore(Node newChild, Node refChild) Creates a list to hold child vertices.final NoderemoveChild(Node oldChild) final NodereplaceChild(Node newChild, Node oldChild) Methods inherited from class org.zkoss.idom.impl.AbstractItem
cloneNode, compareDocumentPosition, detach, equals, getAttributes, getBaseURI, getDocument, getFeature, getLocalName, getLocator, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParent, getParentNode, getPrefix, getPreviousSibling, getText, getTextContent, getUserData, hasAttributes, hashCode, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, match, normalize, setLocator, setName, setNodeValue, setParent, setPrefix, setText, setTextContent, setUserDataMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.zkoss.idom.Item
detach, getDocument, getLocator, getName, getParent, getText, setLocator, setName, setParent, setTextMethods inherited from interface org.w3c.dom.Node
getNodeType
-
Field Details
-
_children
The list of the children. Never null.
-
-
Constructor Details
-
AbstractGroup
protected AbstractGroup()Constructor.
-
-
Method Details
-
newChildren
Creates a list to hold child vertices. Note: the list must be able to protect itself from adding unexpected child -- read-only, wrong type, undetached...The default implementation obeys the semantic of Element, i.e., it doesn't allow any child that cannot be a child of Element.
For performance issue, we introduced a map to improve the search speed for Element node associated with a tag name.
-
getChildren
Description copied from interface:GroupGets all children.The returned list is "live". Any modification to it affects the node. On the other hand,
Group.getElements(String)returns a copy.Unlike JDOM, it won't coalesce adjacent children automatically since it might violate the caller's expectation about List. Rather, we provide coalesce to let caller do the merging explicitly. Note: when building a iDOM tree from a source (SAXBuilder.build), coalesce() will be invoked automatically.
Note: not all items supports children. If this item doesn't, it returns an empty list. And, if any invocation tries to add vertices to the returned list will cause UnsupportOperationException.
- Specified by:
getChildrenin interfaceGroup
-
detachChildren
Description copied from interface:GroupDetaches all children and returns them in a list.Note: you cannot add children to anther Group by doing
group.addAll(e.getChildren()), because you have to detach them first. Then, you could use this method:
group.addAll(e.detachChildren());- Specified by:
detachChildrenin interfaceGroup
-
anyElement
public final boolean anyElement() -
getElementNames
Description copied from interface:GroupReturns a readonly set of names of element children. Then, you could useGroup.getElements(java.lang.String, java.lang.String, int)to get elements.The returned list is a 'live-facade' of the real ones, so the performance is good, and any modification to
Group.getChildren()will affect it.- Specified by:
getElementNamesin interfaceGroup- See Also:
-
getElements
Description copied from interface:GroupReturns a cloned copy of all element childrenUnlike
Group.getChildren()andGroup.getElementNames(), the returned list is NOT a 'live-facade' of the real ones.- Specified by:
getElementsin interfaceGroup- See Also:
-
getElementIndex
Description copied from interface:GroupGets the index of the Element-type first child that match the specified criteria.Note: only Element-type children are returned, since others have no name.
- Specified by:
getElementIndexin interfaceGroup- Parameters:
indexFrom- the index to start searching from; 0 for beginningnamespace- the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignorename- the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignoremode- the search mode; zero or any combination of Item.FIND_xxx, except FIND_RECURSIVE- Returns:
- the index if found; -1 if not found
-
getElementIndex
Description copied from interface:GroupGets the index of the first Element-type child with the specified name.Note: only Element-type children are returned, since others have no name.
getChildren().add(getElementIndex(0, "pre:name"), new Element("pre:another"));- Specified by:
getElementIndexin interfaceGroup- Parameters:
indexFrom- the index to start searching from; 0 for beginningtname- the tag name (i.e., Namespaceable.getName)- Returns:
- the index if found; -1 if not found
-
getElement
Description copied from interface:GroupGets the first Element-type child that matches the giving criteria.Note: only Element-type children are returned. Depending on the mode, the searching is usually linear -- take O(n) to complete.
- Specified by:
getElementin interfaceGroup- Parameters:
namespace- the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignorename- the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignoremode- the search mode; zero or any combination of FIND_xxx.- Returns:
- the found element; null if not found or not supported
-
getElement
Description copied from interface:GroupGets the first Element-type child with the tag name. It is the same as childOf(nsURI, lname, null, 0).Note: only Element-type children are returned. Also, we did some optimization for this method so its access time is nearly constant.
- Specified by:
getElementin interfaceGroup- Parameters:
tname- the tag name (i.e., Namespaceable.getName)- Returns:
- the found element; null if not found or not supported
-
getElements
Description copied from interface:GroupGets a readonly list of Element-type children that match the giving criteria.Unlike
Element.getElementsByTagName(java.lang.String), this method only returns child elements, excluding grand children and other descendants.The returned list is a 'live-facade' of the real ones, so the performance is good, and any modification to
Group.getChildren()will affect it.Note: only Element-type children are returned. Depending on the mode, the searching is usually linear -- take O(n) to complete.
- Specified by:
getElementsin interfaceGroup- Parameters:
namespace- the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignorename- the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignoremode- the search mode; zero or any combination of FIND_xxx.- Returns:
- a read-only list containing all matched children; an empty list if not found or not supported
-
getElements
Description copied from interface:GroupGets a readonly list of children with the tag name.Unlike
Element.getElementsByTagName(java.lang.String), this method only returns child elements, excluding grand children and other descendants.The returned list is a 'live-facade' of the real ones, so the performance is good, and any modification to
Group.getChildren()will affect it.Note: only Element-type children are returned. Also, we did some optimization for this method so its access time is nearly constant.
- Specified by:
getElementsin interfaceGroup- Parameters:
tname- the tag name (i.e., Namespaceable.getName)
-
getElementValue
Description copied from interface:GroupGets the value of the first Element-type child that matches the giving criteria, with a trimming option.- Specified by:
getElementValuein interfaceGroup- Parameters:
namespace- the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignorename- the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignore- Returns:
- the value of the first Element-type child ; null if not found
-
getElementValue
Description copied from interface:GroupGets the text of the first Element-type child with the tag name, with a trimming option.- Specified by:
getElementValuein interfaceGroup- Parameters:
tname- the tag name (i.e., Namespaceable.getName)- Returns:
- the text of the first Element-type child with the tag name; null if not found
-
coalesce
public final int coalesce(boolean recursive) Description copied from interface:GroupCoalesces children if they are siblings with the same type instances of Textual, Textual.isCoalesceable returns true.SAXBuilder.build will do the merging automatically.
-
getChildNodes
- Specified by:
getChildNodesin interfaceNode- Overrides:
getChildNodesin classAbstractItem
-
getFirstChild
- Specified by:
getFirstChildin interfaceNode- Overrides:
getFirstChildin classAbstractItem
-
getLastChild
- Specified by:
getLastChildin interfaceNode- Overrides:
getLastChildin classAbstractItem
-
hasChildNodes
public final boolean hasChildNodes()- Specified by:
hasChildNodesin interfaceNode- Overrides:
hasChildNodesin classAbstractItem
-
insertBefore
- Specified by:
insertBeforein interfaceNode- Overrides:
insertBeforein classAbstractItem
-
replaceChild
- Specified by:
replaceChildin interfaceNode- Overrides:
replaceChildin classAbstractItem
-
removeChild
- Specified by:
removeChildin interfaceNode- Overrides:
removeChildin classAbstractItem
-
appendChild
- Specified by:
appendChildin interfaceNode- Overrides:
appendChildin classAbstractItem
-
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
-