org.jcoderz.commons.util
Class XmlUtil

java.lang.Object
  extended by org.jcoderz.commons.util.XmlUtil

public final class XmlUtil
extends Object

This class holds utility methods for common xml topics.

Author:
Andreas Mandel

Field Summary
static Attributes EMPTY_ATTRIBUTES
          Immutable and always empty version of a Attributes object.
 
Method Summary
static String attributeEscape(String attribute)
          Encode a string so that it can be safely used as attribute value in XML output.
static StreamResult createStreamResult(File outFile)
          Creae a stream result based on a File.
static String escape(String text)
          Encode a string so that it can be safely used as text in an element for XML output.
static String formatXml(String org)
          Simple xml formatter.
 
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
Immutable and always empty version of a Attributes object.

Method Detail

attributeEscape

public static String attributeEscape(String attribute)
Encode a string so that it can be safely used as attribute value in XML output.

Parameters:
attribute - the attribute value to be encoded.
Returns:
a string representing the attribute value that can be safely used in XML output.

escape

public static String escape(String text)
Encode a string so that it can be safely used as text in an element for XML output.

Parameters:
text - the element text body.
Returns:
a string so that it can be safely used as text in an element for XML output.

formatXml

public static String formatXml(String org)
Simple xml formatter. This code might fail for several input. In this case the original input is returned.

Parameters:
org - the input to be formated.
Returns:
the input in xml formated (human readable) form or the input string.

createStreamResult

public static StreamResult createStreamResult(File outFile)
                                       throws IOException
Creae a stream result based on a File. Other than the default implementation not only the File is used to initialize the result, but also a Stream is opened and initialized. This works around an issue with whitespaces in the pathname which otherwise would lead to a file not found exception
 Error during transformation: javax.xml.transform.TransformerException: java.io.FileNotFoundException: ...%20...
   at org.apache.xalan.transformer.TransformerImpl.createSerializationHandler(TransformerImpl.java:1218)
   at org.apache.xalan.transformer.TransformerImpl.createSerializationHandler(TransformerImpl.java:1060)
   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1268)
   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)
   ....
 
. The caller must ensure that the created outputstream is closed.

Parameters:
outFile - the file to be used in the stream result.
Returns:
a new StreamResult piontint to the given File.
Throws:
IOException - in case of an issue while creating the stream.


Copyright 2007 The jCoderZ Project.