Package org.apache.jackrabbit.core.util
Class DOMBuilder
- java.lang.Object
-
- org.apache.jackrabbit.core.util.DOMBuilder
-
public final class DOMBuilder extends Object
Document builder class. This class provides an intuitive interface for incrementally building DOM documents.
-
-
Constructor Summary
Constructors Constructor Description DOMBuilder(String name)
Creates a builder for a new DOM document.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContent(String content)
Adds the given string as text content to the current element.void
addContentElement(String name, String content)
Adds a new child element with the given name and text content.void
endElement()
Makes the parent element current.void
setAttribute(String name, boolean value)
Sets the named boolean attribute of the current element.void
setAttribute(String name, String value)
Sets the named attribute of the current element.void
startElement(String name)
Creates a new element with the given name as the child of the current element and makes the created element current.void
write(OutputStream xml)
Writes the document built by this builder into the given output stream.
-
-
-
Constructor Detail
-
DOMBuilder
public DOMBuilder(String name) throws ParserConfigurationException
Creates a builder for a new DOM document. A new DOM document is instantiated and initialized to contain a root element with the given name. The root element is set as the current element of this builder.- Parameters:
name
- name of the root element- Throws:
ParserConfigurationException
- if a document cannot be created
-
-
Method Detail
-
write
public void write(OutputStream xml) throws IOException
Writes the document built by this builder into the given output stream. This method is normally invoked only when the document is fully built.- Parameters:
xml
- XML output stream- Throws:
IOException
- if the document could not be written
-
startElement
public void startElement(String name)
Creates a new element with the given name as the child of the current element and makes the created element current. TheendElement
method needs to be called to return back to the original element.- Parameters:
name
- name of the new element
-
endElement
public void endElement()
Makes the parent element current. This method should be invoked after a child element created with thestartElement
method has been fully built.
-
setAttribute
public void setAttribute(String name, String value)
Sets the named attribute of the current element.- Parameters:
name
- attribute namevalue
- attribute value
-
setAttribute
public void setAttribute(String name, boolean value)
Sets the named boolean attribute of the current element.- Parameters:
name
- attribute namevalue
- boolean attribute value
-
addContent
public void addContent(String content)
Adds the given string as text content to the current element.- Parameters:
content
- text content
-
-