websphinx
Class Element

java.lang.Object
  |
  +--websphinx.Region
        |
        +--websphinx.Element
Direct Known Subclasses:
Link

public class Element
extends Region

Element in an HTML page. An element runs from a start tag (like <ul>) to its matching end tag (</ul>), inclusive. An element may have an optional end tag (like <p>), in which case the element runs up to (but not including) the tag that implicitly closes it. For example:

<p>Paragraph 1<p>Paragraph 2
contains two elements,
<p>Paragraph 1
and
<p>Paragraph 2
.


Field Summary
protected  websphinx.Element child
           
protected  websphinx.Tag endTag
           
protected  websphinx.Element parent
           
protected  websphinx.Element sibling
           
protected  websphinx.Tag startTag
           
 
Fields inherited from class websphinx.Region
end, names, source, start, TRUE
 
Constructor Summary
Element(websphinx.Tag startTag, int end)
          Make an Element from a start tag and an end position.
Element(websphinx.Tag startTag, websphinx.Tag endTag)
          Make an Element from a start tag and end tag.
 
Method Summary
 java.util.Enumeration enumerateHTMLAttributes()
          Enumerate the HTML attributes found on this tag.
 websphinx.Element getChild()
          Get element's first child.
 websphinx.Tag getEndTag()
          Get end tag.
 java.lang.String getHTMLAttribute(java.lang.String name)
          Get an HTML attribute's value.
 java.lang.String getHTMLAttribute(java.lang.String name, java.lang.String defaultValue)
          Get an HTML attribute's value, with a default value if it doesn't exist.
 websphinx.Element getNext()
          Return next element in an inorder walk of the tree, assuming this element and its children have been visited.
 websphinx.Element getParent()
          Get element's parent.
 websphinx.Element getSibling()
          Get element's next sibling.
 websphinx.Tag getStartTag()
          Get start tag.
 java.lang.String getTagName()
          Get tag name.
 boolean hasHTMLAttribute(java.lang.String name)
          Test if tag has an HTML attribute.
 
Methods inherited from class websphinx.Region
enumerateObjectLabels, findEnd, findStart, getEnd, getField, getFields, getLabel, getLabel, getLength, getNumericLabel, getObjectLabel, getObjectLabels, getRootElement, getSource, getStart, hasAllLabels, hasAllLabels, hasAnyLabels, hasAnyLabels, hasLabel, removeLabel, setField, setFields, setLabel, setLabel, setObjectLabel, span, toHTML, toString, toTags, toText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

startTag

protected websphinx.Tag startTag

endTag

protected websphinx.Tag endTag

sibling

protected websphinx.Element sibling

parent

protected websphinx.Element parent

child

protected websphinx.Element child
Constructor Detail

Element

public Element(websphinx.Tag startTag,
               websphinx.Tag endTag)
Make an Element from a start tag and end tag. The tags must be on the same Page.

Parameters:
startTag - Start tag of element
endTag - End tag of element (may be null)

Element

public Element(websphinx.Tag startTag,
               int end)
Make an Element from a start tag and an end position. Used when the end tag has been omitted (like <p>, frequently).

Parameters:
startTag - Start tag of element
end - Ending offset of element
Method Detail

getTagName

public java.lang.String getTagName()
Get tag name.

Returns:
tag name (like "p"), in lower-case, String.intern()'ed form. Thus you can compare tag names with ==, as in: getTagName() == Tag.IMG.

getStartTag

public websphinx.Tag getStartTag()
Get start tag.

Returns:
start tag of element

getEndTag

public websphinx.Tag getEndTag()
Get end tag.

Returns:
end tag of element, or null if element has no end tag.

getParent

public websphinx.Element getParent()
Get element's parent.

Returns:
element that contains this element, or null if at top-level.

getSibling

public websphinx.Element getSibling()
Get element's next sibling.

Returns:
element that follows this element, or null if at end of parent's children.

getChild

public websphinx.Element getChild()
Get element's first child.

Returns:
first element contained by this element, or null if no children.

getNext

public websphinx.Element getNext()
Return next element in an inorder walk of the tree, assuming this element and its children have been visited.

Returns:
next element

hasHTMLAttribute

public boolean hasHTMLAttribute(java.lang.String name)
Test if tag has an HTML attribute.

Parameters:
name - Name of HTML attribute (e.g. "HREF"). Doesn't have to be converted with toHTMLAttributeName().
Returns:
true if tag has the attribute, false if not

getHTMLAttribute

public java.lang.String getHTMLAttribute(java.lang.String name)
Get an HTML attribute's value.

Parameters:
name - Name of HTML attribute (e.g. "HREF"). Doesn't have to be converted with toHTMLAttributeName().
Returns:
value of attribute if it exists, TRUE if the attribute exists but has no value, or null if tag lacks the attribute.

getHTMLAttribute

public java.lang.String getHTMLAttribute(java.lang.String name,
                                         java.lang.String defaultValue)
Get an HTML attribute's value, with a default value if it doesn't exist.

Parameters:
name - Name of HTML attribute (e.g. "HREF"). Doesn't have to be converted with toHTMLAttributeName().
defaultValue - default value to return if the attribute doesn't exist
Returns:
value of attribute if it exists, TRUE if the attribute exists but has no value, or defaultValue if tag lacks the attribute.

enumerateHTMLAttributes

public java.util.Enumeration enumerateHTMLAttributes()
Enumerate the HTML attributes found on this tag.

Returns:
enumeration of the attribute names found on this tag.