SAP NetWeaver '04

com.sapportals.wcm.util.xml
Class SimpleSerializer

[contained in: com.sap.netweaver.bc.util.par - bc.util.public_api.jar]
java.lang.Object
  |
  +--com.sapportals.wcm.util.xml.SimpleSerializer

public final class SimpleSerializer
extends java.lang.Object

Simple DOM serializer. Only supports UTF-8 encoding and simple indentation (whitespace preservation not implemented - if whitespace preservation is required simply do not indent).

Copyright (c) SAP AG 2001-2004


Field Summary
static java.lang.String NS_XML
          Namespace name for the namespace hardwired to the prefix "xml:"
static java.lang.String NS_XMLNS
          Namespace name for the namespace hardwired to the prefix "xmlns:"
 
Constructor Summary
SimpleSerializer(java.io.Writer writer, java.lang.String indent)
          Construct a new Serializer
 
Method Summary
 void closeElement()
          Closes the currently open element.
static java.lang.String escape(java.lang.String s, boolean escapeQuoteChar)
          Escape characters in a string for inclusion into XML text content.
 SimpleSerializer openElement(org.w3c.dom.Element element)
          Serializes the open tag of the specified element and returns a new SimpleSerializer object for use in serializing any child elements (and writing the closing tag).
 void serialize(org.w3c.dom.Node n)
          Serialize a node and it's children.
 void setNsAware(boolean nsAware)
          Set to false to switch off namespace processing (enabling strict DOM level 1 serialization)
 void setOptimizeNSDeclarations(boolean doOptimize)
           
static java.lang.String toString(org.w3c.dom.Document doc, boolean indent)
          Serialize the document to a string.
static java.lang.String toString(org.w3c.dom.Document doc, boolean indent, boolean doNsProcessing)
          Serialize the document to a string.
static java.lang.String toString(org.w3c.dom.Node n, boolean indent)
          Serialize the element (and it's children) to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NS_XML

public static final java.lang.String NS_XML
Namespace name for the namespace hardwired to the prefix "xml:"

NS_XMLNS

public static final java.lang.String NS_XMLNS
Namespace name for the namespace hardwired to the prefix "xmlns:"
Constructor Detail

SimpleSerializer

public SimpleSerializer(java.io.Writer writer,
                        java.lang.String indent)
Construct a new Serializer
Parameters:
writer - output
indent - indentation string
Method Detail

toString

public static java.lang.String toString(org.w3c.dom.Document doc,
                                        boolean indent)
Serialize the document to a string.
Parameters:
doc - the document
indent - whether to produce indented XML or not
Returns:
the XML string or an empty string in case of error

toString

public static java.lang.String toString(org.w3c.dom.Document doc,
                                        boolean indent,
                                        boolean doNsProcessing)
Serialize the document to a string.
Parameters:
doc - the document
indent - whether to produce indented XML or not
doNsProcessing - enable/disable special namespace support in the serializer
Returns:
the XML string or an empty string in case of error

toString

public static java.lang.String toString(org.w3c.dom.Node n,
                                        boolean indent)
                                 throws java.lang.IllegalArgumentException
Serialize the element (and it's children) to a string.
Parameters:
indent - whether to produce indented XML or not
n - node to serialize
Returns:
the XML string or an empty string in case of error
Throws:
java.lang.IllegalArgumentException - when node is a AttributeNode

setNsAware

public void setNsAware(boolean nsAware)
Set to false to switch off namespace processing (enabling strict DOM level 1 serialization)
Parameters:
nsAware - flag

setOptimizeNSDeclarations

public void setOptimizeNSDeclarations(boolean doOptimize)

openElement

public SimpleSerializer openElement(org.w3c.dom.Element element)
                             throws java.io.IOException
Serializes the open tag of the specified element and returns a new SimpleSerializer object for use in serializing any child elements (and writing the closing tag).
Parameters:
element - Element for which the start tag shall be written
Returns:
new Serializer object
Throws:
java.io.IOException - Exception raised in failure situation

closeElement

public void closeElement()
                  throws java.io.IOException
Closes the currently open element. Do not use this object after calling this method!
Throws:
java.io.IOException - Exception raised in failure situation

escape

public static java.lang.String escape(java.lang.String s,
                                      boolean escapeQuoteChar)
                               throws java.io.IOException
Escape characters in a string for inclusion into XML text content. The generated string is guaranteed to only contain characters from the US-ASCII character set.
Parameters:
s - un-escaped string
escapeQuoteChar - whether to escape the quote character or not (for attribute values). Note that attributes are supposed to be quoted using double quotes, so apostroph characters are not replaced.
Returns:
escaped string
Throws:
java.io.IOException - when quoting not possible

serialize

public void serialize(org.w3c.dom.Node n)
               throws java.io.IOException
Serialize a node and it's children.
Parameters:
n - start node
Throws:
java.io.IOException - Exception raised in failure situation

SAP NetWeaver '04

Copyright © 2004 by SAP AG. All Rights Reserved.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.