001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.dom;
019:
020: import org.w3c.dom.ls.LSOutput;
021:
022: import java.io.Writer;
023: import java.io.OutputStream;
024:
025: /**
026: * This class represents an output destination for data.
027: * This interface allows an application to encapsulate information about an
028: * output destination in a single object, which may include a URI, a byte stream
029: * (possibly with a specifiedencoding), a base URI, and/or a character stream.
030: * The exact definitions of a byte stream and a character stream are binding
031: * dependent.
032: * The application is expected to provide objects that implement this interface
033: * whenever such objects are needed. The application can either provide its
034: * own objects that implement this interface, or it can use the generic factory
035: * method DOMImplementationLS.createLSOutput() to create objects that
036: * implement this interface.
037: * The DOMSerializer will use the LSOutput object to determine where to
038: * serialize the output to. The DOMSerializer will look at the different
039: * outputs specified in the LSOutput in the following order to know which one
040: * to output to, the first one that data can be output to will be used:
041: * 1.LSOutput.characterStream
042: * 2.LSOutput.byteStream
043: * 3.LSOutput.systemId
044: * LSOutput objects belong to the application. The DOM implementation will
045: * never modify them (though it may make copies and modify the copies,
046: * if necessary).
047: *
048: * @xerces.internal
049: *
050: * @author Arun Yadav, Sun Microsytems
051: * @author Gopal Sharma, Sun Microsystems
052: **/
053:
054: public class DOMOutputImpl implements LSOutput {
055:
056: protected Writer fCharStream = null;
057: protected OutputStream fByteStream = null;
058: protected String fSystemId = null;
059: protected String fEncoding = null;
060:
061: /**
062: * Default Constructor
063: */
064: public DOMOutputImpl() {
065: }
066:
067: /**
068: * An attribute of a language and binding dependent type that represents a
069: * writable stream of bytes. If the application knows the character encoding
070: * of the byte stream, it should set the encoding attribute. Setting the
071: * encoding in this way will override any encoding specified in an XML
072: * declaration in the data.
073: */
074:
075: public Writer getCharacterStream() {
076: return fCharStream;
077: };
078:
079: /**
080: * An attribute of a language and binding dependent type that represents a
081: * writable stream of bytes. If the application knows the character encoding
082: * of the byte stream, it should set the encoding attribute. Setting the
083: * encoding in this way will override any encoding specified in an XML
084: * declaration in the data.
085: */
086:
087: public void setCharacterStream(Writer characterStream) {
088: fCharStream = characterStream;
089: };
090:
091: /**
092: * Depending on the language binding in use, this attribute may not be
093: * available. An attribute of a language and binding dependent type that
094: * represents a writable stream to which 16-bit units can be output. The
095: * application must encode the stream using UTF-16 (defined in [Unicode] and
096: * Amendment 1 of [ISO/IEC 10646]).
097: */
098:
099: public OutputStream getByteStream() {
100: return fByteStream;
101: };
102:
103: /**
104: * Depending on the language binding in use, this attribute may not be
105: * available. An attribute of a language and binding dependent type that
106: * represents a writable stream to which 16-bit units can be output. The
107: * application must encode the stream using UTF-16 (defined in [Unicode] and
108: * Amendment 1 of [ISO/IEC 10646]).
109: */
110:
111: public void setByteStream(OutputStream byteStream) {
112: fByteStream = byteStream;
113: };
114:
115: /**
116: * The system identifier, a URI reference [IETF RFC 2396], for this output
117: * destination. If the application knows the character encoding of the
118: * object pointed to by the system identifier, it can set the encoding
119: * using the encoding attribute. If the system ID is a relative URI
120: * reference (see section 5 in [IETF RFC 2396]), the behavior is
121: * implementation dependent.
122: */
123:
124: public String getSystemId() {
125: return fSystemId;
126: };
127:
128: /**
129: * The system identifier, a URI reference [IETF RFC 2396], for this output
130: * destination. If the application knows the character encoding of the
131: * object pointed to by the system identifier, it can set the encoding
132: * using the encoding attribute. If the system ID is a relative URI
133: * reference (see section 5 in [IETF RFC 2396]), the behavior is
134: * implementation dependent.
135: */
136:
137: public void setSystemId(String systemId) {
138: fSystemId = systemId;
139: };
140:
141: /**
142: * The character encoding, if known. The encoding must be a string
143: * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
144: * "Character Encoding in Entities"). This attribute has no effect when the
145: * application provides a character stream or string data. For other sources
146: * of input, an encoding specified by means of this attribute will override
147: * any encoding specified in the XML declaration or the Text declaration, or
148: * an encoding obtained from a higher level protocol, such as HTTP
149: * [IETF RFC 2616].
150: */
151:
152: public String getEncoding() {
153: return fEncoding;
154: };
155:
156: /**
157: * The character encoding, if known. The encoding must be a string
158: * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
159: * "Character Encoding in Entities"). This attribute has no effect when the
160: * application provides a character stream or string data. For other sources
161: * of input, an encoding specified by means of this attribute will override
162: * any encoding specified in the XML declaration or the Text declaration, or
163: * an encoding obtained from a higher level protocol, such as HTTP
164: * [IETF RFC 2616].
165: */
166:
167: public void setEncoding(String encoding) {
168: fEncoding = encoding;
169: };
170:
171: }//DOMOutputImpl
|