You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2004/06/22 16:57:19 UTC

cvs commit: xml-xindice/java/src/org/apache/xindice/server UglyBrowser.java

vgritsenko    2004/06/22 07:57:19

  Modified:    java/src/org/apache/xindice/server UglyBrowser.java
  Log:
  Add pretty print of XML docs to the UglyBrowser.
  Thanks to Gary Orser.
  
  Revision  Changes    Path
  1.14      +21 -6     xml-xindice/java/src/org/apache/xindice/server/UglyBrowser.java
  
  Index: UglyBrowser.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/server/UglyBrowser.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- UglyBrowser.java	11 Feb 2004 14:03:09 -0000	1.13
  +++ UglyBrowser.java	22 Jun 2004 14:57:19 -0000	1.14
  @@ -25,7 +25,11 @@
   import org.apache.xindice.core.Database;
   import org.apache.xindice.xml.TextWriter;
   
  +import org.apache.xml.serialize.XMLSerializer;
  +import org.apache.xml.serialize.OutputFormat;
   import org.w3c.dom.Document;
  +import java.io.ByteArrayOutputStream;
  +
   
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
  @@ -187,13 +191,24 @@
           }
   
           return "Document '" + document + "'<p>\n"
  -            + escapeHtml(TextWriter.toString(doc));
  +            + "<pre>" + escapeHtml(prettyPrint(doc)) + "</pre>";
  +    }
  +
  +    protected static String prettyPrint(Document doc) throws Exception {
  +        ByteArrayOutputStream out = new ByteArrayOutputStream();
  +        OutputFormat format = new OutputFormat(doc);
  +        format.setLineWidth(65);
  +        format.setIndenting(true);
  +        format.setIndent(2);
  +        XMLSerializer serializer = new XMLSerializer(out, format);
  +        serializer.serialize(doc);
  +        return out.toString();
       }
   
       /* simple function to escape the xml stuff that'll
        * not be displayed correctly in html.
        */
  -    static public String escapeHtml(String value) {
  +    protected static String escapeHtml(String value) {
           StringBuffer buf = new StringBuffer();
           for (int i = 0; i < value.length(); i++) {
               char c = value.charAt(i);
  @@ -230,7 +245,7 @@
       /**
        * Is the given character allowed inside an HTML document?
        */
  -    static public boolean isLegalCharacter(char c) {
  +    protected static boolean isLegalCharacter(char c) {
           return (c > 0x07) && (c < 0x80);
       }