XHTMLWriter.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* XHTMLWriter.java --
  2. Copyright (C) 1999,2000,2001 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.xml.util;
  32. import java.io.IOException;
  33. import java.io.OutputStream;
  34. import java.io.OutputStreamWriter;
  35. import java.io.Writer;
  36. /**
  37. * This extends XMLWriter to create a class which defaults to writing
  38. * XHTML text, preferring the US-ASCII encoding. It adds no unique
  39. * functionality, only changing the defaults slightly to simplify writing
  40. * XHTML processing components by providing a bean class whose properties
  41. * have more convenient defaults. An artifact of using the US-ASCII
  42. * encoding is that no XML declaration is written, so that HTML tools
  43. * that can't accept them will not become confused. Components can treat
  44. * the output as UTF-8, ISO-8859-1, or US-ASCII without incurring any
  45. * data loss.
  46. *
  47. * @author David Brownell
  48. *
  49. * @deprecated Please use the javax.xml.stream APIs instead
  50. */
  51. public class XHTMLWriter extends XMLWriter
  52. {
  53. /**
  54. * Constructs this handler with System.out used to write
  55. * SAX events using the US-ASCII encoding, as XHTML.
  56. */
  57. public XHTMLWriter ()
  58. throws IOException
  59. {
  60. this (System.out);
  61. }
  62. /**
  63. * Constructs this handler such that the specified output stream
  64. * is used to write SAX events in the US-ASCII encoding, as XHTML.
  65. *
  66. * @param out Where US-ASCII encoding of the stream of SAX
  67. * events will be sent.
  68. */
  69. public XHTMLWriter (OutputStream out)
  70. throws IOException
  71. {
  72. // not all JVMs understand "ASCII" as an encoding name, so
  73. // we use 8859_1 (they all seem to handle that one) and
  74. // make the echo handler filter out non-ASCII characters
  75. this (new OutputStreamWriter (out, "8859_1"), "US-ASCII");
  76. }
  77. /**
  78. * Constructs this handler such that the specified output stream
  79. * is used to write SAX events as XHTML.
  80. *
  81. * @param out Where the stream of SAX events will be written.
  82. */
  83. public XHTMLWriter (Writer out)
  84. {
  85. this (out, null);
  86. }
  87. /**
  88. * Constructs this handler such that the specified output stream
  89. * is used to write SAX events as XHTML, labeled with the specified
  90. * encoding.
  91. *
  92. * @param out Where the stream of SAX events will be written.
  93. * @param encoding If non-null, this names the encoding to be
  94. * placed in the encoding declaration.
  95. */
  96. public XHTMLWriter (Writer out, String encoding)
  97. {
  98. super (out, encoding);
  99. setXhtml (true);
  100. }
  101. }