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(Document, String, String) 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.
 java.lang.String getPrefix()
          Returns the namespace prefix that is used to create elements.
 java.lang.String getQualifiedName(java.lang.String localName)
          Returns the qualified name for a local name using the prefix of this NamespaceHelper.
protected  void setDocument(org.w3c.dom.Document document)
          Sets the document of this NamespaceHelper.
 
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 you omit the prefix, 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 you omit the prefix, 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

setDocument

protected void setDocument(org.w3c.dom.Document document)
Sets the document of this NamespaceHelper.

Parameters:
document - the document

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 java.lang.String getQualifiedName(java.lang.String localName)
Returns the qualified name for a local name using the prefix of this NamespaceHelper.

Parameters:
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.


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