org.apache.cocoon.xml
Class XMLUtils

java.lang.Object
  extended by org.apache.cocoon.xml.XMLUtils

public class XMLUtils
extends Object

XML utility methods.

Version:
$Id: XMLUtils.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Nicola Ken Barozzi, Sylvain Wallez, Carsten Ziegeler

Field Summary
static Attributes EMPTY_ATTRIBUTES
          Empty attributes immutable object.
 
Constructor Summary
XMLUtils()
           
 
Method Summary
static void createElement(ContentHandler contentHandler, String localName)
          Create a start and endElement with a empty Namespace and without Attributes
static void createElement(ContentHandler contentHandler, String localName, Attributes atts)
          Create a start and endElement with a empty Namespace
static void createElement(ContentHandler contentHandler, String localName, Attributes atts, String stringValue)
          Create a start and endElement with a empty Namespace The content of the Element is set to the stringValue parameter
static void createElement(ContentHandler contentHandler, String localName, String stringValue)
          Create a start and endElement with a empty Namespace and without Attributes The content of the Element is set to the stringValue parameter
static void createElementNS(ContentHandler contentHandler, String namespaceURI, String localName)
          Create a start and endElement without Attributes
static void createElementNS(ContentHandler contentHandler, String namespaceURI, String localName, Attributes atts)
          Create a start and endElement
static void createElementNS(ContentHandler contentHandler, String namespaceURI, String localName, Attributes atts, String stringValue)
          Create a start and endElement with a empty Namespace The content of the Element is set to the stringValue parameter
static void createElementNS(ContentHandler contentHandler, String namespaceURI, String localName, String stringValue)
          Create a start and endElement without Attributes The content of the Element is set to the stringValue parameter
static Properties createPropertiesForXML(boolean omitXMLDeclaration)
          Create a new properties set for serializing xml.
static void data(ContentHandler contentHandler, String data)
          Add string data
static Properties defaultSerializeToXMLFormat()
          Deprecated. Use createPropertiesForXML(false) instead and add the encoding
static Properties defaultSerializeToXMLFormat(boolean omitXMLDeclaration)
          Deprecated. Use createPropertiesForXML(boolean) instead and add the encoding
static void endElement(ContentHandler contentHandler, String localName)
          Create endElement with empty Namespace For information on the names, see startElement.
static void endElement(ContentHandler contentHandler, String namespaceURI, String localName)
          Create endElement Prefix must be mapped to empty String For information on the names, see startElement.
static XMLConsumer getConsumer(ContentHandler ch)
          Get an XMLConsumer from ContentHandler.
static XMLConsumer getConsumer(ContentHandler ch, LexicalHandler lh)
          Get an XMLConsumer from a ContentHandler and a LexicalHandler.
static String serialize(XMLizable xml, Properties format)
          Serialize a XMLizable into a string.
static String serializeNode(Node node)
          Serialize a DOM node into a string using format created by createPropertiesForXML(false).
static String serializeNode(Node node, Properties format)
          Serialize a DOM node into a string.
static String serializeNodeToXML(Node node)
          Deprecated. use serializeNode(Node, Properties) instead
static void startElement(ContentHandler contentHandler, String localName)
          Create a startElement with a empty Namespace and without Attributes
static void startElement(ContentHandler contentHandler, String localName, Attributes atts)
          Create a startElement with a empty Namespace
static void startElement(ContentHandler contentHandler, String namespaceURI, String localName)
          Create a startElement without Attributes Prefix must be mapped to empty String
static void startElement(ContentHandler contentHandler, String namespaceURI, String localName, Attributes atts)
          Create a startElement with a empty Namespace Prefix must be mapped to empty String
static void stripDuplicateAttributes(Node node, Node parent)
           
static void valueOf(ContentHandler contentHandler, Collection v)
          Implementation of <xsp:expr> for java.util.Collection : outputs the value by calling xspExpr() on each element of the collection.
static void valueOf(ContentHandler contentHandler, Node v)
          Implementation of <xsp:expr> for org.w3c.dom.Node : converts the Node to a SAX event stream.
static void valueOf(ContentHandler contentHandler, Object v)
          Implementation of <xsp:expr> for Object depending on its class : if it's an array, call xspExpr() on all its elements, if it's class has a specific xspExpr()implementation, use it, else, output it's string representation.
static void valueOf(ContentHandler contentHandler, String text)
          Implementation of <xsp:expr> for String : outputs characters representing the value.
static void valueOf(ContentHandler contentHandler, XMLizable v)
          Implementation of <xsp:expr> for XMLizable : outputs the value by calling v.toSax(contentHandler).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ATTRIBUTES

public static final Attributes EMPTY_ATTRIBUTES
Empty attributes immutable object.

Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

stripDuplicateAttributes

public static void stripDuplicateAttributes(Node node,
                                            Node parent)

getConsumer

public static XMLConsumer getConsumer(ContentHandler ch,
                                      LexicalHandler lh)
Get an XMLConsumer from a ContentHandler and a LexicalHandler. If the content handler is already an XMLConsumer, it is returned as is, otherwise it is wrapped in an XMLConsumer with the lexical handler.

Parameters:
ch - the content handler, which should not be null
lh - the lexical handler, which can be null
Returns:
an XMLConsumer for ch an lh

getConsumer

public static XMLConsumer getConsumer(ContentHandler ch)
Get an XMLConsumer from ContentHandler. If the content handler is already an XMLConsumer, it is returned as is, otherwise it is wrapped in an XMLConsumer.

Parameters:
ch - the content handler, which should not be null
Returns:
an XMLConsumer for ch

serializeNodeToXML

public static String serializeNodeToXML(Node node)
                                 throws ProcessingException
Deprecated. use serializeNode(Node, Properties) instead

Serialize a DOM node to a String. The defaultSerializeToXMLFormat() is used to format the serialized xml.

Throws:
ProcessingException

defaultSerializeToXMLFormat

public static Properties defaultSerializeToXMLFormat()
Deprecated. Use createPropertiesForXML(false) instead and add the encoding

This is the default properties set used to serialize xml. It is used by the serializeNodeToXML() method. The format is as follows: Method: xml Encoding: ISO-8859-1 Omit xml declaration: no Indent: yes


defaultSerializeToXMLFormat

public static Properties defaultSerializeToXMLFormat(boolean omitXMLDeclaration)
Deprecated. Use createPropertiesForXML(boolean) instead and add the encoding

This is the default properties set used to serialize xml. It is used by the serializeNodeToXML() method. The omit xml declaration property can be controlled by the flag. Method: xml Encoding: ISO-8859-1 Omit xml declaration: according to the flag Indent: yes


createPropertiesForXML

public static Properties createPropertiesForXML(boolean omitXMLDeclaration)
Create a new properties set for serializing xml. The omit xml declaration property can be controlled by the flag.


serializeNode

public static String serializeNode(Node node)
                            throws ProcessingException
Serialize a DOM node into a string using format created by createPropertiesForXML(false).

Throws:
ProcessingException
See Also:
createPropertiesForXML(boolean)

serializeNode

public static String serializeNode(Node node,
                                   Properties format)
                            throws ProcessingException
Serialize a DOM node into a string. If the node is null the empty string is returned.

Parameters:
format - The format of the output to be used by SAX transformer.
Throws:
ProcessingException
See Also:
OutputKeys

serialize

public static String serialize(XMLizable xml,
                               Properties format)
                        throws ProcessingException
Serialize a XMLizable into a string. If the object is null the empty string is returned.

Parameters:
format - The format of the output to be used by SAX transformer.
Throws:
ProcessingException
See Also:
OutputKeys

data

public static void data(ContentHandler contentHandler,
                        String data)
                 throws SAXException
Add string data

Parameters:
contentHandler - The SAX content handler
data - The string data
Throws:
SAXException

valueOf

public static void valueOf(ContentHandler contentHandler,
                           String text)
                    throws SAXException
Implementation of <xsp:expr> for String : outputs characters representing the value.

Parameters:
contentHandler - the SAX content handler
text - the value
Throws:
SAXException

valueOf

public static void valueOf(ContentHandler contentHandler,
                           XMLizable v)
                    throws SAXException
Implementation of <xsp:expr> for XMLizable : outputs the value by calling v.toSax(contentHandler).

Parameters:
contentHandler - the SAX content handler
v - the XML fragment
Throws:
SAXException

valueOf

public static void valueOf(ContentHandler contentHandler,
                           Node v)
                    throws SAXException
Implementation of <xsp:expr> for org.w3c.dom.Node : converts the Node to a SAX event stream.

Parameters:
contentHandler - the SAX content handler
v - the value
Throws:
SAXException

valueOf

public static void valueOf(ContentHandler contentHandler,
                           Collection v)
                    throws SAXException
