com.day.cq.commons
Class SimpleXml.Element

java.lang.Object
  extended by com.day.cq.commons.SimpleXml.Element
Enclosing class:
SimpleXml

public class SimpleXml.Element
extends Object

The SimpleXml.Element reperesents an XML element.


Constructor Summary
protected SimpleXml.Element(String uri, String localName, String name)
          Creates a new SimpleXML.Element instance using the specified URI, local name and name.
 
Method Summary
 SimpleXml.Element addAttribute(String uri, String localName, String name, String value, String type)
          Adds a new attribute to the XML element.
 SimpleXml.Element attr(String name, String value)
          Adds a new attribute to the XML element.
 SimpleXml.Element attr(String localName, String name, String value)
          Adds a new attribute to the XML element.
 SimpleXml.Element attr(String uri, String localName, String name, String value, String type)
          Adds a new attribute to the XML element.
 SimpleXml.Element attrs(String[]... atts)
          Adds the specified attributes to the XML element.
 SimpleXml close()
          Explicitly closes the XML element.
protected  AttributesImpl getAttributes()
          Returns the attributes of the XML element.
protected  String getLocalName()
          Returns the local name of the XML element.
protected  String getName()
          Returns the name of the XML element.
protected  String getText()
          Returns the content of the XML element.
protected  String getUri()
          Returns the URI of the XML element.
protected  SimpleXml getWriter()
          Returns the underlying XML writer
 boolean hasCDATA()
          States whether the XML element has a CDATA block.
protected  boolean isClosed()
          States whether the output of the XML element has been ended.
protected  boolean isOpened()
          States whether the output of the XML element has been started.
 SimpleXml open()
          Explicitly opens the XML element.
 SimpleXml.Element open(String name)
          Opens and returns a new XML element with the specified name.
 SimpleXml.Element open(String localName, String name)
          Opens and returns a new XML element with the specified name.
 SimpleXml.Element open(String name, String content, boolean cdata)
          Opens and returns a new XML element with the specified name and content.
 SimpleXml.Element open(String uri, String localName, String name)
          Opens and returns a new XML element with the specified name.
 SimpleXml.Element setCDATA(boolean cdata)
          Defines whether the XML element has a CDATA block.
protected  void setClosed(boolean closed)
          Defines whether the output of the XML element has been ended.
protected  void setOpened(boolean opened)
          Defines whether the output of the XML element has been started.
 SimpleXml.Element setText(String text, boolean cdata)
          Sets the content of the XML element.
 SimpleXml.Element text(String text)
          Sets the content of the XML element.
 SimpleXml.Element text(String text, boolean cdata)
          Sets the content of the XML element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleXml.Element

protected SimpleXml.Element(String uri,
                            String localName,
                            String name)
Creates a new SimpleXML.Element instance using the specified URI, local name and name.

Parameters:
uri - The URI of the XML element
localName - The local name of the XML element
name - The name of the XML element
Method Detail

attr

public SimpleXml.Element attr(String name,
                              String value)
Adds a new attribute to the XML element. This method is a shorthand for addAttribute(String, String, String, String, String).

Parameters:
name - The name of the attribute
value - The value of the attribute
Returns:
The XML element

attr

public SimpleXml.Element attr(String localName,
                              String name,
                              String value)
Adds a new attribute to the XML element. This method is a shorthand for addAttribute(String, String, String, String, String).

Parameters:
localName - The local name of the attribute
name - The name of the attribute
value - The value of the attribute
Returns:
The XML element

attr

public SimpleXml.Element attr(String uri,
                              String localName,
                              String name,
                              String value,
                              String type)
Adds a new attribute to the XML element. This method is a shorthand for addAttribute(String, String, String, String, String).

Parameters:
uri - The URI of the attribute
localName - The local name of the attribute
name - The name of the attribute
value - The value of the attribute
type - The type of the attribute
Returns:
The XML element

attrs

public SimpleXml.Element attrs(String[]... atts)
Adds the specified attributes to the XML element.

Parameters:
atts - The attributes
Returns:
The XML element

addAttribute

public SimpleXml.Element addAttribute(String uri,
                                      String localName,
                                      String name,
                                      String value,
                                      String type)
Adds a new attribute to the XML element.

Parameters:
uri - The URI of the attribute
localName - The local name of the attribute
name - The name of the attribute
value - The value of the attribute
type - The type of the attribute
Returns:
The XML element

