org.apache.lenya.xml
Class NamespaceHelper

java.lang.Object
  extended by org.apache.lenya.xml.NamespaceHelper

public class NamespaceHelper
extends java.lang.Object

A NamespaceHelper object simplifies the creation of elements in a certain namespace. All elements are owned by a document that is passed to the NamespaceHelper(String, String, Document) constructor or created using the NamespaceHelper(String, String, String) constructor.


Constructor Summary
NamespaceHelper(java.lang.String _namespaceUri, java.lang.String _prefix, org.w3c.dom.Document _document)
          Creates a new instance of NamespaceHelper using an existing document.
NamespaceHelper(java.lang.String _namespaceUri, java.lang.String _prefix, java.lang.String localName)
           Creates a new instance of NamespaceHelper.
 
Method Summary
 org.w3c.dom.Element createElement(java.lang.String localName)
           Creates an element within the namespace of this NamespaceHelper object with a given local name containing a text node.
 org.w3c.dom.Element createElement(java.lang.String localName, java.lang.String text)
           Creates an element within the namespace of this NamespaceHelper object with a given local name containing a text node.
 org.w3c.dom.Element[] getChildren(org.w3c.dom.Element element)
          Returns all children of an element in the namespace of this NamespaceHelper.
 org.w3c.dom.Element[] getChildren(org.w3c.dom.Element element, java.lang.String localName)
          Returns all children of an element with a local name in the namespace of this NamespaceHelper.
 org.w3c.dom.Document getDocument()
          Returns the document that is used to create elements.
 org.w3c.dom.Element getFirstChild(org.w3c.dom.Element element, java.lang.String localName)
          Returns the first childr of an element with a local name in the namespace of this NamespaceHelper or null if none exists.
 java.lang.String getNamespaceURI()
          Returns the namespace URI of this NamespaceHelper.
 org.w3c.dom.Element[] getNextSiblings(org.w3c.dom.Element element, java.lang.String localName)
          Returns the next siblings of an element with a local name in the namespace of this NamespaceHelper or null if none exists.
 org.w3c.dom.Element[] getPrecedingSiblings(org.w3c.dom.Element element, java.lang.String localName)
          Returns the preceding siblings of an element with a local name in the namespace of this NamespaceHelper or null if none exists.
 java.lang.String getPrefix()
          Returns the namespace prefix that is used to create elements.
static java.lang.String getQualifiedName(java.lang.String prefix, java.lang.String localName)
          Returns the qualified name for a local name using the prefix of this NamespaceHelper.
 void save(java.io.OutputStream stream)
          Saves the XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespaceHelper

public NamespaceHelper(java.lang.String _namespaceUri,
                       java.lang.String _prefix,
                       org.w3c.dom.Document _document)
Creates a new instance of NamespaceHelper using an existing document. The document is not affected. If the prefix is null, the default namespace is used.

Parameters:
_document - The document.
_namespaceUri - The namespace URI.
_prefix - The namespace prefix.

NamespaceHelper

public NamespaceHelper(java.lang.String _namespaceUri,
                       java.lang.String _prefix,
                       java.lang.String localName)
                throws javax.xml.parsers.ParserConfigurationException

Creates a new instance of NamespaceHelper. A new document is created using a document element in the given namespace with the given prefix. If the prefix is null, the default namespace is used.

NamespaceHelper("http://www.w3.org/2000/svg", "svg", "svg"):
<?xml version="1.0">
<svg:svg xmlns:svg="http://www.w3.org/2000/svg">
</svg:svg>

Parameters:
localName - The local name of the document element.
_namespaceUri - The namespace URI.
_prefix - The namespace prefix.
Throws:
javax.xml.parsers.ParserConfigurationException - if an error occured
Method Detail

getDocument

public org.w3c.dom.Document getDocument()
Returns the document that is used to create elements.

Returns:
A document object.

getNamespaceURI

public java.lang.String getNamespaceURI()
Returns the namespace URI of this NamespaceHelper.

Returns:
The namespace URI.

getPrefix

public java.lang.String getPrefix()
Returns the namespace prefix that is used to create elements.

Returns:
The namespace prefix.

getQualifiedName

public static java.lang.String getQualifiedName(java.lang.String prefix,
                                                java.lang.String localName)
Returns the qualified name for a local name using the prefix of this NamespaceHelper.

Parameters:
prefix - The namespace prefix.
localName - The local name.
Returns:
The qualified name, i.e. prefix:localName.

createElement

public org.w3c.dom.Element createElement(java.lang.String localName)

Creates an element within the namespace of this NamespaceHelper object with a given local name containing a text node.

createElement("text"): <prefix:text/>.

Parameters:
localName - The local name of the element.
Returns:
A new element.

createElement

public org.w3c.dom.Element createElement(java.lang.String localName,
                                         java.lang.String text)

Creates an element within the namespace of this NamespaceHelper object with a given local name containing a text node.

createElement("text", "Hello World!"): <prefix:text>Hello World!</prefix:text>.

Parameters:
localName - The local name of the element.
text - The text for the text node inside the element.
Returns:
A new element containing a text node.

getChildren

public org.w3c.dom.Element[] getChildren(org.w3c.dom.Element element)
Returns all children of an element in the namespace of this NamespaceHelper.

Parameters:
element - The parent element.
Returns:
the children.

getChildren

public org.w3c.dom.Element[] getChildren(org.w3c.dom.Element element,
                                         java.lang.String localName)
Returns all children of an element with a local name in the namespace of this NamespaceHelper.

Parameters:
element - The parent element.
localName - The local name of the children to return.
Returns:
the children.

getFirstChild

public org.w3c.dom.Element getFirstChild(org.w3c.dom.Element element,
                                         java.lang.String localName)
Returns the first childr of an element with a local name in the namespace of this NamespaceHelper or null if none exists.

Parameters:
element - The parent element.
localName - The local name of the children to return.
Returns:
the first child.

getNextSiblings

public org.w3c.dom.Element[] getNextSiblings(org.w3c.dom.Element element,
                                             java.lang.String localName)
Returns the next siblings of an element with a local name in the namespace of this NamespaceHelper or null if none exists.

Parameters:
element - The parent element.
localName - The local name of the children to return.
Returns:
the next siblings.

getPrecedingSiblings

public org.w3c.dom.Element[] getPrecedingSiblings(org.w3c.dom.Element element,
                                                  java.lang.String localName)
Returns the preceding siblings of an element with a local name in the namespace of this NamespaceHelper or null if none exists.

Parameters:
element - The parent element.
localName - The local name of the children to return.
Returns:
the preceding siblings.

save

public void save(java.io.OutputStream stream)
Saves the XML.

Parameters:
stream - The stream to write to.


Copyright © 1999-2006 Apache Software Foundation. All Rights Reserved.