PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package xml.parser.javacc;
  16. import java.io.OutputStream;
  17. import java.io.PrintWriter;
  18. /**
  19. * Simple XmlVisitor which dumps out the document to the specified
  20. * output stream.
  21. *
  22. * @author Brian Goetz, Quiotix
  23. */
  24. public class XmlDebugDumper extends XmlVisitor {
  25. protected PrintWriter out;
  26. public XmlDebugDumper(OutputStream os) {
  27. out = new PrintWriter(os);
  28. }
  29. public void finish() {
  30. out.flush();
  31. }
  32. public void visit(XmlDocument.Tag t) {
  33. out.print("Tag(" + t + ")");
  34. }
  35. public void visit(XmlDocument.EndTag t) {
  36. out.print("Tag(" + t + ")");
  37. }
  38. public void visit(XmlDocument.Comment c) {
  39. out.print("Comment(" + c + ")");
  40. }
  41. public void visit(XmlDocument.Text t) {
  42. out.print(t);
  43. }
  44. public void visit(XmlDocument.Newline n) {
  45. out.println("-NL-");
  46. }
  47. public void visit(XmlDocument.Annotation a) {
  48. out.print(a);
  49. }
  50. public void visit(XmlDocument.TagBlock bl) {
  51. out.print("<BLOCK>");
  52. visit(bl.startTag);
  53. visit(bl.body);
  54. visit(bl.endTag);
  55. out.print("</BLOCK>");
  56. }
  57. public static void main(String[] args) throws ParseException {
  58. XmlParser parser = new XmlParser(System.in);
  59. XmlDocument doc = parser.XmlDocument();
  60. doc.accept(new XmlDebugDumper(System.out));
  61. }
  62. }