1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001, 2002 The Apache Software Foundation.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 2001, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.dom;
  58. import org.w3c.dom.ls.LSOutput;
  59. import java.io.Writer;
  60. import java.io.OutputStream;
  61. /**
  62. * This class represents an output destination for data.
  63. * This interface allows an application to encapsulate information about an
  64. * output destination in a single object, which may include a URI, a byte stream
  65. * (possibly with a specifiedencoding), a base URI, and/or a character stream.
  66. * The exact definitions of a byte stream and a character stream are binding
  67. * dependent.
  68. * The application is expected to provide objects that implement this interface
  69. * whenever such objects are needed. The application can either provide its
  70. * own objects that implement this interface, or it can use the generic factory
  71. * method DOMImplementationLS.createLSOutput() to create objects that
  72. * implement this interface.
  73. * The DOMSerializer will use the LSOutput object to determine where to
  74. * serialize the output to. The DOMSerializer will look at the different
  75. * outputs specified in the LSOutput in the following order to know which one
  76. * to output to, the first one that data can be output to will be used:
  77. * 1.LSOutput.characterStream
  78. * 2.LSOutput.byteStream
  79. * 3.LSOutput.systemId
  80. * LSOutput objects belong to the application. The DOM implementation will
  81. * never modify them (though it may make copies and modify the copies,
  82. * if necessary).
  83. *
  84. *
  85. * @author Arun Yadav, Sun Microsytems
  86. * @author Gopal Sharma, Sun Microsystems
  87. **/
  88. public class DOMOutputImpl implements LSOutput {
  89. protected Writer fCharStream = null;
  90. protected OutputStream fByteStream = null;
  91. protected String fSystemId = null;
  92. protected String fEncoding = null;
  93. /**
  94. * Default Constructor
  95. */
  96. public DOMOutputImpl() {}
  97. /**
  98. * An attribute of a language and binding dependent type that represents a
  99. * writable stream of bytes. If the application knows the character encoding
  100. * of the byte stream, it should set the encoding attribute. Setting the
  101. * encoding in this way will override any encoding specified in an XML
  102. * declaration in the data.
  103. */
  104. public Writer getCharacterStream(){
  105. return fCharStream;
  106. };
  107. /**
  108. * An attribute of a language and binding dependent type that represents a
  109. * writable stream of bytes. If the application knows the character encoding
  110. * of the byte stream, it should set the encoding attribute. Setting the
  111. * encoding in this way will override any encoding specified in an XML
  112. * declaration in the data.
  113. */
  114. public void setCharacterStream(Writer characterStream){
  115. fCharStream = characterStream;
  116. };
  117. /**
  118. * Depending on the language binding in use, this attribute may not be
  119. * available. An attribute of a language and binding dependent type that
  120. * represents a writable stream to which 16-bit units can be output. The
  121. * application must encode the stream using UTF-16 (defined in [Unicode] and
  122. * Amendment 1 of [ISO/IEC 10646]).
  123. */
  124. public OutputStream getByteStream(){
  125. return fByteStream;
  126. };
  127. /**
  128. * Depending on the language binding in use, this attribute may not be
  129. * available. An attribute of a language and binding dependent type that
  130. * represents a writable stream to which 16-bit units can be output. The
  131. * application must encode the stream using UTF-16 (defined in [Unicode] and
  132. * Amendment 1 of [ISO/IEC 10646]).
  133. */
  134. public void setByteStream(OutputStream byteStream){
  135. fByteStream = byteStream;
  136. };
  137. /**
  138. * The system identifier, a URI reference [IETF RFC 2396], for this output
  139. * destination. If the application knows the character encoding of the
  140. * object pointed to by the system identifier, it can set the encoding
  141. * using the encoding attribute. If the system ID is a relative URI
  142. * reference (see section 5 in [IETF RFC 2396]), the behavior is
  143. * implementation dependent.
  144. */
  145. public String getSystemId(){
  146. return fSystemId;
  147. };
  148. /**
  149. * The system identifier, a URI reference [IETF RFC 2396], for this output
  150. * destination. If the application knows the character encoding of the
  151. * object pointed to by the system identifier, it can set the encoding
  152. * using the encoding attribute. If the system ID is a relative URI
  153. * reference (see section 5 in [IETF RFC 2396]), the behavior is
  154. * implementation dependent.
  155. */
  156. public void setSystemId(String systemId){
  157. fSystemId = systemId;
  158. };
  159. /**
  160. * The character encoding, if known. The encoding must be a string
  161. * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
  162. * "Character Encoding in Entities"). This attribute has no effect when the
  163. * application provides a character stream or string data. For other sources
  164. * of input, an encoding specified by means of this attribute will override
  165. * any encoding specified in the XML declaration or the Text declaration, or
  166. * an encoding obtained from a higher level protocol, such as HTTP
  167. * [IETF RFC 2616].
  168. */
  169. public String getEncoding(){
  170. return fEncoding;
  171. };
  172. /**
  173. * The character encoding, if known. The encoding must be a string
  174. * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
  175. * "Character Encoding in Entities"). This attribute has no effect when the
  176. * application provides a character stream or string data. For other sources
  177. * of input, an encoding specified by means of this attribute will override
  178. * any encoding specified in the XML declaration or the Text declaration, or
  179. * an encoding obtained from a higher level protocol, such as HTTP
  180. * [IETF RFC 2616].
  181. */
  182. public void setEncoding(String encoding){
  183. fEncoding = encoding;
  184. };
  185. }//DOMOutputImpl