org.apache.jackrabbit.core.util
Class DOMBuilder

java.lang.Object
  extended byorg.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
DOMBuilder(String name)
          Creates a builder for a new DOM document.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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. The endElement 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 the startElement method has been fully built.


setAttribute

public void setAttribute(String name,
                         String value)
Sets the named attribute of the current element.

Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(String name,
                         boolean value)
Sets the named boolean attribute of the current element.

Parameters:
name - attribute name
value - boolean attribute value

addContent

public void addContent(String content)
Adds the given string as text content to the current element.

Parameters:
content - text content

addContentElement

public void addContentElement(String name,
                              String content)
Adds a new child element with the given name and text content. The created element will contain no attributes and no child elements of its own.

Parameters:
name - child element name
content - child element content


Copyright © 2004-2006 The Apache Software Foundation. All Rights Reserved.