text

public SimpleXml.Element text(String text)
Sets the content of the XML element. This method is a shorthand for setText(String, boolean).

Parameters:
text - The content
Returns:
The XML element

text

public SimpleXml.Element text(String text,
                              boolean cdata)
Sets the content of the XML element. This method is a shorthand for setText(String, boolean).

Parameters:
text - The content
cdata - true if content should be in a CDATA block, false otherwise
Returns:
The XML element

setText

public SimpleXml.Element setText(String text,
                                 boolean cdata)
Sets the content of the XML element.

Parameters:
text - The content
cdata - true if content should be in a CDATA block, false otherwise
Returns:
The XML element

setCDATA

public SimpleXml.Element setCDATA(boolean cdata)
Defines whether the XML element has a CDATA block.

Parameters:
cdata - true if the XML element has a CDATA block, false otherwise
Returns:
The XML element

open

public SimpleXml open()
               throws IOException
Explicitly opens the XML element. No more attributes can be added to the XML element after calling this method.

Returns:
The XML writer
Throws:
IOException - If output fails

open

public SimpleXml.Element open(String name)
                       throws IOException
Opens and returns a new XML element with the specified name. This method can be used for chaining. It opens the current XML element, then calls its equivalent in SimpleXml.

Parameters:
name - The name of the XML element
Returns:
The XML element
Throws:
IOException - If output fails
See Also:
SimpleXml.open(String)

open

public SimpleXml.Element open(String localName,
                              String name)
                       throws IOException
Opens and returns a new XML element with the specified name. This method can be used for chaining. It opens the current XML element, then calls its equivalent in SimpleXml.

Parameters:
localName - The local name of the XML element
name - The name of the XML element
Returns:
The XML element
Throws:
IOException - If output fails
See Also:
SimpleXml.open(String, String)

open

public SimpleXml.Element open(String uri,
                              String localName,
                              String name)
                       throws IOException
Opens and returns a new XML element with the specified name. This method can be used for chaining. It opens the current XML element, then calls its equivalent in SimpleXml.

Parameters:
uri - The URI of the XML element
localName - The local name of the XML element
name - The name of the XML element
Returns:
The XML element
Throws:
IOException - If output fails
See Also:
SimpleXml.open(String, String, String)

open

public SimpleXml.Element open(String name,
                              String content,
                              boolean cdata)
                       throws IOException
Opens and returns a new XML element with the specified name and content. This method can be used for chaining. It opens the current XML element, then calls its equivalent in SimpleXml.

Parameters:
name - The name of the XML element
content - The content of the XML element
cdata - true if content should be in a CDATA block, false otherwise
Returns:
The XML element
Throws:
IOException - If output fails
See Also:
SimpleXml.open(String, String, boolean)

close

public SimpleXml close()
                throws IOException
Explicitly closes the XML element. This method will write the XML element and consequently render it immutable.

Returns:
The XML writer
Throws:
IOException - If output fails

hasCDATA

public boolean hasCDATA()
States whether the XML element has a CDATA block.

Returns:
true if the XML element has a CDATA block, false otherwise

getWriter

protected SimpleXml getWriter()
Returns the underlying XML writer

Returns:
The XML writer

isOpened

protected boolean isOpened()
States whether the output of the XML element has been started.

Returns:
true if the output has been started, false otherwise

setOpened

protected void setOpened(boolean opened)
Defines whether the output of the XML element has been started.

Parameters:
opened - true if the output has been started, false otherwise

isClosed

protected boolean isClosed()
States whether the output of the XML element has been ended.

Returns:
true if the output has been ended, false otherwise

setClosed

protected void setClosed(boolean closed)
Defines whether the output of the XML element has been ended.

Parameters:
closed - true if the output has been ended, false otherwise

getAttributes

protected AttributesImpl getAttributes()
Returns the attributes of the XML element.

Returns:
The attributes

getUri

protected String getUri()
Returns the URI of the XML element.

Returns:
The URI

getLocalName

protected String getLocalName()
Returns the local name of the XML element.

Returns:
The local name

getName

protected String getName()
Returns the name of the XML element.

Returns:
The name

getText

protected String getText()
Returns the content of the XML element.

Returns:
The content


Copyright © 2009 Day Management AG. All Rights Reserved.