|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.lwuit.xml.Element
public class Element
The Element class defines a single XML element with its attributes and children. Due to its hierarchial nature, this class can be used for a single "leaf" Element, for more complex elements (with child elements), and up to describing the entire document.
Field Summary | |
---|---|
static int |
DEPTH_INFINITE
A constant that can be used for the get descendants methods to denote infinite recursion |
Constructor Summary | |
---|---|
protected |
Element()
Constructs and Element without specifying a name This can be used by subclasses that do not require name assigments. |
|
Element(java.lang.String tagName)
Constructs an Element with the specified name |
|
Element(java.lang.String tagName,
boolean isTextElement)
Constructs an Element (or a text element) with the specified name or text. |
Method Summary | |
---|---|
void |
addChild(Element childElement)
Adds the specified Element as a child to this element. |
boolean |
contains(Element element)
Returns true if the specified element is contained in this element's hierarchy (meaning it is one of its descendants) |
java.lang.String |
getAttribute(java.lang.String name)
Returns the attribute value by its name (or null if it wasn't defined for this element) |
protected java.util.Hashtable |
getAttributes()
Returns the attributes Hashtable |
Element |
getChildAt(int index)
Returns the Element's child positioned at the specified index |
int |
getChildIndex(Element child)
Returns the child index |
protected java.util.Vector |
getChildren()
Returns the internal children vector |
java.util.Vector |
getChildrenByTagName(java.lang.String name)
Returns all children with the specified tag name |
java.util.Vector |
getDescendantsByTagName(java.lang.String name)
Returns all descendants with the specified tag name |
java.util.Vector |
getDescendantsByTagName(java.lang.String name,
int depth)
Returns all descendants with the specified tag name |
Element |
getElementById(java.lang.String id)
Returns the element with the specified ID |
Element |
getFirstChildByTagName(java.lang.String name)
Returns an Element's child by a tag name |
int |
getNumChildren()
Returns the number of this Element's children |
Element |
getParent()
Returns this Element's parent |
java.lang.String |
getTagName()
Returns this Element's tag name |
java.lang.String |
getText()
Returns the text of this element (for text elements only) |
java.util.Vector |
getTextChildren(java.lang.String text,
boolean caseSensitive)
Returns all children with the specified text |
java.util.Vector |
getTextDescendants(java.lang.String text,
boolean caseSensitive)
Returns all text descendants containing the specified text |
java.util.Vector |
getTextDescendants(java.lang.String text,
boolean caseSensitive,
int depth)
Returns all text descendants containing the specified text |
void |
insertChildAt(Element child,
int index)
Inserts the given child at the specified index |
boolean |
isTextElement()
Returns true if this is a text element, false otherwise |
protected void |
removeAttribute(java.lang.Object id)
Removes the specified attribute if it exist in this Element This method allows creating a key that is non-string to be used by subclasses that optimize attributes retrieval |
void |
removeAttribute(java.lang.String attribute)
Removes the specified attribute |
void |
removeChildAt(int index)
Removes the child at the given index |
void |
replaceChild(Element oldChild,
Element newChild)
Replaces one child with another |
protected void |
setAttribute(java.lang.Object id,
java.lang.String value)
Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value. |
int |
setAttribute(java.lang.String attribute,
java.lang.String value)
Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value. |
protected void |
setChildren(java.util.Vector children)
Sets the children vector of this Element |
protected void |
setParent(Element parent)
Sets this element parent, done interanlly in addChild |
protected void |
setTagName(java.lang.String name)
Sets the name or text (for text elements) of this tag |
void |
setText(java.lang.String str)
Sets the text of this element to the specified string (For text elements only) |
protected void |
setTextElement(boolean textElement)
Sets this element as a text element |
java.lang.String |
toString()
Returns a printable string representing this element |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEPTH_INFINITE
Constructor Detail |
---|
protected Element()
public Element(java.lang.String tagName)
tagName
- The tag namepublic Element(java.lang.String tagName, boolean isTextElement)
tagName
- The tag name, or in the case of a text element the element's textisTextElement
- true for a text element, false otherwiseMethod Detail |
---|
public boolean isTextElement()
public java.lang.String getTagName()
java.lang.IllegalStateException
- if this is a text elementprotected java.util.Hashtable getAttributes()
protected void setAttribute(java.lang.Object id, java.lang.String value)
id
- The attribute IDvalue
- The attribute valuepublic void addChild(Element childElement)
childElement
- The child elementprotected void setParent(Element parent)
parent
- The element's parentpublic Element getParent()
public int getNumChildren()
protected java.util.Vector getChildren()
protected void setChildren(java.util.Vector children)
children
- The vector to set as this Element's childrenprotected void setTagName(java.lang.String name)
name
- The name or text of this tagprotected void setTextElement(boolean textElement)
textElement
- true to set this as a text element, false otherwisepublic Element getChildAt(int index)
index
- The requested index
java.lang.ArrayIndexOutOfBoundsException
- if the index is bigger than the children's count or smaller than 0public Element getFirstChildByTagName(java.lang.String name)
name
- The child's tag name
public Element getElementById(java.lang.String id)
id
- The id to find
public java.util.Vector getDescendantsByTagName(java.lang.String name, int depth)
name
- The tag name to look fordepth
- The search depth (1 - children, 2 - grandchildren .... DEPTH_INFINITE - for all descendants)
public java.util.Vector getDescendantsByTagName(java.lang.String name)
name
- The tag name to look for
public java.util.Vector getChildrenByTagName(java.lang.String name)
name
- The tag name to look for
public java.util.Vector getTextDescendants(java.lang.String text, boolean caseSensitive, int depth)
text
- The text to look for (null to return all text children)caseSensitive
- true to perform a case sensitive match, false to ignore casedepth
- The search depth (1 - children, 2 - grandchildren .... DEPTH_INFINITE - for all descendants)
public java.util.Vector getTextDescendants(java.lang.String text, boolean caseSensitive)
text
- The text to look for (null to return all text children)caseSensitive
- true to perform a case sensitive match, false to ignore case
public java.util.Vector getTextChildren(java.lang.String text, boolean caseSensitive)
text
- The text to look for (null to return all text children)caseSensitive
- true to perform a case sensitive match, false to ignore case
public boolean contains(Element element)
element
- The element to look for
public int setAttribute(java.lang.String attribute, java.lang.String value)
attribute
- The attribute's namevalue
- The attribute's value
public void removeAttribute(java.lang.String attribute)
attribute
- The attribute to removeprotected void removeAttribute(java.lang.Object id)
id
- The attribute IDpublic java.lang.String getAttribute(java.lang.String name)
name
- The attribute id
public void removeChildAt(int index)
index
- The child's indexpublic int getChildIndex(Element child)
child
- The child element to look for
public void insertChildAt(Element child, int index)
child
- The child to insertindex
- The index to insert it atpublic void replaceChild(Element oldChild, Element newChild)
oldChild
- The child to replace (Must belong to this element, otherwise a call to this method will have no effect)newChild
- The child to replace it withpublic java.lang.String getText()
java.lang.IllegalStateException
- if this is not a text elementpublic void setText(java.lang.String str)
str
- The text to set
java.lang.IllegalStateException
- if this is not a text elementpublic java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |