Class XmlUtil


  • public class XmlUtil
    extends java.lang.Object
    Common XML utilities methods.
    Since:
    1.5.7
    Version:
    $Id$
    Author:
    Vincent Siveton
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isXml​(java.io.File f)
      Determines if a given File shall be handled as XML.
      static void prettyFormat​(java.io.InputStream is, java.io.OutputStream os)
      Pretty format the input stream.
      static void prettyFormat​(java.io.InputStream is, java.io.OutputStream os, int indentSize, java.lang.String lineSeparator)
      Pretty format the input stream.
      static void prettyFormat​(java.io.Reader reader, java.io.Writer writer)
      Pretty format the input reader.
      static void prettyFormat​(java.io.Reader reader, java.io.Writer writer, int indentSize, java.lang.String lineSeparator)
      Pretty format the input reader.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_INDENTATION_SIZE

        public static final int DEFAULT_INDENTATION_SIZE
        The default line indenter size i.e. 2.
        See Also:
        Constant Field Values
      • DEFAULT_LINE_SEPARATOR

        public static final java.lang.String DEFAULT_LINE_SEPARATOR
        The default line separator ("\n" on UNIX)
    • Constructor Detail

      • XmlUtil

        public XmlUtil()
    • Method Detail

      • isXml

        public static boolean isXml​(java.io.File f)
        Determines if a given File shall be handled as XML.
        Parameters:
        f - not null file
        Returns:
        true if the given file has XML content, false otherwise.
      • prettyFormat

        public static void prettyFormat​(java.io.Reader reader,
                                        java.io.Writer writer)
                                 throws java.io.IOException
        Pretty format the input reader. For instance, the following input:
         <div><b>content</b></div>
         
        becomes
         <div>
           <b>content</b>
         </div>
         
        Parameters:
        reader - not null
        writer - not null
        Throws:
        java.io.IOException - if any or invalid xml content
        See Also:
        prettyFormat(Reader, Writer, int, String), to read an xml content, to write an xml content
      • prettyFormat

        public static void prettyFormat​(java.io.Reader reader,
                                        java.io.Writer writer,
                                        int indentSize,
                                        java.lang.String lineSeparator)
                                 throws java.io.IOException
        Pretty format the input reader. For instance, the following input:
         <div><b>content</b></div>
         
        becomes
         <div>
           <b>content</b>
         </div>
         
        Parameters:
        reader - not null
        writer - not null
        indentSize - positive number for the indentation
        lineSeparator - the wanted line separator
        Throws:
        java.io.IOException - if any or invalid xml content
        See Also:
        to read an xml content, to write an xml content
      • prettyFormat

        public static void prettyFormat​(java.io.InputStream is,
                                        java.io.OutputStream os)
                                 throws java.io.IOException
        Pretty format the input stream. For instance, the following input:
         <div><b>content</b></div>
         
        becomes
         <div>
           <b>content</b>
         </div>
         
        Parameters:
        is - not null
        os - not null
        Throws:
        java.io.IOException - if any or invalid xml content
        See Also:
        prettyFormat(InputStream, OutputStream, int, String)
      • prettyFormat

        public static void prettyFormat​(java.io.InputStream is,
                                        java.io.OutputStream os,
                                        int indentSize,
                                        java.lang.String lineSeparator)
                                 throws java.io.IOException
        Pretty format the input stream. For instance, the following input:
         <div><b>content</b></div>
         
        becomes
         <div>
           <b>content</b>
         </div>
         
        Parameters:
        is - not null
        os - not null
        indentSize - positive number for the indentation
        lineSeparator - the wanted line separator
        Throws:
        java.io.IOException - if any or invalid xml content