PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 70 lines | 36 code | 14 blank | 20 comment | 0 complexity | 2c0a4e77f4e5ec672b132e51c50317cc 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 sidekick.html.parser.html;
  16. import java.io.OutputStream;
  17. import java.io.OutputStreamWriter;
  18. import java.io.PrintWriter;
  19. import java.io.UnsupportedEncodingException;
  20. /**
  21. * Simple HtmlVisitor which dumps out the document to the specified
  22. * output stream.
  23. *
  24. * @author Brian Goetz, Quiotix
  25. */
  26. public class HtmlDumper extends HtmlVisitor {
  27. protected PrintWriter out;
  28. public HtmlDumper(OutputStream os) {
  29. out = new PrintWriter(os);
  30. }
  31. public HtmlDumper(OutputStream os, String encoding)
  32. throws UnsupportedEncodingException {
  33. out = new PrintWriter(new OutputStreamWriter(os, encoding));
  34. }
  35. public void finish() {
  36. out.flush();
  37. }
  38. public void visit(HtmlDocument.Tag t) {
  39. out.print(t);
  40. }
  41. public void visit(HtmlDocument.EndTag t) {
  42. out.print(t);
  43. }
  44. public void visit(HtmlDocument.Comment c) {
  45. out.print(c);
  46. }
  47. public void visit(HtmlDocument.Text t) {
  48. out.print(t);
  49. }
  50. public void visit(HtmlDocument.Newline n) {
  51. out.println();
  52. }
  53. public void visit(HtmlDocument.Annotation a) {
  54. out.print(a);
  55. }
  56. }