SimpleServlets v5.5.0

com.simpleservlets.htmlobjects
Interface HTMLElement

All Known Implementing Classes:
GenericHTMLElement, HTMLBody, HTMLBold, HTMLBreak, HTMLCode, HTMLEmphasis, HTMLEntity, HTMLFont, HTMLForm, HTMLForm.Input, HTMLForm.Option, HTMLForm.Select, HTMLHead, HTMLHeader, HTMLHorizontalRule, HTMLImage, HTMLItalic, HTMLLink, HTMLList, HTMLList.Item, HTMLMeta, HTMLPage, HTMLParagraph, HTMLPre, HTMLSimpleForm, HTMLSmall, HTMLSpan, HTMLString, HTMLStrong, HTMLStylesheetRef, HTMLSubscript, HTMLSuperscript, HTMLTable, HTMLTable.Cell, HTMLTable.Row, HTMLTitle, HTMLUnderline, NoTagHTMLElement

public interface HTMLElement

Core unit for HTMLObjects. HTMLElement's are added to other HTMLElement's. Attributes can be added to HTMLElement's.

Author:
Paul Hyde
See Also:
GenericHTMLElement, HTMLAttribute

Field Summary
static HTMLElement[] ZERO_LEN_ARRAY
           
 
Method Summary
 HTMLElement add(HTMLElement element)
          Add the specified child element to this container.
 HTMLString add(String text)
          Convenience method to wrap the specified text in an HTMLString and call add(HTMLElement).
 HTMLElement addSibling(HTMLElement element)
          Add the specified element to this element's parent.
 HTMLString addSibling(String text)
          Convenience method to wrap the specified text in an HTMLString and call addSibling(HTMLElement).
 HTMLAttribute[] getAttributes()
          Returns an array of all of the attributes.
 HTMLElement[] getChildren()
          Returns an array of all of the children of this element.
 String getName()
          Returns the tag name for this element.
 HTMLElement getParent()
          Returns the current parent element of this element (may be null).
 boolean hasAttributes()
          Returns true if this element has any attributes set.
 boolean hasChildren()
          Returns true if there are currently any children nested within this element.
 boolean isSafeToWrapWithWhitespace()
          Returns true if is is safe to add whitespace before and after this element.
 void removeAllAttributes()
          Removes all of the attributes.
 void removeAllChildren()
          Removes all of the children.
 boolean removeAttribute(String name)
          Attempts to remove the attribute with the specified name.
 boolean removeChild(int index)
          Attempts to remove the child HTMLElement at the specified index.
 void setAttribute(HTMLAttribute attribute)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttribute(String name)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttribute(String name, double value)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttribute(String name, int value)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttribute(String name, Object value)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttribute(String name, String value)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttribute(String name, Value value)
          Sets the specified attribute potentially replacing anything that was previously stored for the same name.
 void setAttributeGroup(HTMLAttribute[] attributeGroup)
          Sets ALL the specified attributes potentially replacing anything that was previously stored for the same name(s).
 void setParent(HTMLElement parent)
          Changes or initially sets the parent element for this element.
 void setStyle(String styleName)
          Used to add the attribute class with the specified value.
 

Field Detail

ZERO_LEN_ARRAY

static final HTMLElement[] ZERO_LEN_ARRAY
Method Detail

getName

String getName()
Returns the tag name for this element.


hasAttributes

boolean hasAttributes()
Returns true if this element has any attributes set.


getAttributes

HTMLAttribute[] getAttributes()
Returns an array of all of the attributes. If there are no attributes, a zero-length array is returned.


setAttribute

void setAttribute(HTMLAttribute attribute)
Sets the specified attribute potentially replacing anything that was previously stored for the same name.


setAttribute

void setAttribute(String name,
                  String value)
                  throws IllegalArgumentException
Sets the specified attribute potentially replacing anything that was previously stored for the same name. The value is parsed for entities (see HTMLAttribute.HTMLAttribute(String, String)).

Throws:
IllegalArgumentException

setAttribute

void setAttribute(String name,
                  Value value)
                  throws IllegalArgumentException
Sets the specified attribute potentially replacing anything that was previously stored for the same name. The value is parsed for entities (see HTMLAttribute.HTMLAttribute(String, Value)).

Throws:
IllegalArgumentException

setAttribute

void setAttribute(String name,
                  Object value)
                  throws IllegalArgumentException
Sets the specified attribute potentially replacing anything that was previously stored for the same name. The value is parsed for entities (see HTMLAttribute.HTMLAttribute(String, Object)).

Throws:
IllegalArgumentException

setAttribute

void setAttribute(String name,
                  int value)
                  throws IllegalArgumentException
Sets the specified attribute potentially replacing anything that was previously stored for the same name. (see HTMLAttribute.HTMLAttribute(String, int)).

Throws:
IllegalArgumentException

setAttribute

void setAttribute(String name,
                  double value)
                  throws IllegalArgumentException
Sets the specified attribute potentially replacing anything that was previously stored for the same name. (see HTMLAttribute.HTMLAttribute(String, double)).

Throws:
IllegalArgumentException

setAttribute

void setAttribute(String name)
                  throws IllegalArgumentException
Sets the specified attribute potentially replacing anything that was previously stored for the same name. The value defaults to be the same as the name (no attributes are allowed without values). The value is parsed for entities (see HTMLAttribute.HTMLAttribute(String)).

Throws:
IllegalArgumentException

setAttributeGroup

void setAttributeGroup(HTMLAttribute[] attributeGroup)
Sets ALL the specified attributes potentially replacing anything that was previously stored for the same name(s).


setStyle

void setStyle(String styleName)
Used to add the attribute class with the specified value. For use with CSS stylesheets.


removeAttribute

boolean removeAttribute(String name)
Attempts to remove the attribute with the specified name.

Parameters:
name - the name of the attribute to remove
Returns:
true if the attribute was removed, false otherwise.

removeAllAttributes

void removeAllAttributes()
Removes all of the attributes.


hasChildren

boolean hasChildren()
Returns true if there are currently any children nested within this element.


getChildren

HTMLElement[] getChildren()
Returns an array of all of the children of this element. If there are no children, then a zero-len array is returned (null is never returned).


add

HTMLElement add(HTMLElement element)
Add the specified child element to this container. The value returned is the same as the value passed in—allowing for convenient method chaining.

Parameters:
element - the element to add. null is ignored (and returned).
Returns:
the element added (same as what is passed in).

add

HTMLString add(String text)
Convenience method to wrap the specified text in an HTMLString and call add(HTMLElement). Only adds the specified text if it is not null and has a length greater than 0. The value returned is the HTMLString created, or null if the passed text was null or zero-length.


addSibling

HTMLElement addSibling(HTMLElement element)
                       throws HTMLException
Add the specified element to this element's parent. The value returned is the same as the value passed in—allowing for convenient method chaining. Equivalent to:
 getParent().add(element);
 

Parameters:
element - the element to add. null is ignored (and returned).
Returns:
the element added (same as what is passed in).
Throws:
HTMLException - if there is no parent container at the moment (if getParent() returns null). This is a RuntimeException, so callers are not required to use a try/catch block.

addSibling

HTMLString addSibling(String text)
                      throws HTMLException
Convenience method to wrap the specified text in an HTMLString and call addSibling(HTMLElement). Only adds the specified text if it is not null and has a length greater than 0. The value returned is the HTMLString created, or null if the passed text was null or zero-length.

Throws:
HTMLException - if there is no parent container at the moment (if getParent() returns null). This is a RuntimeException, so callers are not required to use a try/catch block.

removeChild

boolean removeChild(int index)
Attempts to remove the child HTMLElement at the specified index. Out of range index values are silently ignored. The index value is based on the order the elements are returned from getChildren().

Parameters:
index - value from 0 to (getChildren().length - 1)
Returns:
true if the child was removed, false otherwise.

removeAllChildren

void removeAllChildren()
Removes all of the children.


setParent

void setParent(HTMLElement parent)
Changes or initially sets the parent element for this element.


getParent

HTMLElement getParent()
Returns the current parent element of this element (may be null).


isSafeToWrapWithWhitespace

boolean isSafeToWrapWithWhitespace()
Returns true if is is safe to add whitespace before and after this element. This is mostly used for formatting HTML purposes. Any elements that are not sure should return false to be safer.


SimpleServlets v5.5.0

Copyright © 2001-2007 Programix Incorporated. All rights reserved. SimpleServlets is free and is OSI Certified Open Source Software under the BSD license.