PageRenderTime 47ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/xml/parser/javacc/XmlDebugDumper.java

#
Java | 82 lines | 42 code | 20 blank | 20 comment | 0 complexity | b2faa9ea87bf4d55ad4581f6c3ea34a4 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 xml.parser.javacc;
17
18import java.io.OutputStream;
19import java.io.PrintWriter;
20
21/**
22 * Simple XmlVisitor which dumps out the document to the specified
23 * output stream.
24 *
25 * @author Brian Goetz, Quiotix
26 */
27
28public class XmlDebugDumper extends XmlVisitor {
29    protected PrintWriter out;
30
31    public XmlDebugDumper(OutputStream os) {
32        out = new PrintWriter(os);
33    }
34
35    public void finish() {
36        out.flush();
37    }
38
39    public void visit(XmlDocument.Tag t) {
40        out.print("Tag(" + t + ")");
41    }
42
43    public void visit(XmlDocument.EndTag t) {
44        out.print("Tag(" + t + ")");
45    }
46
47    public void visit(XmlDocument.Comment c) {
48        out.print("Comment(" + c + ")");
49    }
50
51    public void visit(XmlDocument.Text t) {
52        out.print(t);
53    }
54
55    public void visit(XmlDocument.Newline n) {
56        out.println("-NL-");
57    }
58
59    public void visit(XmlDocument.Annotation a) {
60        out.print(a);
61    }
62
63    public void visit(XmlDocument.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        XmlParser parser = new XmlParser(System.in);
73        XmlDocument doc = parser.XmlDocument();
74        doc.accept(new XmlDebugDumper(System.out));
75    }
76}
77
78
79
80
81
82