PageRenderTime 258ms CodeModel.GetById 253ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/sidekick/html/parser/html/HtmlDebugDumper.java

#
Java | 82 lines | 42 code | 20 blank | 20 comment | 0 complexity | db561bd363dfab8a513f306f38d87ddb MD5 | raw file
 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
16package sidekick.html.parser.html;
17
18import java.io.OutputStream;
19import 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
28public class HtmlDebugDumper extends HtmlVisitor {
29    protected PrintWriter out;
30
31    public HtmlDebugDumper(OutputStream os) {
32        out = new PrintWriter(os);
33    }
34
35    public void finish() {
36        out.flush();
37    }
38
39    public void visit(HtmlDocument.Tag t) {
40        out.print("Tag(" + t + ")");
41    }
42
43    public void visit(HtmlDocument.EndTag t) {
44        out.print("Tag(" + t + ")");
45    }
46
47    public void visit(HtmlDocument.Comment c) {
48        out.print("Comment(" + c + ")");
49    }
50
51    public void visit(HtmlDocument.Text t) {
52        out.print(t);
53    }
54
55    public void visit(HtmlDocument.Newline n) {
56        out.println("-NL-");
57    }
58
59    public void visit(HtmlDocument.Annotation a) {
60        out.print(a);
61    }
62
63    public void visit(HtmlDocument.TagBlock bl) {
64        out.print("<BLOCK>");
65        visit(bl.startTag);
66        visit(bl.body);
67        visit(bl.endTag);
68        out.print("</BLOCK>");
69    }
70
71    public static void main(String[] args) throws ParseException {
72        HtmlParser parser = new HtmlParser(System.in);
73        HtmlDocument doc = parser.HtmlDocument();
74        doc.accept(new HtmlDebugDumper(System.out));
75    }
76}
77
78
79
80
81
82