|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.zkoss.idom.impl.AbstractItem
org.zkoss.idom.impl.AbstractGroup
org.zkoss.idom.Element
public class Element
The iDOM element.
Attribute,
Serialized Form| Nested 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 Map |
_addNamespaces
Additional namespaces. |
protected List |
_attrs
The attributes. |
protected 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.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,
String lname)
Constructor. |
|
Element(String lname)
Constructor without a namespace (i.e., Namespace.NO_NAMESPACE). |
|
Element(String nsURI,
String tname)
Constructor. |
| Method Summary | |
|---|---|
boolean |
addDeclaredNamespace(Namespace ns)
Adds a namespace to the namespace declaration. |
Object |
clone()
Clones this object (a deep cloning not including contents contained in Textual nodes). |
String |
getAttribute(String tname)
|
int |
getAttributeIndex(int indexFrom,
String tname)
Gets the index of the attribute with the giving local name. |
int |
getAttributeIndex(int indexFrom,
String namespace,
String name,
int mode)
Gets the index of the first attribute that matches the specified criteria. |
Attribute |
getAttributeItem(String tname)
Gets the attribute with the tag name. |
Attribute |
getAttributeItem(String namespace,
String name,
int mode)
Gets the first attribute that matches the specified criteria. |
List |
getAttributeItems()
Returns all attributes of this object. |
Attr |
getAttributeNode(String tname)
|
Attr |
getAttributeNodeNS(String nsURI,
String lname)
|
String |
getAttributeNS(String nsURI,
String lname)
|
NamedNodeMap |
getAttributes()
|
List |
getAttributes(String namespace,
String name,
int mode)
Gets a list of attributes of the specified criteria. |
String |
getAttributeValue(String tname)
Returns the value of the attribute of the specified tag name, or null if not specified. |
String |
getAttributeValue(String namespace,
String name,
int mode)
Gets the value of the first attribute that matches the giving criteria, or null if not found. |
Object |
getContent()
Gets the content of this element. |
Object |
getContent(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. |
Collection |
getDeclaredNamespaces()
Returns namespace declared on this element. |
NodeList |
getElementsByTagName(String tname)
|
NodeList |
getElementsByTagNameNS(String nsURI,
String lname)
|
String |
getLocalName()
Gets the local name of this item. |
String |
getName()
Gets the tag name of the element -- the name with prefix. |
Namespace |
getNamespace()
Gets the namespace. |
Namespace |
getNamespace(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. |
String |
getNamespaceURI()
|
short |
getNodeType()
|
String |
getNodeValue()
Always null. |
String |
getPrefix()
|
TypeInfo |
getSchemaTypeInfo()
|
String |
getTagName()
Gets the tag name of this item. |
String |
getText()
Returns the concatenation of Textual children; never null. |
String |
getText(boolean trim)
Returns the concatenation of Textual children; never null. |
boolean |
hasAttribute(String tname)
|
boolean |
hasAttributeNS(String nsURI,
String lname)
|
boolean |
hasAttributes()
|
boolean |
hasContent(String path)
Tests whether the child element with the giving path exists. |
boolean |
isAttributeModificationAware()
Deprecated. As of release 5.0.8, it always returns false. |
boolean |
isRootElement()
Tests whether this element is the root element of the owning document. |
protected List |
newAttrArray()
Creates an empty list of attributes. |
void |
removeAttribute(String tname)
|
Attr |
removeAttributeNode(Attr oldAttr)
|
void |
removeAttributeNS(String nsURI,
String lname)
|
Object |
removeContent(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(String tname,
String value)
|
void |
setAttributeModificationAware(boolean aware)
Deprecated. As of release 5.0.8, it always returns false. |
Attr |
setAttributeNode(Attr newAttr)
|
Attr |
setAttributeNodeNS(Attr newAttr)
|
void |
setAttributeNS(String nsURI,
String tname,
String value)
|
Attribute |
setAttributeValue(String tname,
String value)
Sets the value of the attribute with the giving tag name. |
Object |
setContent(Object obj)
Sets the content of this element. |
Object |
setContent(String path,
Object obj)
Sets the content of the child element with the giving path. |
void |
setIdAttribute(String name,
boolean isId)
|
void |
setIdAttributeNode(Attr idAttr,
boolean isId)
|
void |
setIdAttributeNS(String namespaceURI,
String localName,
boolean isId)
|
void |
setLocalName(String lname)
Sets the local name of this item. |
void |
setName(String tname)
Sets the tag name of the element. |
void |
setNamespace(Namespace ns)
Sets the namespace. |
void |
setNamespace(String prefix,
String nsURI)
Sets the namespace. |
void |
setPrefix(String prefix)
|
void |
setTagName(String tname)
Sets the tag name of this item. |
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 |
|---|
clearModified, clone, cloneNode, compareDocumentPosition, detach, equals, getBaseURI, getDocument, getFeature, getLocator, getNextSibling, getNodeName, getOwnerDocument, getParent, getParentNode, getPreviousSibling, getTextContent, getUserData, hashCode, isDefaultNamespace, isEqualNode, isModified, isReadonly, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, match, normalize, setLocator, setModified, setNodeValue, setParent, setReadonly, 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 |
|---|
clearModified, clone, detach, getDocument, getLocator, getParent, isModified, isReadonly, setLocator, setModified, setParent, setReadonly, setText |
| Field Detail |
|---|
protected Namespace _ns
protected String _lname
protected List _attrs
protected Map _addNamespaces
| Constructor Detail |
|---|
public Element(String nsURI,
String tname)
nsURI - the namespace URItname - the tag name
public Element(Namespace ns,
String lname)
ns - the namespace; if null, the default namespace is assumed
(not necessary Namespace.NO_NAMESPACE).lname - the local namepublic Element(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(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 Collection 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 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 Object setContent(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 Object getContent(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(String path)
getContent(String).
public final Object setContent(String path,
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 Object removeContent(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(String prefix,
String nsURI)
public final Namespace getNamespace()
Namespaceable
getNamespace in interface Namespaceablepublic final String getTagName()
NamespaceableTo get the local name (the name without prefix), Namespaceable.getLocalName could be used.
getTagName in interface ElementgetTagName in interface Namespaceablepublic final void setTagName(String tname)
Namespaceable
setTagName in interface Namespaceablepublic final String getLocalName()
NamespaceableTo get the tag name (the name with prefix), Namespaceable.getTagName could be used.
getLocalName in interface NodegetLocalName in interface NamespaceablegetLocalName in class AbstractItempublic final void setLocalName(String lname)
Namespaceable
setLocalName in interface Namespaceablepublic final String getName()
getName in interface ItemNamespaceable.getTagName()public final void setName(String tname)
setName in interface ItemsetName in class AbstractItemNamespaceable.setTagName(java.lang.String)public final 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 ItemgetText in class AbstractItemgetText(boolean)public final String getText(boolean trim)
Textual children; never null.
trim - whether to trim before returninggetText()public final boolean isAttributeModificationAware()
isAttributeModificationAware in interface Attributablepublic final void setAttributeModificationAware(boolean aware)
setAttributeModificationAware in interface Attributablepublic final List getAttributeItems()
AttributableThe 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 Attributableprotected List newAttrArray()
public final int getAttributeIndex(int indexFrom,
String namespace,
String name,
int mode)
Attributable
getAttributeIndex in interface AttributableindexFrom - the index to start searching from; 0 for beginningnamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the serach mode; zero or any combination of Item.FIND_xxx
public final int getAttributeIndex(int indexFrom,
String tname)
Attributable
getAttributeIndex in interface AttributableindexFrom - 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(String namespace,
String name,
int mode)
AttributableThe name is a bit strange because we have to avoid name conflicts with org.w3c.dom.Node.
getAttributeItem in interface Attributablenamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the serach mode; zero or any combination of Item.FIND_xxx
public final Attribute getAttributeItem(String tname)
AttributableThe name is a bit strange because we have to avoid name conflicts with org.w3c.dom.Node.
getAttributeItem in interface Attributabletname - the tag name (i.e., Attribute.getName()) --
consists of the prefix and the local name
public final List getAttributes(String namespace,
String name,
int mode)
Attributable
getAttributes in interface Attributablenamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the serach mode; zero or any combination of Item.FIND_xxx
public final Attribute setAttribute(Attribute attr)
Attributable
setAttribute in interface Attributableattr - the new attribute to add
public final String getAttributeValue(String namespace,
String name,
int mode)
AttributableAccording to Section 3.3.3 of XML 1.0 spec, the value is normalized, including trimmed.
getAttributeValue in interface Attributablenamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignore
public final String getAttributeValue(String tname)
AttributableNote: 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(String tname,
String value)
AttributableNote: it looks similar to Attribute(String, String), but this method requires the tag name.
setAttributeValue in interface Attributabletname - the tag name (i.e., Attribute.getName)value - the new value.
public Object clone()
AbstractItem
clone in interface Itemclone in class AbstractGrouppublic final short getNodeType()
getNodeType in interface Nodepublic final String getNodeValue()
getNodeValue in interface NodegetNodeValue in class AbstractItempublic final NamedNodeMap getAttributes()
getAttributes in interface NodegetAttributes in class AbstractItempublic final boolean hasAttributes()
hasAttributes in interface NodehasAttributes in class AbstractItempublic final String getNamespaceURI()
getNamespaceURI in interface NodegetNamespaceURI in class AbstractItempublic final String getPrefix()
getPrefix in interface NodegetPrefix in class AbstractItempublic final void setPrefix(String prefix)
setPrefix in interface NodesetPrefix in class AbstractItempublic final NodeList getElementsByTagName(String tname)
getElementsByTagName in interface Element
public final NodeList getElementsByTagNameNS(String nsURI,
String lname)
getElementsByTagNameNS in interface Elementpublic final Attr getAttributeNode(String tname)
getAttributeNode in interface Element
public final Attr getAttributeNodeNS(String nsURI,
String lname)
getAttributeNodeNS in interface Elementpublic final String getAttribute(String tname)
getAttribute in interface Element
public final String getAttributeNS(String nsURI,
String lname)
getAttributeNS in interface Element
public final void setAttribute(String tname,
String value)
setAttribute in interface Element
public final void setAttributeNS(String nsURI,
String tname,
String value)
setAttributeNS in interface Elementpublic final Attr setAttributeNode(Attr newAttr)
setAttributeNode in interface Elementpublic final Attr setAttributeNodeNS(Attr newAttr)
setAttributeNodeNS in interface Elementpublic final void removeAttribute(String tname)
removeAttribute in interface Element
public final void removeAttributeNS(String nsURI,
String lname)
removeAttributeNS in interface Elementpublic final Attr removeAttributeNode(Attr oldAttr)
removeAttributeNode in interface Elementpublic final boolean hasAttribute(String tname)
hasAttribute in interface Element
public final boolean hasAttributeNS(String nsURI,
String lname)
hasAttributeNS in interface Elementpublic final String toString()
toString in class Objectpublic TypeInfo getSchemaTypeInfo()
getSchemaTypeInfo in interface Element
public void setIdAttribute(String name,
boolean isId)
throws DOMException
setIdAttribute in interface ElementDOMException
public void setIdAttributeNS(String namespaceURI,
String localName,
boolean isId)
throws DOMException
setIdAttributeNS in interface ElementDOMException
public void setIdAttributeNode(Attr idAttr,
boolean isId)
throws DOMException
setIdAttributeNode in interface ElementDOMException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||