Implementation of <xsp:expr> for java.util.Collection : outputs the value by calling xspExpr() on each element of the collection.

Parameters:
contentHandler - the SAX content handler
v - the XML fragment
Throws:
SAXException

valueOf

public static void valueOf(ContentHandler contentHandler,
                           Object v)
                    throws SAXException
Implementation of <xsp:expr> for Object depending on its class :

Parameters:
contentHandler - the SAX content handler
v - the value
Throws:
SAXException

createElement

public static void createElement(ContentHandler contentHandler,
                                 String localName)
                          throws SAXException
Create a start and endElement with a empty Namespace and without Attributes

Parameters:
localName - The local name (without prefix)
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String)

createElement

public static void createElement(ContentHandler contentHandler,
                                 String localName,
                                 String stringValue)
                          throws SAXException
Create a start and endElement with a empty Namespace and without Attributes The content of the Element is set to the stringValue parameter

Parameters:
localName - The local name (without prefix)
stringValue - The content of the Element
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String)

createElement

public static void createElement(ContentHandler contentHandler,
                                 String localName,
                                 Attributes atts)
                          throws SAXException
Create a start and endElement with a empty Namespace

Parameters:
localName - The local name (without prefix)
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String), Attributes

createElement

public static void createElement(ContentHandler contentHandler,
                                 String localName,
                                 Attributes atts,
                                 String stringValue)
                          throws SAXException
Create a start and endElement with a empty Namespace The content of the Element is set to the stringValue parameter

Parameters:
localName - The local name (without prefix)
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
stringValue - The content of the Element
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String), Attributes

createElementNS

public static void createElementNS(ContentHandler contentHandler,
                                   String namespaceURI,
                                   String localName)
                            throws SAXException
Create a start and endElement without Attributes

Parameters:
localName - The local name (without prefix)
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String)

createElementNS

public static void createElementNS(ContentHandler contentHandler,
                                   String namespaceURI,
                                   String localName,
                                   String stringValue)
                            throws SAXException
Create a start and endElement without Attributes The content of the Element is set to the stringValue parameter

Parameters:
localName - The local name (without prefix)
stringValue - The content of the Element
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String)

createElementNS

public static void createElementNS(ContentHandler contentHandler,
                                   String namespaceURI,
                                   String localName,
                                   Attributes atts)
                            throws SAXException
Create a start and endElement

Parameters:
localName - The local name (without prefix)
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String), Attributes

createElementNS

public static void createElementNS(ContentHandler contentHandler,
                                   String namespaceURI,
                                   String localName,
                                   Attributes atts,
                                   String stringValue)
                            throws SAXException
Create a start and endElement with a empty Namespace The content of the Element is set to the stringValue parameter

Parameters:
localName - The local name (without prefix)
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
stringValue - The content of the Element
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String), Attributes

endElement

public static void endElement(ContentHandler contentHandler,
                              String localName)
                       throws SAXException
Create endElement with empty Namespace

For information on the names, see startElement.

Parameters:
localName - The local name (without prefix)
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

endElement

public static void endElement(ContentHandler contentHandler,
                              String namespaceURI,
                              String localName)
                       throws SAXException
Create endElement Prefix must be mapped to empty String

For information on the names, see startElement.

Parameters:
localName - The local name (without prefix)
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

startElement

public static void startElement(ContentHandler contentHandler,
                                String localName)
                         throws SAXException
Create a startElement with a empty Namespace and without Attributes

Parameters:
localName - The local name (without prefix)
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String)

startElement

public static void startElement(ContentHandler contentHandler,
                                String namespaceURI,
                                String localName)
                         throws SAXException
Create a startElement without Attributes Prefix must be mapped to empty String

Parameters:
namespaceURI - The Namespace URI
localName - The local name (without prefix)
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String)

startElement

public static void startElement(ContentHandler contentHandler,
                                String localName,
                                Attributes atts)
                         throws SAXException
Create a startElement with a empty Namespace

Parameters:
localName - The local name (without prefix)
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String), Attributes

startElement

public static void startElement(ContentHandler contentHandler,
                                String namespaceURI,
                                String localName,
                                Attributes atts)
                         throws SAXException
Create a startElement with a empty Namespace Prefix must be mapped to empty String

Parameters:
namespaceURI - The Namespace URI
localName - The local name (without prefix)
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(ContentHandler, String), Attributes


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.