com.sodius.mdw.core.util.io
Class XMLUtils

java.lang.Object
  extended by com.sodius.mdw.core.util.io.XMLUtils

public final class XMLUtils
extends Object

General XML related operations.

This class cannot be instantiated or subclassed by clients.


Field Summary
static String DEFAULT_ENCODING
          The XML default encoding to use, which is "UTF-8".
static String OPTION_DECLARE_XML
          Option to determine whether to put the XML declaration on top of the serialized XML stream.
static String OPTION_ENCODING
          Options to specify the XML encoding to use.
static String OPTION_FORMATTED
          Option to determine whether to format an XML serialization.
static String OPTION_INDENT_STRING
          Option to specify the indentation String to use.
static String OPTION_NEW_LINE
          Option to specify the line separator to use when serializing XML streams.
static String OPTION_USE_BUFFERED_WRITER
          Option to determine whether to use a buffered stream when serializing an XML stream.
 
Method Summary
static CoreException createCoreException(SAXException e)
          Creates a CoreException based on the specified XML exception.
static XMLWriter createWriter(File file)
          Creates a new XMLWriter instance for the specified file, using the default XML encoding.
static XMLWriter createWriter(OutputStream os, boolean useBuffer)
          Creates a new XMLWriter instance for the specified output stream, using the default XML encoding.
static XMLWriter createWriter(OutputStream os, Map<?,?> options)
          Creates a new XMLWriter instance for the specified output stream, using the serialization options.
static XMLWriter createWriter(Writer writer, boolean useBuffer)
          Creates a new XMLWriter instance for the specified writer.
static XMLWriter createWriter(Writer writer, Map<?,?> options)
          Creates a new XMLWriter instance for the specified writer, using the serialization options.
static SAXParser newParser()
          Creates a new SAXParser parser instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_ENCODING

public static final String OPTION_ENCODING
Options to specify the XML encoding to use. Default value is UTF-8.

Since:
MDWorkbench 3.1.0
See Also:
Constant Field Values

OPTION_NEW_LINE

public static final String OPTION_NEW_LINE
Option to specify the line separator to use when serializing XML streams. Default value is the System line separator, except for XHTML plain text serialization where it is \n.

Since:
MDWorkbench 3.1.0
See Also:
Constant Field Values

OPTION_FORMATTED

public static final String OPTION_FORMATTED
Option to determine whether to format an XML serialization. Default value is true.

Since:
MDWorkbench 3.1.0
See Also:
Constant Field Values

OPTION_DECLARE_XML

public static final String OPTION_DECLARE_XML
Option to determine whether to put the XML declaration on top of the serialized XML stream. Default value is true.

Since:
MDWorkbench 3.1.0
See Also:
Constant Field Values

OPTION_INDENT_STRING

public static final String OPTION_INDENT_STRING
Option to specify the indentation String to use.

Since:
MDWorkbench 3.1.0
See Also:
Constant Field Values

OPTION_USE_BUFFERED_WRITER

public static final String OPTION_USE_BUFFERED_WRITER
Option to determine whether to use a buffered stream when serializing an XML stream. Default value is true.

Since:
MDWorkbench 3.1.0
See Also:
Constant Field Values

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING
The XML default encoding to use, which is "UTF-8".

See Also:
Constant Field Values
Method Detail

newParser

public static SAXParser newParser()
                           throws SAXException
Creates a new SAXParser parser instance.

You should then register to this parser a subclass of XMLDefaultHandler as content handler.

Returns:
the new XML parser instance.
Throws:
SAXException - if an XML parser can't be provided.
See Also:
XMLDefaultHandler

createWriter

public static XMLWriter createWriter(File file)
                              throws IOException
Creates a new XMLWriter instance for the specified file, using the default XML encoding.

Parameters:
file - the output location where to write XML data.
Returns:
a new XML writer.
Throws:
IOException - if the file could not be opened for write.
See Also:
DEFAULT_ENCODING

createWriter

public static XMLWriter createWriter(OutputStream os,
                                     boolean useBuffer)
                              throws IOException
Creates a new XMLWriter instance for the specified output stream, using the default XML encoding.

You can specify whether the platform must use buffering on top of the provided output stream. It is recommended to use buffering, unless the specified output stream internally already uses buffers.

Parameters:
os - the output location where to write XML data.
useBuffer - true if the buffering must be used.
Returns:
a new XML writer.
Throws:
IOException - if the file could not be opened for write.
See Also:
DEFAULT_ENCODING

createWriter

public static XMLWriter createWriter(OutputStream os,
                                     Map<?,?> options)
                              throws IOException
Creates a new XMLWriter instance for the specified output stream, using the serialization options.

Parameters:
os - the output location where to write XML data.
Returns:
a new XML writer.
Throws:
IOException - if the file could not be opened for write.
Since:
MDWorkbench 3.1.0

createWriter

public static XMLWriter createWriter(Writer writer,
                                     boolean useBuffer)
                              throws IOException
Creates a new XMLWriter instance for the specified writer.

You can specify whether the platform must use buffering on top of the provided writer. It is recommended to use buffering, unless the specified writer internally already uses buffers.

Parameters:
writer - the writer where to write XML data.
useBuffer - true if the buffering must be used.
Returns:
a new XML writer.
Throws:
IOException - if the file could not be opened for write.
Since:
2.1.0

createWriter

public static XMLWriter createWriter(Writer writer,
                                     Map<?,?> options)
                              throws IOException
Creates a new XMLWriter instance for the specified writer, using the serialization options.

Parameters:
writer - the writer where to write XML data.
Returns:
a new XML writer.
Throws:
IOException - if the file could not be opened for write.
Since:
MDWorkbench 3.1.0

createCoreException

public static CoreException createCoreException(SAXException e)
Creates a CoreException based on the specified XML exception.

Parameters:
e - the exception thrown by the XML parser or writer.
Returns:
a new CoreException.