Class Element
- Direct Known Subclasses:
HTMLElement
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA constant that can be used for the get descendants methods to denote infinite recursion -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedElement()Constructs and Element without specifying a name This can be used by subclasses that do not require name assigments.Constructs an Element with the specified nameConstructs an Element (or a text element) with the specified name or text. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified Element as a child to this element.booleanReturns true if the specified element is contained in this element's hierarchy (meaning it is one of its descendants)getAttribute(String name) Returns the attribute value by its name (or null if it wasn't defined for this element)intgetAttributeAsInt(String name, int def) Helper method to return the attribute as an integerReturns the attributes HashtablegetChildAt(int index) Returns the Element's child positioned at the specified indexintgetChildIndex(Element child) Returns the child indexprotected VectorReturns the internal children vectorgetChildrenByTagName(String name) Returns all children with the specified tag nameReturns all descendants with the specified tag namegetDescendantsByTagName(String name, int depth) Returns all descendants with the specified tag namegetDescendantsByTagNameAndAttribute(String name, String attributeName, int depth) Returns all descendants with the specified tag name and the none empty attributegetElementById(String id) Returns the element with the specified IDgetFirstChildByTagName(String name) Returns an Element's child by a tag nameintReturns the number of this Element's childrenReturns this Element's parentReturns this Element's tag namegetText()Returns the text of this element (for text elements only)getTextChildren(String text, boolean caseSensitive) Returns all children with the specified textgetTextDescendants(String text, boolean caseSensitive) Returns all text descendants containing the specified textgetTextDescendants(String text, boolean caseSensitive, int depth) Returns all text descendants containing the specified textbooleanDetermines whether or not this Element has any text children.voidinsertChildAt(Element child, int index) Inserts the given child at the specified indexbooleanisEmpty()Determines whether or not this Element has no children.booleanReturns true if this is a text element, false otherwiseiterator()Iterable for children of this entry making tree walking easier, this makes for(Element child : base) {} possibleprotected voidRemoves 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 retrievalvoidremoveAttribute(String attribute) Removes the specified attributevoidremoveChildAt(int index) Removes the child at the given indexvoidreplaceChild(Element oldChild, Element newChild) Replaces one child with anotherprotected voidsetAttribute(Object id, String value) Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value.intsetAttribute(String attribute, String value) Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value.protected voidsetChildren(Vector children) Sets the children vector of this Elementprotected voidSets this element parent, done interanlly in addChildprotected voidsetTagName(String name) Sets the name or text (for text elements) of this tagvoidSets the text of this element to the specified string (For text elements only)protected voidsetTextElement(boolean textElement) Sets this element as a text elementtoString()Returns a printable string representing this elementA recursive method for creating a printout of a full tag with its entire hierarchy.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
DEPTH_INFINITE
public static final int DEPTH_INFINITEA constant that can be used for the get descendants methods to denote infinite recursion- See Also:
-
-
Constructor Details
-
Element
protected Element()Constructs and Element without specifying a name This can be used by subclasses that do not require name assigments. -
Element
Constructs an Element with the specified name
Parameters
tagName: The tag name
-
Element
Constructs an Element (or a text element) with the specified name or text.
Parameters
-
tagName: The tag name, or in the case of a text element the element's text -
isTextElement: true for a text element, false otherwise
-
-
-
Method Details
-
isTextElement
public boolean isTextElement()Returns true if this is a text element, false otherwise
Returns
true if this is a text element, false otherwise
-
setTextElement
protected void setTextElement(boolean textElement) Sets this element as a text element
Parameters
textElement: true to set this as a text element, false otherwise
-
getTagName
Returns this Element's tag name
Returns
the Element's tag name
Throws
IllegalStateException: if this is a text element
-
setTagName
Sets the name or text (for text elements) of this tag
Parameters
name: The name or text of this tag
-
getAttributes
Returns the attributes Hashtable
Returns
the attributes Hashtable
-
setAttribute
Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value. This method allows creating a key that is non-string to be used by subclasses that optimize attributes retrieval
Parameters
-
id: The attribute ID -
value: The attribute value
-
-
addChild
Adds the specified Element as a child to this element. If the specified element was found to be unsupported (i.e. it's ID is TAG_UNSUPPORTED, it is not added.
Parameters
childElement: The child element
-
getParent
Returns this Element's parent
Returns
this Element's parent
-
setParent
Sets this element parent, done interanlly in addChild
Parameters
parent: The element's parent
-
getNumChildren
public int getNumChildren()Returns the number of this Element's children
Returns
the number of this Element's children
-
getChildren
Returns the internal children vector
Returns
the children vector
Deprecated
this uses the old vector API instead of the more modern Collection/List
-
setChildren
Sets the children vector of this Element
Parameters
children: The vector to set as this Element's children
Deprecated
this uses the old vector API instead of the more modern Collection/List
-
getChildAt
Returns the Element's child positioned at the specified index
Parameters
index: The requested index
Returns
child number index of this ELement
Throws
ArrayIndexOutOfBoundsException: if the index is bigger than the children's count or smaller than 0
-
getFirstChildByTagName
-
getElementById
-
getDescendantsByTagNameAndAttribute
Returns all descendants with the specified tag name and the none empty attribute
Parameters
-
name: The tag name to look for -
attributeName: the attribute that must exist on the tag -
depth: The search depth (1 - children, 2 - grandchildren .... DEPTH_INFINITE - for all descendants)
Returns
A vector containing descendants with the specified tag name
-
-
getDescendantsByTagName
Returns all descendants with the specified tag name
Parameters
-
name: The tag name to look for -
depth: The search depth (1 - children, 2 - grandchildren .... DEPTH_INFINITE - for all descendants)
Returns
A vector containing descendants with the specified tag name
-
-
getDescendantsByTagName
-
getChildrenByTagName
-
getTextDescendants
Returns all text descendants containing the specified text
Parameters
-
text: The text to look for (null to return all text children) -
caseSensitive: true to perform a case sensitive match, false to ignore case -
depth: The search depth (1 - children, 2 - grandchildren .... DEPTH_INFINITE - for all descendants)
Returns
A vector containing descendants containing the specified text
-
-
getTextDescendants
Returns all text descendants containing the specified text
Parameters
-
text: The text to look for (null to return all text children) -
caseSensitive: true to perform a case sensitive match, false to ignore case
Returns
A vector containing decensants containing the specified text
-
-
getTextChildren
Returns all children with the specified text
Parameters
-
text: The text to look for (null to return all text children) -
caseSensitive: true to perform a case sensitive match, false to ignore case
Returns
A vector containing children containing the specified text
-
-
contains
Returns true if the specified element is contained in this element's hierarchy (meaning it is one of its descendants)
Parameters
element: The element to look for
Returns
true if this element contains the specified element, false otherwise
-
setAttribute
Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value.
Parameters
-
attribute: The attribute's name -
value: The attribute's value
Returns
a positive error code or -1 if attribute is supported and valid
-
-
removeAttribute
Removes the specified attribute
Parameters
attribute: The attribute to remove
-
removeAttribute
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
Parameters
id: The attribute ID
-
getAttributeAsInt
Helper method to return the attribute as an integer
Parameters
-
name: the name of the attribute -
def: default value
Returns
return value
-
-
getAttribute
-
removeChildAt
public void removeChildAt(int index) Removes the child at the given index
Parameters
index: The child's index
-
getChildIndex
Returns the child index
Parameters
child: The child element to look for
Returns
The child position, or -1 if the child does not belong to this element.
-
insertChildAt
Inserts the given child at the specified index
Parameters
-
child: The child to insert -
index: The index to insert it at
-
-
replaceChild
-
getText
Returns the text of this element (for text elements only)
Returns
the text of this element (for text elements only)
Throws
IllegalStateException: if this is not a text element
-
setText
Sets the text of this element to the specified string (For text elements only)
Parameters
str: The text to set
Throws
IllegalStateException: if this is not a text element
-
toString
-
toString
-
hasTextChild
public boolean hasTextChild()Determines whether or not this Element has any text children.
Returns
true if any of this Elements children are text Elements.
-
isEmpty
public boolean isEmpty()Determines whether or not this Element has no children.
Returns
true if this Element has no children.
-
iterator
-