Methods Summary |
---|
public void | add(HTMLComponent child)
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 Attribute | addAttribute(java.lang.String id, java.lang.String value)
Attribute att = new HTMLAttribute(id, value);
add(att);
return att;
|
public Text | addComment(java.lang.String content)
HTMLComment comment = new HTMLComment(content);
add(comment);
return comment;
|
public Element | addElement(java.lang.String name)
if (name == null) {
throw new NullPointerException("Element name is null.");
}
Element newElement = new HTMLElement(name);
add(newElement);
return newElement;
|
public Text | addText(java.lang.String text)
if(text != null) {
Text textNode = new HTMLText(text);
add(textNode);
return textNode;
}
return null;
|
public void | addText(java.util.Iterator textValues)
while(textValues.hasNext()) {
Text textNode = new HTMLText(textValues.next());
add(textNode);
}
|
public java.util.List | children()
List<HTMLComponent> childrenList = new LinkedList<HTMLComponent>();
childrenList.addAll(children);
childrenList.addAll(attributes);
return childrenList;
|
public void | delete(HTMLComponent child)
if (child instanceof Attribute) {
attributes.remove(child);
} else {
children.remove(child);
}
|
public java.util.List | get(java.lang.Class type)Get all children of this element which are of a 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.List | getAttributes()
List<Attribute> retval = new LinkedList<Attribute>();
retval.addAll(attributes);
return retval;
|
public java.util.List | getAttributes(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.List | getComments()
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.List | getElements()
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.List | getElements(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.String | getName()
return name;
|
public java.util.List | getTexts()
List<Text> retval = new LinkedList<Text>();
for (HTMLComponent node : children) {
if (node instanceof Text) {
retval.add((Text) node);
}
} // Loop over children.
return retval;
|
public void | setName(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.String | 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 void | write(java.io.Writer output)
output.append(toString());
output.flush();
|
public void | write(java.io.File file)
FileWriter fileWriter = new FileWriter(file);
write(fileWriter);
fileWriter.close();
|