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.OutputStreamWriter;
20  import java.io.PrintWriter;
21  import java.io.UnsupportedEncodingException;
22  
23  /**
24   * Simple HtmlVisitor which dumps out the document to the specified
25   * output stream.
26   *
27   * @author Brian Goetz, Quiotix
28   */
29  
30  public class HtmlDumper extends HtmlVisitor {
31      protected PrintWriter out;
32  
33      /** Constructor. */
34      public HtmlDumper(OutputStream os) {
35          out = new PrintWriter(os);
36      }
37  
38      /** Constructor. */
39      public HtmlDumper(OutputStream os, String encoding)
40              throws UnsupportedEncodingException {
41          out = new PrintWriter(new OutputStreamWriter(os, encoding));
42      }
43  
44      public void finish() {
45          out.flush();
46      }
47  
48      public void visit(HtmlDocument.Tag t) {
49          out.print(t);
50      }
51  
52      public void visit(HtmlDocument.EndTag t) {
53          out.print(t);
54      }
55  
56      public void visit(HtmlDocument.Comment c) {
57          out.print(c);
58      }
59  
60      public void visit(HtmlDocument.Text t) {
61          out.print(t);
62      }
63  
64      public void visit(HtmlDocument.Newline n) {
65          out.println();
66      }
67  
68      public void visit(HtmlDocument.Annotation a) {
69          out.print(a);
70      }
71  }
72