org.jaxup.jdom
Class JDOMDocumentUpdater

java.lang.Object
  extended by org.jaxup.jdom.JDOMDocumentUpdater
All Implemented Interfaces:
Updater

public class JDOMDocumentUpdater
extends java.lang.Object
implements Updater

XML document creating and updating methods for the JDOM document object model.

Author:
Erwin Bolwidt

Constructor Summary
JDOMDocumentUpdater()
           
 
Method Summary
 void appendChild(java.lang.Object element, java.lang.Object child, int position)
          Inserts a node into the document by appending it to the children of the parent, or if the position parameter isn't -1, by inserting it at that position in the list of children of the parent.
 java.lang.Object createAttribute(java.lang.Object contextNode, java.lang.String uri, java.lang.String qname, java.lang.String value)
          Creates an attribute node.
 java.lang.Object createComment(java.lang.Object contextNode, java.lang.String comment)
          Creates a comment node with the given text as the comment.
 java.lang.Object createDocument()
          Creates an empty XML document.
 java.lang.Object createElement(java.lang.Object contextNode, java.lang.String uri, java.lang.String qname)
          Creates an element node.
 java.lang.Object createNamespace(java.lang.Object contextNode, java.lang.String prefix, java.lang.String uri)
          Creates a namespace node.
 java.lang.Object createProcessingInstruction(java.lang.Object contextNode, java.lang.String target, java.lang.String data)
          Creates a processing-instruction node of the given target and data.
 java.lang.Object createText(java.lang.Object contextNode, java.lang.String text)
          Creates a text node of the given text.
protected  org.jdom.Document getDocument(java.lang.Object node)
           
static Navigator getModifiedNavigator()
           
 Navigator getNavigator()
          Returns a jaxen Navigator instance that can be used to navigate the document that is being updated by this Updater.
protected  org.jdom.Element getParent(java.lang.Object node)
           
protected  java.lang.Object getParentOrDocument(java.lang.Object node)
           
 void insertAfter(java.lang.Object refNode, java.lang.Object node)
          Inserts a node into the document after the refNode, as a sibling of the ref Node.
 void insertBefore(java.lang.Object refNode, java.lang.Object node)
          Inserts a node into the document before the refNode, as a sibling of the ref Node.
 void remove(java.lang.Object node)
          Removes a node from the document that it is in.
 void setAttribute(java.lang.Object element, java.lang.Object attribute)
          Sets an attribute on an element node, replacing an existing attribute with the same name.
 void setAttributeValue(java.lang.Object attribute, java.lang.String value)
          Changes the value of an existing attribute.
 void setNamespace(java.lang.Object element, java.lang.Object namespace)
          Binds a namespace node to an element node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDOMDocumentUpdater

public JDOMDocumentUpdater()
Method Detail

createDocument

public java.lang.Object createDocument()
                                throws UpdateException
Description copied from interface: Updater
Creates an empty XML document.

Specified by:
createDocument in interface Updater
Throws:
UpdateException - A document could not be created.

getModifiedNavigator

public static Navigator getModifiedNavigator()

getNavigator

public Navigator getNavigator()
Description copied from interface: Updater
Returns a jaxen Navigator instance that can be used to navigate the document that is being updated by this Updater.

Specified by:
getNavigator in interface Updater
Returns:
A Navigator instance for the same document object model as this updater.
See Also:
Navigator

createComment

public java.lang.Object createComment(java.lang.Object contextNode,
                                      java.lang.String comment)
                               throws InvalidContextException
Description copied from interface: Updater
Creates a comment node with the given text as the comment.

Specified by:
createComment in interface Updater
Parameters:
contextNode - A node in the document in which the comment will be used.
comment - The text of the comment to create.
Returns:
A comment node that can be used in the same document as the contextNode.
Throws:
InvalidContextException - The contextNode parameter is not of a class or interface that the document model recognizes for a node.

createText

public java.lang.Object createText(java.lang.Object contextNode,
                                   java.lang.String text)
                            throws InvalidContextException
Description copied from interface: Updater
Creates a text node of the given text.

Specified by:
createText in interface Updater
Parameters:
contextNode - A node in the document in which the text will be used.
Returns:
A text node that can be used in the same document as the contextNode.
Throws:
InvalidContextException - The contextNode parameter is not of a class or interface that the document model recognizes for a node.

createElement

public java.lang.Object createElement(java.lang.Object contextNode,
                                      java.lang.String uri,
                                      java.lang.String qname)
                               throws InvalidContextException
Description copied from interface: Updater
Creates an element node. Note that the namespace declaration attributes that would bind the prefix of the qname to the namespace uri are not automatically created. If they are not created separately, the document cannot be serialized in to a valid xml document that has the same meaning as the document tree that is in memory.

Specified by:
createElement in interface Updater
Parameters:
contextNode - A node in the document in which the element will be used.
uri - The namespace uri of the new element, or null
qname - The qualified name (prefix, semicolon, localname) of the new element.
Returns:
An element node that can be used in the same document as the contextNode.
Throws:
InvalidContextException - The contextNode parameter is not of a class or interface that the document model recognizes for a node.

createNamespace

public java.lang.Object createNamespace(java.lang.Object contextNode,
                                        java.lang.String prefix,
                                        java.lang.String uri)
                                 throws InvalidContextException
Description copied from interface: Updater
Creates a namespace node. A namespace node is a virtual node that is used in XPath and in XML Infoset. It has no equivalent in a serialized XML document, but is instead derived from the namespace declaration attributes in the serialized XML document. Care needs to be taken to create the namespace declaration attributes when creating namespace nodes, otherwise the serialized XML document may not be a valid representation of the in-memory document.

Specified by:
createNamespace in interface Updater
Parameters:
contextNode - A node in the document in which the namespace will be used.
prefix - The namespace prefix that will be bound to the namespace uri.
uri - The namespace uri of the new namespace node.
Returns:
A namespace node that can be used in the same document as the contextNode.
Throws:
InvalidContextException - The contextNode parameter is not of a class or interface that the document model recognizes for a node.

createAttribute

public java.lang.Object createAttribute(java.lang.Object contextNode,
                                        java.lang.String uri,
                                        java.lang.String qname,
                                        java.lang.String value)
                                 throws InvalidContextException
Description copied from interface: Updater
Creates an attribute node. Note that the namespace declaration attributes that would bind the prefix of the qname to the namespace uri are not automatically created. If they are not created separately, the document cannot be serialized in to a valid xml document that has the same meaning as the document tree that is in memory.

Specified by:
createAttribute in interface Updater
Parameters:
contextNode - A node in the document in which the attribute will be used.
uri - The namespace uri of the new attribute, or null to indicate that the attribute will not be in a namespace.
qname - The qualified name (prefix, semicolon, localname) of the new attribute.
value - The value of the new attribute.
Returns:
An attribute node that can be used in the same document as the contextNode.
Throws:
InvalidContextException - The contextNode parameter is not of a class or interface that the document model recognizes for a node.

createProcessingInstruction

public java.lang.Object createProcessingInstruction(java.lang.Object contextNode,
                                                    java.lang.String target,
                                                    java.lang.String data)
                                             throws InvalidContextException
Description copied from interface: Updater
Creates a processing-instruction node of the given target and data. Format: <?target data?>

Specified by:
createProcessingInstruction in interface Updater
Parameters:
contextNode - A node in the document in which the text will be used.
target - The target for the processing instruction to create.
data - The data for the processing instruction to create. The format of the data depends on the syntax defined by the target; many targets define a syntax simular to the attribute list of an element node.
Returns:
A processing-instruction node that can be used in the same document as the contextNode.
Throws:
InvalidContextException - The contextNode parameter is not of a class or interface that the document model recognizes for a node.

getParent

protected org.jdom.Element getParent(java.lang.Object node)

getDocument

protected org.jdom.Document getDocument(java.lang.Object node)

getParentOrDocument

protected java.lang.Object getParentOrDocument(java.lang.Object node)

insertBefore

public void insertBefore(java.lang.Object refNode,
                         java.lang.Object node)
                  throws UpdateException
Description copied from interface: Updater
Inserts a node into the document before the refNode, as a sibling of the ref Node.

Specified by:
insertBefore in interface Updater
Parameters:
refNode - The reference node, before which the new node will be inserted as a sibling.
node - The node that will be inserted.
Throws:
InvalidNodeException - A parameter that represents a node is not of a class or interface that the document model recognizes for the expected type of node.
UpdateException - Another exception occurred during update.

insertAfter

public void insertAfter(java.lang.Object refNode,
                        java.lang.Object node)
                 throws UpdateException
Description copied from interface: Updater
Inserts a node into the document after the refNode, as a sibling of the ref Node.

Specified by:
insertAfter in interface Updater
Parameters:
refNode - The reference node, after which the new node will be inserted as a sibling.
node - The node that will be inserted.
Throws:
InvalidNodeException - A parameter that represents a node is not of a class or interface that the document model recognizes for the expected type of node.
UpdateException - Another exception occurred during update.

appendChild

public void appendChild(java.lang.Object element,
                        java.lang.Object child,
                        int position)
                 throws UpdateException
Description copied from interface: Updater
Inserts a node into the document by appending it to the children of the parent, or if the position parameter isn't -1, by inserting it at that position in the list of children of the parent.

Specified by:
appendChild in interface Updater
Parameters:
element - The parent node, which must be either a document or element node.
child - The node that will be appended / inserted.
position - The position in the child list where the child node will be inserted, or -1 to append the new child to the list of children.
Throws:
InvalidNodeException - A parameter that represents a node is not of a class or interface that the document model recognizes for the expected type of node.
UpdateException - Another exception occurred during update.

remove

public void remove(java.lang.Object node)
            throws UpdateException
Description copied from interface: Updater
Removes a node from the document that it is in.

Specified by:
remove in interface Updater
Parameters:
node - The node to remove.
Throws:
InvalidNodeException - A parameter that represents a node is not of a class or interface that the document model recognizes for the expected type of node.
UpdateException - Another exception occurred during update.

setAttribute

public void setAttribute(java.lang.Object element,
                         java.lang.Object attribute)
                  throws UpdateException
Description copied from interface: Updater
Sets an attribute on an element node, replacing an existing attribute with the same name.

Specified by:
setAttribute in interface Updater
Parameters:
element - The element node to set the attribute on.
attribute - The attribute node to set on the element.
Throws:
InvalidNodeException - A parameter that represents a node is not of a class or interface that the document model recognizes for the expected type of node.
UpdateException - Another exception occurred during update.

setNamespace

public void setNamespace(java.lang.Object element,
                         java.lang.Object namespace)
                  throws UpdateException
Description copied from interface: Updater
Binds a namespace node to an element node.

Specified by:
setNamespace in interface Updater
Parameters:
element - The element node to bind the namespace node to.
namespace - The namespace node to bind to the element node.
Throws:
InvalidNodeException - A parameter that represents a node is not of a class or interface that the document model recognizes for the expected type of node.
UpdateException - Another exception occurred during update.

setAttributeValue

public void setAttributeValue(java.lang.Object attribute,
                              java.lang.String value)
                       throws UpdateException
Description copied from interface: Updater
Changes the value of an existing attribute.

Specified by:
setAttributeValue in interface Updater
Throws:
UpdateException