View Javadoc

1   /*
2    * HtmlDumper.java -- Dumps an HTML document tree. 
3    * Copyright (C) 1999 Quiotix Corporation.  
4    *
5    * This program is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License, version 2, as 
7    * published by the Free Software Foundation.  
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License (http://www.gnu.org/copyleft/gpl.txt)
13   * for more details.
14   */
15  
16  package com.quiotix.html.parser;
17  
18  import java.io.OutputStream;
19  import java.io.PrintWriter;
20  
21  /**
22   * Simple HtmlVisitor which dumps out the document to the specified
23   * output stream.
24   *
25   * @author Brian Goetz, Quiotix
26   */
27  
28  public class HtmlDebugDumper extends HtmlVisitor {
29      protected PrintWriter out;
30  
31      /** Constructor. */
32      public HtmlDebugDumper(OutputStream os) {
33          out = new PrintWriter(os);
34      }
35  
36      public void finish() {
37          out.flush();
38      }
39  
40      public void visit(HtmlDocument.Tag t) {
41          out.print("Tag(" + t + ")");
42      }
43  
44      public void visit(HtmlDocument.EndTag t) {
45          out.print("Tag(" + t + ")");
46      }
47  
48      public void visit(HtmlDocument.Comment c) {
49          out.print("Comment(" + c + ")");
50      }
51  
52      public void visit(HtmlDocument.Text t) {
53          out.print(t);
54      }
55  
56      public void visit(HtmlDocument.Newline n) {
57          out.println("-NL-");
58      }
59  
60      public void visit(HtmlDocument.Annotation a) {
61          out.print(a);
62      }
63  
64      public void visit(HtmlDocument.TagBlock bl) {
65          out.print("<BLOCK>");
66          visit(bl.startTag);
67          visit(bl.body);
68          visit(bl.endTag);
69          out.print("</BLOCK>");
70      }
71  
72      /**
73       * Runnable.
74       */
75      public static void main(String[] args) throws ParseException {
76          HtmlParser parser = new HtmlParser(System.in);
77          HtmlDocument doc = parser.HtmlDocument();
78          doc.accept(new HtmlDebugDumper(System.out));
79      }
80  }
81  
82  
83  
84  
85  
86