sbailliez    02/02/08 16:52:09

  Modified:    src/main/org/apache/tools/ant/util DOMElementWriter.java
  Log:
  - Add an helper method to write directly a document
  as UTF8 from a stream.
  
  Revision  Changes    Path
  1.8       +23 -5     
jakarta-ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java
  
  Index: DOMElementWriter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DOMElementWriter.java     10 Jan 2002 11:21:21 -0000      1.7
  +++ DOMElementWriter.java     9 Feb 2002 00:52:09 -0000       1.8
  @@ -56,6 +56,9 @@
   
   import java.io.IOException;
   import java.io.Writer;
  +import java.io.OutputStream;
  +import java.io.OutputStreamWriter;
  +
   import org.w3c.dom.Element;
   import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.Attr;
  @@ -73,7 +76,7 @@
    *
    * @author The original author of XmlLogger
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</tt>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</tt>
    */
   public class DOMElementWriter {
   
  @@ -85,15 +88,30 @@
        * entities.
        */
       protected String[] knownEntities = {"gt", "amp", "lt", "apos", "quot"};
  -    
  +
  +
  +    /**
  +     * Writes a DOM tree to a stream in UTF8 encoding. Note that
  +     * it appends the &lt;?xml version='1.0' encoding='UTF-8'?&gt;.
  +     * The indent number is set to 0 and a 2-space indent.
  +     * @param root the root element of the DOM tree.
  +     * @param out the outputstream to write to.
  +     * @throws IOException if an error happens while writing to the stream.
  +     */
  +    public void write(Element root, OutputStream out) throws IOException {
  +        Writer wri = new OutputStreamWriter(out, "UTF8");
  +        wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  +        write(root, wri, 0, "  ");
  +        wri.flush();
  +    }
  +
       /**
        * Writes a DOM tree to a stream.
  -     *
        * @param element the Root DOM element of the tree
        * @param out where to send the output
        * @param indent number of 
  -     * @param indentWith strings, 
  -     *       that should be used to indent the corresponding tag.
  +     * @param indentWith string that should be used to indent the 
corresponding tag.
  +     * @throws IOException if an error happens while writing to the stream.
        */
       public void write(Element element, Writer out, int indent, 
                         String indentWith)
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to