You are viewing a plain text version of this content. The canonical link for it is here.
Posted to crimson-cvs@xml.apache.org by ed...@apache.org on 2001/01/18 21:32:57 UTC

cvs commit: xml-crimson/examples/DOMEcho DOMEcho.java

edwingo     01/01/18 12:32:56

  Modified:    examples/DOMEcho DOMEcho.java
  Log:
  Use PrintWriter-s so output can be printed in UTF-8.
  
  Revision  Changes    Path
  1.2       +17 -8     xml-crimson/examples/DOMEcho/DOMEcho.java
  
  Index: DOMEcho.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/examples/DOMEcho/DOMEcho.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DOMEcho.java	2000/11/23 01:53:40	1.1
  +++ DOMEcho.java	2001/01/18 20:32:54	1.2
  @@ -61,8 +61,9 @@
   import org.w3c.dom.*;
   
   import java.io.IOException;
  -import java.io.PrintStream;
  +import java.io.PrintWriter;
   import java.io.File;
  +import java.io.*;
   
   
   /**
  @@ -80,8 +81,11 @@
    * @author Edwin Goei <ed...@apache.org>
    */
   public class DOMEcho {
  +    /** All output will be use this encoding */
  +    static final String outputEncoding = "UTF-8";
  +
       /** Output goes here */
  -    private PrintStream out;
  +    private PrintWriter out;
   
       /** Indent level */
       private int indent = 0;
  @@ -89,7 +93,7 @@
       /** Indentation will be in multiples of basicIndent  */
       private final String basicIndent = "  ";
   
  -    DOMEcho(PrintStream out) {
  +    DOMEcho(PrintWriter out) {
           this.out = out;
       }
   
  @@ -240,7 +244,7 @@
           System.exit(1);
       }
   
  -    public static void main(String[] args) {
  +    public static void main(String[] args) throws Exception {
           String filename = null;
           boolean validation = false;
   
  @@ -300,7 +304,10 @@
           }
   
           // Set an ErrorHandler before parsing
  -        db.setErrorHandler(new MyErrorHandler(System.err));
  +        OutputStreamWriter errorWriter =
  +            new OutputStreamWriter(System.err, outputEncoding);
  +        db.setErrorHandler(
  +            new MyErrorHandler(new PrintWriter(errorWriter, true)));
   
           // Step 3: parse the input file
           Document doc = null;
  @@ -315,15 +322,17 @@
           }
   
           // Print out the DOM tree
  -        new DOMEcho(System.out).echo(doc);
  +        OutputStreamWriter outWriter =
  +            new OutputStreamWriter(System.out, outputEncoding);
  +        new DOMEcho(new PrintWriter(outWriter, true)).echo(doc);
       }
   
       // Error handler to report errors and warnings
       private static class MyErrorHandler implements ErrorHandler {
           /** Error handler output goes here */
  -        private PrintStream out;
  +        private PrintWriter out;
   
  -        MyErrorHandler(PrintStream out) {
  +        MyErrorHandler(PrintWriter out) {
               this.out = out;
           }