FileDocCategorySizeDatePackage
HTMLElement.javaAPI DocGlassfish v2 API9218Fri May 04 22:34:48 BST 2007com.sun.enterprise.diagnostics.report.html

HTMLElement

public class HTMLElement extends Object implements Element
Basic implementation of an element.

Fields Summary
private String
name
The name of this element.
private List
children
The children of this element which are not attributes.
private List
attributes
The attributes for this element.
private static final char
TAG_MARKER_BEGIN
private static final char
TAG_MARKER_END
private static final String
SLASH_BEGIN
private static final String
SLASH_END
Constructors Summary
public HTMLElement(String name)
Make a new element, specifying the name.

param
name The name of the element.


             	         
       
        setName(name);
    
Methods Summary
public voidadd(HTMLComponent child)

param
child The node to add.
return
This element.

        if (child == null) {
            throw new NullPointerException("Child node is null.");
        }
        if (child == this) {
            throw new IllegalArgumentException("Attempt to add a node " +
            		"to itself.  Node is " + toString() + ".");
        }
        if (child instanceof Attribute) {
            attributes.add((Attribute) child);
        } else {
            children.add(child);
        }
    
public AttributeaddAttribute(java.lang.String id, java.lang.String value)

        Attribute att = new HTMLAttribute(id, value);
        add(att);
        return att;
    
public TextaddComment(java.lang.String content)

        HTMLComment comment = new HTMLComment(content);
        add(comment);
        return comment;
       
    
public ElementaddElement(java.lang.String name)

        if (name == null) {
            throw new NullPointerException("Element name is null.");
        }
        Element newElement = new HTMLElement(name);
        add(newElement);
        return newElement;
    
public TextaddText(java.lang.String text)

        if(text != null) {
            Text textNode = new HTMLText(text);
            add(textNode);
            return textNode;
        }
        return null;
    
public voidaddText(java.util.Iterator textValues)

        while(textValues.hasNext()) {
            Text textNode = new HTMLText(textValues.next());
            add(textNode);
        }
    
public java.util.Listchildren()

        List<HTMLComponent> childrenList = new LinkedList<HTMLComponent>();
        childrenList.addAll(children);
        childrenList.addAll(attributes);
        return childrenList;
    
public voiddelete(HTMLComponent child)

param
child The node to delete.

        if (child instanceof Attribute) {
            attributes.remove(child);
        } else {
            children.remove(child);
        }
    
public java.util.Listget(java.lang.Class type)
Get all children of this element which are of a specified class.

param
type The class of the children to obtain.
return
All children of the specified class.

        List<T> list = new LinkedList<T>();
        for (HTMLComponent child : children()) {
            if (type.isInstance(child)) {
                list.add((T) child);
            }
        }
        return list;
    
public java.util.ListgetAttributes()

        List<Attribute> retval = new LinkedList<Attribute>();
        retval.addAll(attributes);
        return retval;
    
public java.util.ListgetAttributes(java.lang.String name)

        List<Attribute> retval = new LinkedList<Attribute>();
        for (HTMLComponent node : getAttributes()) {
            if (node instanceof Attribute) {
                Attribute att = (Attribute) node;
                if (att.getName().equalsIgnoreCase(name)) {
                    retval.add((Attribute) node);
                }
            }
        } // Loop over children.
        return retval;
    
public java.util.ListgetComments()

        List<Text> list = new LinkedList<Text>();
        for (HTMLComponent node : children) {
            if (node instanceof HTMLComment) {
                list.add((HTMLComment) node);
            }
        } // Loop over children.
        return list;
    
public java.util.ListgetElements()

        List<Element> retval = new LinkedList<Element>();
        for (HTMLComponent node : children) {
            if (node instanceof Element) {
                retval.add((Element) node);
            }
        } // Loop over children.
        return retval;
    
public java.util.ListgetElements(java.lang.String name)

        List<Element> list = new LinkedList<Element>();
        for (HTMLComponent node : children) {
            if (node instanceof Element) {
                Element element = (Element) node;
                if (element.getName().equalsIgnoreCase(name)) {
                    list.add((Element) node);
                }
            }
        } // Loop over children.
        return list;
    
public java.lang.StringgetName()

        return name;
    
public java.util.ListgetTexts()

        List<Text> retval = new LinkedList<Text>();
        for (HTMLComponent node : children) {
            if (node instanceof Text) {
                retval.add((Text) node);
            }
        } // Loop over children.
        return retval;
    
public voidsetName(java.lang.String name)

        if (name == null) {
            throw new NullPointerException("Element name is null.");
        }
        if (name.length() == 0) {
            throw new IllegalArgumentException("Element name is empty.");
        }
        this.name = name;
    
public java.lang.StringtoString()

see
java.lang.Object#toString()

        StringBuffer buf = new StringBuffer();
      
        String eName = Escape.getInstance().encodeEntities(name, " \t\r\n");
        buf.append(TAG_MARKER_BEGIN).append(eName);
        for (Attribute att : attributes) {
            buf.append(" ").append(att.toString());
        } // Loop over attributes.
        if (children.size() == 0) {
            buf.append(SLASH_BEGIN);
        } else {
	        buf.append(TAG_MARKER_END);
	        for (HTMLComponent node : children) {
	            buf.append(node.toString());
	        } // Loop over children.
	        buf.append(SLASH_END).append(eName).append(TAG_MARKER_END);
        }
        return buf.toString();
    
public voidwrite(java.io.Writer output)

        output.append(toString());
	output.flush();
    
public voidwrite(java.io.File file)

        FileWriter fileWriter = new FileWriter(file);
        write(fileWriter);
        fileWriter.close();