com.randomcoder.xml
Class XmlUtils

java.lang.Object
  extended by com.randomcoder.xml.XmlUtils

public final class XmlUtils
extends Object

Various convenience methods to get data in and out of DOM, pretty print, etc.

 Copyright (c) 2006, Craig Condit. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
   * Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
     
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 


Method Summary
static Transformer getTransformer(boolean indent, String publicId, String systemId, Source xsl)
          Gets a Transformer object suitable for writing DOM objects.
static void logXml(org.apache.commons.logging.Log log, Document doc)
          Log XML to the given log object.
static void logXml(org.apache.commons.logging.Log log, Document doc, String publicId, String systemId)
          Log XML to the given log object.
static void logXml(org.apache.commons.logging.Log log, String message, Document doc)
          Log XML to the given log object.
static void logXml(org.apache.commons.logging.Log log, String message, Document doc, String publicId, String systemId)
          Log XML to the given log object.
static Document parseXml(InputSource source)
          Parse the given input source into a DOM object.
static void prettyPrint(Document input, StreamResult output)
          Pretty-print (indent) a DOM document.
static void prettyPrint(Document input, StreamResult output, DocumentType docType)
          Pretty-print (indent) a DOM document.
static void writeXml(Document doc, Result result, String publicId, String systemId)
          Writes a DOM object to the given Result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseXml

public static Document parseXml(InputSource source)
                         throws SAXException,
                                IOException
Parse the given input source into a DOM object.

Parameters:
source - input source
Returns:
dom representation
Throws:
SAXException - if parsing fails
IOException - if an I/O error occurs

writeXml

public static void writeXml(Document doc,
                            Result result,
                            String publicId,
                            String systemId)
                     throws TransformerException
Writes a DOM object to the given Result.

Parameters:
doc - Document to convert
result - destination
publicId - public id of dtd or null if not specified
systemId - system id of dtd or null if not specified
Throws:
TransformerException - if transformation fails

getTransformer

public static Transformer getTransformer(boolean indent,
                                         String publicId,
                                         String systemId,
                                         Source xsl)
Gets a Transformer object suitable for writing DOM objects.

Parameters:
indent - whether to indent output
publicId - public id of dtd or null if not specified
systemId - system id of dtd or null if not specified
xsl - XSL source or null if not needed
Returns:
Transformer configured to output using the given parameters

logXml

public static void logXml(org.apache.commons.logging.Log log,
                          Document doc)
Log XML to the given log object.

Parameters:
log - log to output to
doc - document to write

logXml

public static void logXml(org.apache.commons.logging.Log log,
                          Document doc,
                          String publicId,
                          String systemId)
Log XML to the given log object.

Parameters:
log - log to output to
doc - document to write
publicId - public id for dtd or null for none
systemId - system id for dtd or null for none

logXml

public static void logXml(org.apache.commons.logging.Log log,
                          String message,
                          Document doc)
Log XML to the given log object.

Parameters:
log - log to output to
message - message to add
doc - document to write

logXml

public static void logXml(org.apache.commons.logging.Log log,
                          String message,
                          Document doc,
                          String publicId,
                          String systemId)
Log XML to the given log object.

Parameters:
log - log to output to
message - message to add
doc - document to write
publicId - public id for dtd or null for none
systemId - system id for dtd or null for none

prettyPrint

public static void prettyPrint(Document input,
                               StreamResult output)
                        throws TransformerException
Pretty-print (indent) a DOM document.

Parameters:
input - DOM input
output - stream result
Throws:
TransformerException - if transformation fails

prettyPrint

public static void prettyPrint(Document input,
                               StreamResult output,
                               DocumentType docType)
                        throws TransformerException
Pretty-print (indent) a DOM document.

Parameters:
input - DOM input
output - stream result
docType - DTD to output
Throws:
TransformerException - if transformation fails


Copyright © 2006-2010 Craig Condit. All Rights Reserved.