|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.idom.impl.AbstractItem org.zkoss.idom.impl.AbstractGroup org.zkoss.idom.Element
public class Element
The iDOM element.
Attribute
,
Serialized FormNested Class Summary | |
---|---|
protected class |
Element.AttrArray
|
protected class |
Element.AttrMap
|
Nested classes/interfaces inherited from class org.zkoss.idom.impl.AbstractGroup |
---|
AbstractGroup.ChildArray, AbstractGroup.ElementMap |
Field Summary | |
---|---|
protected java.util.Map<java.lang.String,Namespace> |
_addNamespaces
Additional namespaces. |
protected java.util.List<Attribute> |
_attrs
The attributes. |
protected java.lang.String |
_lname
The local name. |
protected Namespace |
_ns
The namespace. |
Fields inherited from class org.zkoss.idom.impl.AbstractGroup |
---|
_children |
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 |
Fields inherited from interface org.zkoss.idom.Item |
---|
FIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVE |
Constructor Summary | |
---|---|
protected |
Element()
Constructor. |
|
Element(Namespace ns,
java.lang.String lname)
Constructor. |
|
Element(java.lang.String lname)
Constructor without a namespace (i.e., Namespace.NO_NAMESPACE ). |
|
Element(java.lang.String nsURI,
java.lang.String tname)
Constructor. |
Method Summary | |
---|---|
boolean |
addDeclaredNamespace(Namespace ns)
Adds a namespace to the namespace declaration. |
java.lang.Object |
clone()
Clones this object (a deep cloning not including contents contained in Textual nodes). |
java.lang.String |
getAttribute(java.lang.String tname)
|
int |
getAttributeIndex(int indexFrom,
java.lang.String tname)
Gets the index of the attribute with the giving local name. |
int |
getAttributeIndex(int indexFrom,
java.lang.String namespace,
java.lang.String name,
int mode)
Gets the index of the first attribute that matches the specified criteria. |
Attribute |
getAttributeItem(java.lang.String tname)
Gets the attribute with the tag name. |
Attribute |
getAttributeItem(java.lang.String namespace,
java.lang.String name,
int mode)
Gets the first attribute that matches the specified criteria. |
java.util.List<Attribute> |
getAttributeItems()
Returns all attributes of this object. |
org.w3c.dom.Attr |
getAttributeNode(java.lang.String tname)
|
org.w3c.dom.Attr |
getAttributeNodeNS(java.lang.String nsURI,
java.lang.String lname)
|
java.lang.String |
getAttributeNS(java.lang.String nsURI,
java.lang.String lname)
|
org.w3c.dom.NamedNodeMap |
getAttributes()
|
java.util.List<Attribute> |
getAttributes(java.lang.String namespace,
java.lang.String name,
int mode)
Gets a list of attributes of the specified criteria. |
java.lang.String |
getAttributeValue(java.lang.String tname)
Returns the value of the attribute of the specified tag name, or null if not specified. |
java.lang.String |
getAttributeValue(java.lang.String namespace,
java.lang.String name,
int mode)
Gets the value of the first attribute that matches the giving criteria, or null if not found. |
java.lang.Object |
getContent()
Gets the content of this element. |
java.lang.Object |
getContent(java.lang.String path)
Returns the content of the child element with the giving path, or null if the content is null or the child element doesn't exist. |
java.util.Collection<Namespace> |
getDeclaredNamespaces()
Returns namespace declared on this element. |
org.w3c.dom.NodeList |
getElementsByTagName(java.lang.String tname)
|
org.w3c.dom.NodeList |
getElementsByTagNameNS(java.lang.String nsURI,
java.lang.String lname)
|
java.lang.String |
getLocalName()
Gets the local name of this item. |
java.lang.String |
getName()
Gets the tag name of the element -- the name with prefix. |
Namespace |
getNamespace()
Gets the namespace. |
Namespace |
getNamespace(java.lang.String prefix)
Returns the Namespace in scope on this element for the given prefix (this involves searching up the tree, so the results depend on the current location of the element), or null if not found. |
java.lang.String |
getNamespaceURI()
|
short |
getNodeType()
|
java.lang.String |
getNodeValue()
Always null. |
java.lang.String |
getPrefix()
|
org.w3c.dom.TypeInfo |
getSchemaTypeInfo()
|
java.lang.String |
getTagName()
Gets the tag name of this item. |
java.lang.String |
getText()
Returns the concatenation of Textual children; never null. |
java.lang.String |
getText(boolean trim)
Returns the concatenation of Textual children; never null. |
boolean |
hasAttribute(java.lang.String tname)
|
boolean |
hasAttributeNS(java.lang.String nsURI,
java.lang.String lname)
|
boolean |
hasAttributes()
|
boolean |
hasContent(java.lang.String path)
Tests whether the child element with the giving path exists. |
boolean |
isRootElement()
Tests whether this element is the root element of the owning document. |
protected java.util.List<Attribute> |
newAttrArray()
Creates an empty list of attributes. |
void |
removeAttribute(java.lang.String tname)
|
org.w3c.dom.Attr |
removeAttributeNode(org.w3c.dom.Attr oldAttr)
|
void |
removeAttributeNS(java.lang.String nsURI,
java.lang.String lname)
|
java.lang.Object |
removeContent(java.lang.String path)
Removes the content of the child element with the giving path, and the child element itself if no other child. |
Attribute |
setAttribute(Attribute attr)
Adds the giving attribute. |
void |
setAttribute(java.lang.String tname,
java.lang.String value)
|
org.w3c.dom.Attr |
setAttributeNode(org.w3c.dom.Attr newAttr)
|
org.w3c.dom.Attr |
setAttributeNodeNS(org.w3c.dom.Attr newAttr)
|
void |
setAttributeNS(java.lang.String nsURI,
java.lang.String tname,
java.lang.String value)
|
Attribute |
setAttributeValue(java.lang.String tname,
java.lang.String value)
Sets the value of the attribute with the giving tag name. |
java.lang.Object |
setContent(java.lang.Object obj)
Sets the content of this element. |
java.lang.Object |
setContent(java.lang.String path,
java.lang.Object obj)
Sets the content of the child element with the giving path. |
void |
setIdAttribute(java.lang.String name,
boolean isId)
|
void |
setIdAttributeNode(org.w3c.dom.Attr idAttr,
boolean isId)
|
void |
setIdAttributeNS(java.lang.String namespaceURI,
java.lang.String localName,
boolean isId)
|
void |
setLocalName(java.lang.String lname)
Sets the local name of this item. |
void |
setName(java.lang.String tname)
Sets the tag name of the element. |
void |
setNamespace(Namespace ns)
Sets the namespace. |
void |
setNamespace(java.lang.String prefix,
java.lang.String nsURI)
Sets the namespace. |
void |
setPrefix(java.lang.String prefix)
|
void |
setTagName(java.lang.String tname)
Sets the tag name of this item. |
java.lang.String |
toString()
|
Methods inherited from class org.zkoss.idom.impl.AbstractGroup |
---|
anyElement, appendChild, coalesce, detachChildren, getChildNodes, getChildren, getElement, getElement, getElementIndex, getElementIndex, getElementNames, getElements, getElements, getElements, getElementValue, getElementValue, getFirstChild, getLastChild, hasChildNodes, insertBefore, newChildren, removeChild, replaceChild |
Methods inherited from class org.zkoss.idom.impl.AbstractItem |
---|
cloneNode, compareDocumentPosition, detach, equals, getBaseURI, getDocument, getFeature, getLocator, getNextSibling, getNodeName, getOwnerDocument, getParent, getParentNode, getPreviousSibling, getTextContent, getUserData, hashCode, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, match, normalize, setLocator, setNodeValue, setParent, setText, 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, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNextSibling, getNodeName, getOwnerDocument, getParentNode, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setTextContent, setUserData |
Methods inherited from interface org.zkoss.idom.Item |
---|
detach, getDocument, getLocator, getParent, setLocator, setParent, setText |
Field Detail |
---|
protected Namespace _ns
protected java.lang.String _lname
protected java.util.List<Attribute> _attrs
protected java.util.Map<java.lang.String,Namespace> _addNamespaces
Constructor Detail |
---|
public Element(java.lang.String nsURI, java.lang.String tname)
nsURI
- the namespace URItname
- the tag namepublic Element(Namespace ns, java.lang.String lname)
ns
- the namespace; if null, the default namespace is assumed
(not necessary Namespace.NO_NAMESPACE
).lname
- the local namepublic Element(java.lang.String lname)
Namespace.NO_NAMESPACE
).
lname
- the local nameprotected Element()
Method Detail |
---|
public final boolean isRootElement()
Note: false is returned if it doesn't has any parent.
public final Namespace getNamespace(java.lang.String prefix)
If prefix is empty, it searches for the "default" namespace in scope. Thus, to search for attribute's namespace, caller have to skip this one and use NO_NAMESPACE. (due XML, an attribute without prefix is NO_NAMESPACE)
prefix
- namespace prefix to look up; null for emptypublic final java.util.Collection<Namespace> getDeclaredNamespaces()
It is not a "live" representation. Also, it is read-only.
Note: Namespace.equals compares namespace's URI. However, the distinction here is the prefix, because it is mainly for getNamespace(prefix).
public final boolean addDeclaredNamespace(Namespace ns)
DOMException
- if the name space with the same prefix
already exists but with different URIpublic final java.lang.Object getContent()
The content of an element is the first Binary or Text child of the element. Each element can has zero or one content.
Note: getText()
returns the concatenation of all Text
children, not just the first one.
getContent(String)
public final java.lang.Object setContent(java.lang.Object obj)
All existent Binary or Text children of this element are removed first. If the object is a String, a Text item is created to hold it. Otherwise, a Binary item is created to hold it.
Non-Binary/Text children are preserved.
If obj is a Item
or an array/collection of Item
,
this method will add them as child vertices rather than
being the content.
Moreover, if the first item of the array/collection is Item
,
it is assumed to be all valid component to being has valid vertices.
If not, an exception is thrown.
Thus, getContent might not return the object being set by setContent.
obj
- the object to set; null is OK
getContent()
public final java.lang.Object getContent(java.lang.String path)
Note that there might be more than one child with the same path in an iDOM tree; this method simply picks the first one that matches and returns its content. To access certain one, you might use [n] to [@attr = value] specify which one to access.
To know whether the child element exists or content is null,
use hasContent(java.lang.String)
.
The content of an element is a special feature of iDOM.
Like a Map, it is designed to let developers use names (in a path-like
format) to access objects. See setContent(String, Object)
.
Like Unix path, the giving name could use '/' to concatenate a series of child elements.
An empty path denotes this element itself. Leading, ending and consecutive '/' will be ignored.
Example:
Object o = element.getContent("abc/def");
String s = Objects.toString(element.getContent("ab/cd"));
element.setContent("t:ab/cd/f:ef", new Integer(10));
TODO: support [n] and [@attr = value]
path
- a path; e.g., "b", "a/b", "t:a/t:b"getContent()
public final boolean hasContent(java.lang.String path)
getContent(String)
.
public final java.lang.Object setContent(java.lang.String path, java.lang.Object obj)
Note that there might be more than one child with the same path
in an iDOM tree; this method simply pick one that matches and set
its content (see setContent(Object)
).
The content of an element is a special feature of iDOM.
Like a Map, it is designed to let developers use names (in a path-like
format) to access objects. See getContent(String)
.
Like Unix path, the giving name could use '/' to concatenate a series of child elements.
An empty path denotes this element itself. Leading, ending and consecutive '/' will be ignored.
If any element in the path is not found, it will be created automatically.
path
- a path; e.g., "b", "a/b", "t:a/t:b"obj
- the object to set; null is acceptable
setContent(Object)
,
removeContent(java.lang.String)
,
hasContent(java.lang.String)
public final java.lang.Object removeContent(java.lang.String path)
Unlike setContent(String, Object)
with null,
the child element identified by path will be detached if it has no
other child (but the content). So does its parent
excluding this element. Thus, removeContent(path)
could undo setContent(path, v).
setContent(String, Object)
public final void setNamespace(Namespace ns)
Namespace.NO_NAMESPACE
.
According W3C/DOM, unlike element, an attribute doesn't allow a namespace that has an URI but without a prefix.
setNamespace
in interface Namespaceable
public final void setNamespace(java.lang.String prefix, java.lang.String nsURI)
public final Namespace getNamespace()
Namespaceable
getNamespace
in interface Namespaceable
public final java.lang.String getTagName()
Namespaceable
To get the local name (the name without prefix), Namespaceable.getLocalName could be used.
getTagName
in interface org.w3c.dom.Element
getTagName
in interface Namespaceable
public final void setTagName(java.lang.String tname)
Namespaceable
setTagName
in interface Namespaceable
public final java.lang.String getLocalName()
Namespaceable
To get the tag name (the name with prefix), Namespaceable.getTagName could be used.
getLocalName
in interface org.w3c.dom.Node
getLocalName
in interface Namespaceable
getLocalName
in class AbstractItem
public final void setLocalName(java.lang.String lname)
Namespaceable
setLocalName
in interface Namespaceable
public final java.lang.String getName()
getName
in interface Item
Namespaceable.getTagName()
public final void setName(java.lang.String tname)
setName
in interface Item
setName
in class AbstractItem
Namespaceable.setTagName(java.lang.String)
public final java.lang.String getText()
Textual
children; never null.
Note: both <tag/> and <tag></tag> returns an
empty string. To tell the difference, check the number of children.
getText
in interface Item
getText
in class AbstractItem
getText(boolean)
public final java.lang.String getText(boolean trim)
Textual
children; never null.
trim
- whether to trim before returninggetText()
public final java.util.List<Attribute> getAttributeItems()
Attributable
The returned list is "live". Any modification to it affects the object that owns the attributes.
If the new added attribute has the same tag name as that of any existent attribute, DOMException is thrown. Thus, it is, sometimes, more convenient to ue setAttribute.
Naming reason: we don't call it getAttributes() to avoid the name conflict with Node.getAttributes().
getAttributeItems
in interface Attributable
protected java.util.List<Attribute> newAttrArray()
public final int getAttributeIndex(int indexFrom, java.lang.String namespace, java.lang.String name, int mode)
Attributable
getAttributeIndex
in interface Attributable
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
public final int getAttributeIndex(int indexFrom, java.lang.String tname)
Attributable
getAttributeIndex
in interface Attributable
indexFrom
- the index to start searching from; 0 for beginningtname
- the tag name (i.e., Attribute.getName()
) --
consists of the prefix and the local name
public final Attribute getAttributeItem(java.lang.String namespace, java.lang.String name, int mode)
Attributable
The name is a bit strange because we have to avoid name conflicts with org.w3c.dom.Node.
getAttributeItem
in interface Attributable
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 Item.FIND_xxx
public final Attribute getAttributeItem(java.lang.String tname)
Attributable
The name is a bit strange because we have to avoid name conflicts with org.w3c.dom.Node.
getAttributeItem
in interface Attributable
tname
- the tag name (i.e., Attribute.getName()
) --
consists of the prefix and the local name
public final java.util.List<Attribute> getAttributes(java.lang.String namespace, java.lang.String name, int mode)
Attributable
getAttributes
in interface Attributable
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 Item.FIND_xxx
public final Attribute setAttribute(Attribute attr)
Attributable
setAttribute
in interface Attributable
attr
- the new attribute to add
public final java.lang.String getAttributeValue(java.lang.String namespace, java.lang.String name, int mode)
Attributable
According to Section 3.3.3 of XML 1.0 spec, the value is normalized, including trimmed.
getAttributeValue
in interface Attributable
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
public final java.lang.String getAttributeValue(java.lang.String tname)
Attributable
Note: unlike W3C's getAttribute, which returns empty if not specified, this method returns null if not specified.
getAttributeValue
in interface Attributable
public final Attribute setAttributeValue(java.lang.String tname, java.lang.String value)
Attributable
Note: it looks similar to Attribute(String, String), but this method requires the tag name.
setAttributeValue
in interface Attributable
tname
- the tag name (i.e., Attribute.getName)value
- the new value.
public java.lang.Object clone()
AbstractItem
clone
in interface Item
clone
in class AbstractGroup
public final short getNodeType()
getNodeType
in interface org.w3c.dom.Node
public final java.lang.String getNodeValue()
getNodeValue
in interface org.w3c.dom.Node
getNodeValue
in class AbstractItem
public final org.w3c.dom.NamedNodeMap getAttributes()
getAttributes
in interface org.w3c.dom.Node
getAttributes
in class AbstractItem
public final boolean hasAttributes()
hasAttributes
in interface org.w3c.dom.Node
hasAttributes
in class AbstractItem
public final java.lang.String getNamespaceURI()
getNamespaceURI
in interface org.w3c.dom.Node
getNamespaceURI
in class AbstractItem
public final java.lang.String getPrefix()
getPrefix
in interface org.w3c.dom.Node
getPrefix
in class AbstractItem
public final void setPrefix(java.lang.String prefix)
setPrefix
in interface org.w3c.dom.Node
setPrefix
in class AbstractItem
public final org.w3c.dom.NodeList getElementsByTagName(java.lang.String tname)
getElementsByTagName
in interface org.w3c.dom.Element
public final org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String nsURI, java.lang.String lname)
getElementsByTagNameNS
in interface org.w3c.dom.Element
public final org.w3c.dom.Attr getAttributeNode(java.lang.String tname)
getAttributeNode
in interface org.w3c.dom.Element
public final org.w3c.dom.Attr getAttributeNodeNS(java.lang.String nsURI, java.lang.String lname)
getAttributeNodeNS
in interface org.w3c.dom.Element
public final java.lang.String getAttribute(java.lang.String tname)
getAttribute
in interface org.w3c.dom.Element
public final java.lang.String getAttributeNS(java.lang.String nsURI, java.lang.String lname)
getAttributeNS
in interface org.w3c.dom.Element
public final void setAttribute(java.lang.String tname, java.lang.String value)
setAttribute
in interface org.w3c.dom.Element
public final void setAttributeNS(java.lang.String nsURI, java.lang.String tname, java.lang.String value)
setAttributeNS
in interface org.w3c.dom.Element
public final org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr newAttr)
setAttributeNode
in interface org.w3c.dom.Element
public final org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr)
setAttributeNodeNS
in interface org.w3c.dom.Element
public final void removeAttribute(java.lang.String tname)
removeAttribute
in interface org.w3c.dom.Element
public final void removeAttributeNS(java.lang.String nsURI, java.lang.String lname)
removeAttributeNS
in interface org.w3c.dom.Element
public final org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr oldAttr)
removeAttributeNode
in interface org.w3c.dom.Element
public final boolean hasAttribute(java.lang.String tname)
hasAttribute
in interface org.w3c.dom.Element
public final boolean hasAttributeNS(java.lang.String nsURI, java.lang.String lname)
hasAttributeNS
in interface org.w3c.dom.Element
public final java.lang.String toString()
toString
in class java.lang.Object
public org.w3c.dom.TypeInfo getSchemaTypeInfo()
getSchemaTypeInfo
in interface org.w3c.dom.Element
public void setIdAttribute(java.lang.String name, boolean isId) throws DOMException
setIdAttribute
in interface org.w3c.dom.Element
DOMException
public void setIdAttributeNS(java.lang.String namespaceURI, java.lang.String localName, boolean isId) throws DOMException
setIdAttributeNS
in interface org.w3c.dom.Element
DOMException
public void setIdAttributeNode(org.w3c.dom.Attr idAttr, boolean isId) throws DOMException
setIdAttributeNode
in interface org.w3c.dom.Element
DOMException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |