SimpleServlets v5.5.0

com.simpleservlets.htmlobjects
Class GenericHTMLElement

java.lang.Object
  extended by com.simpleservlets.htmlobjects.GenericHTMLElement
All Implemented Interfaces:
HTMLElement
Direct Known Subclasses:
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, HTMLSmall, HTMLSpan, HTMLString, HTMLStrong, HTMLStylesheetRef, HTMLSubscript, HTMLSuperscript, HTMLTable, HTMLTable.Cell, HTMLTable.Row, HTMLTitle, HTMLUnderline, NoTagHTMLElement

public class GenericHTMLElement
extends Object
implements HTMLElement

Core implementation of HTMLElement. This class can be used directly for HTML support which is not present in HTMLObjects. GenericHTMLElement can be used as a superclass, or it can be instantiated directly.

Author:
Paul Hyde

Field Summary
 
Fields inherited from interface com.simpleservlets.htmlobjects.HTMLElement
ZERO_LEN_ARRAY
 
Constructor Summary
GenericHTMLElement()
           
GenericHTMLElement(String name)
           
GenericHTMLElement(String name, boolean safeToWrapWithWhitespace)
           
GenericHTMLElement(String name, HTMLElement parent)
           
GenericHTMLElement(String name, HTMLElement parent, boolean safeToWrapWithWhitespace)
           
 
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 HTMLElement.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 attName)
          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)
          Adds or replaces the specified attribute to the list of attributes.
 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.
protected  void setSafeToWrapWithWhitespace(boolean extraWhitespaceIsHarmless)
          Widen to public on subclasses where it is appropriate to be able to set this value externally.
 void setStyle(String styleName)
          Used to add the attribute class with the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericHTMLElement

public GenericHTMLElement(String name,
                          HTMLElement parent,
                          boolean safeToWrapWithWhitespace)

GenericHTMLElement

public GenericHTMLElement(String name,
                          HTMLElement parent)

GenericHTMLElement

public GenericHTMLElement(String name,
                          boolean safeToWrapWithWhitespace)

GenericHTMLElement

public GenericHTMLElement(String name)

GenericHTMLElement

public GenericHTMLElement()
Method Detail

getName

public String getName()
Description copied from interface: HTMLElement
Returns the tag name for this element.

Specified by:
getName in interface HTMLElement

hasAttributes

public boolean hasAttributes()
Description copied from interface: HTMLElement
Returns true if this element has any attributes set.

Specified by:
hasAttributes in interface HTMLElement

getAttributes

public HTMLAttribute[] getAttributes()
Description copied from interface: HTMLElement
Returns an array of all of the attributes. If there are no attributes, a zero-length array is returned.

Specified by:
getAttributes in interface HTMLElement

setAttribute

public void setAttribute(HTMLAttribute attribute)
Adds or replaces the specified attribute to the list of attributes. All the overloaded versions of setAttribute call this method (so subclasses that wish to intercept the addition of attributes need only override this method).

Specified by:
setAttribute in interface HTMLElement

setAttribute

public void setAttribute(String name,
                         String value)
Description copied from interface: HTMLElement
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)).

Specified by:
setAttribute in interface HTMLElement

setAttribute

public void setAttribute(String name,
                         Value value)
Description copied from interface: HTMLElement
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)).

Specified by:
setAttribute in interface HTMLElement

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: HTMLElement
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)).

Specified by:
setAttribute in interface HTMLElement

setAttribute

public void setAttribute(String name,
                         int value)
Description copied from interface: HTMLElement
Sets the specified attribute potentially replacing anything that was previously stored for the same name. (see HTMLAttribute.HTMLAttribute(String, int)).

Specified by:
setAttribute in interface HTMLElement

setAttribute

public void setAttribute(String name,
                         double value)
Description copied from interface: HTMLElement
Sets the specified attribute potentially replacing anything that was previously stored for the same name. (see HTMLAttribute.HTMLAttribute(String, double)).

Specified by:
setAttribute in interface HTMLElement

setAttribute

public void setAttribute(String name)
Description copied from interface: HTMLElement
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)).

Specified by:
setAttribute in interface HTMLElement

setAttributeGroup

public void setAttributeGroup(HTMLAttribute[] attributeGroup)
Description copied from interface: HTMLElement
Sets ALL the specified attributes potentially replacing anything that was previously stored for the same name(s).

Specified by:
setAttributeGroup in interface HTMLElement

setStyle

public void setStyle(String styleName)
Description copied from interface: HTMLElement
Used to add the attribute class with the specified value. For use with CSS stylesheets.

Specified by:
setStyle in interface HTMLElement

removeAttribute

public boolean removeAttribute(String attName)
Description copied from interface: HTMLElement
Attempts to remove the attribute with the specified name.

Specified by:
removeAttribute in interface HTMLElement
Parameters:
attName - the name of the attribute to remove
Returns:
true if the attribute was removed, false otherwise.

removeAllAttributes

public void removeAllAttributes()
Description copied from interface: HTMLElement
Removes all of the attributes.

Specified by:
removeAllAttributes in interface HTMLElement

hasChildren

public boolean hasChildren()
Description copied from interface: HTMLElement
Returns true if there are currently any children nested within this element.

Specified by:
hasChildren in interface HTMLElement

getChildren

public HTMLElement[] getChildren()
Description copied from interface: HTMLElement
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).

Specified by:
getChildren in interface HTMLElement

add

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

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

add

public HTMLString add(String text)
Description copied from interface: HTMLElement
Convenience method to wrap the specified text in an HTMLString and call HTMLElement.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.

Specified by:
add in interface HTMLElement

addSibling

public HTMLElement addSibling(HTMLElement element)
                       throws HTMLException
Description copied from interface: HTMLElement
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);
 

Specified by:
addSibling in interface HTMLElement
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

public HTMLString addSibling(String text)
                      throws HTMLException
Description copied from interface: HTMLElement
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.

Specified by:
addSibling in interface HTMLElement
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

public boolean removeChild(int index)
Description copied from interface: HTMLElement
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 HTMLElement.getChildren().

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

removeAllChildren

public void removeAllChildren()
Description copied from interface: HTMLElement
Removes all of the children.

Specified by:
removeAllChildren in interface HTMLElement

setParent

public void setParent(HTMLElement parent)
Description copied from interface: HTMLElement
Changes or initially sets the parent element for this element.

Specified by:
setParent in interface HTMLElement

getParent

public HTMLElement getParent()
Description copied from interface: HTMLElement
Returns the current parent element of this element (may be null).

Specified by:
getParent in interface HTMLElement

isSafeToWrapWithWhitespace

public boolean isSafeToWrapWithWhitespace()
Description copied from interface: HTMLElement
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.

Specified by:
isSafeToWrapWithWhitespace in interface HTMLElement

setSafeToWrapWithWhitespace

protected void setSafeToWrapWithWhitespace(boolean extraWhitespaceIsHarmless)
Widen to public on subclasses where it is appropriate to be able to set this value externally.


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.