com.sapportals.wcm.util.xml

Class SimpleSerializer

java.lang.Object
  extended bycom.sapportals.wcm.util.xml.SimpleSerializer

public final class SimpleSerializer
extends 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-2005


Nested Class Summary
static class SimpleSerializer.IllegalXmlNameException
           
 
Field Summary
static String NS_XML
          Namespace name for the namespace hardwired to the prefix "xml:"
static String NS_XMLNS
          Namespace name for the namespace hardwired to the prefix "xmlns:"
 
Constructor Summary
SimpleSerializer(Writer writer, String indent)
          Construct a new Serializer
 
Method Summary
static void checkLegalNCName(String name)
          Check whether a name is a legal
 void closeElement()
          Closes the currently open element.
static String escape(String s, boolean escapeQuoteChar)
          Escape characters in a string for inclusion into XML text content.
 SimpleSerializer openElement(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(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 String toString(Document doc, boolean indent)
          Serialize the document to a string.
static String toString(Document doc, boolean indent, boolean doNsProcessing)
          Serialize the document to a string.
static String toString(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 String NS_XML
Namespace name for the namespace hardwired to the prefix "xml:"

See Also:
Constant Field Values

NS_XMLNS

public static final String NS_XMLNS
Namespace name for the namespace hardwired to the prefix "xmlns:"

See Also:
Constant Field Values
Constructor Detail

SimpleSerializer

public SimpleSerializer(Writer writer,
                        String indent)
Construct a new Serializer

Parameters:
writer - output
indent - indentation string
Method Detail

toString

public static String toString(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 String toString(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 String toString(Node n,
                              boolean indent)
                       throws 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:
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(Element element)
                             throws 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:
IOException

closeElement

public void closeElement()
                  throws IOException
Closes the currently open element. Do not use this object after calling this method!

Throws:
IOException

escape

public static String escape(String s,
                            boolean escapeQuoteChar)
                     throws 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:
IOException - when quoting not possible

serialize

public void serialize(Node n)
               throws IOException
Serialize a node and it's children.

Parameters:
n - start node
Throws:
IOException

checkLegalNCName

public static void checkLegalNCName(String name)
                             throws SimpleSerializer.IllegalXmlNameException
Check whether a name is a legal SimpleSerializer.IllegalXmlNameException


Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. 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.