19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id:  $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.serializer.dom3;
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.ls.LSOutput;
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.Writer;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.OutputStream;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This is a copy of the Xerces-2J class org.apache.xerces.dom.DOMOutputImpl.java
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This class represents an output destination for data.
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This interface allows an application to encapsulate information about an
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * output destination in a single object, which may include a URI, a byte stream
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (possibly with a specifiedencoding), a base URI, and/or a character stream.
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The exact definitions of a byte stream and a character stream are binding
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * dependent.
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The application is expected to provide objects that implement this interface
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * whenever such objects are needed. The application can either provide its
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * own objects that implement this interface, or it can use the generic factory
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method DOMImplementationLS.createLSOutput() to create objects that
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * implement this interface.
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The DOMSerializer will use the LSOutput object to determine where to
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * serialize the output to. The DOMSerializer will look at the different
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * outputs specified in the LSOutput in the following order to know which one
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to output to, the first one that data can be output to will be used:
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1.LSOutput.characterStream
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2.LSOutput.byteStream
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3.LSOutput.systemId
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * LSOutput objects belong to the application. The DOM implementation will
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * never modify them (though it may make copies and modify the copies,
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if necessary).
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @author Arun Yadav, Sun Microsytems
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @author Gopal Sharma, Sun Microsystems
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @version $Id :
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonfinal class DOMOutputImpl implements LSOutput {
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private Writer fCharStream = null;
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private OutputStream fByteStream = null;
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private String fSystemId = null;
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private String fEncoding = null;
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Default Constructor
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    DOMOutputImpl() {}
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * An attribute of a language and binding dependent type that represents a
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * writable stream of bytes. If the application knows the character encoding
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * of the byte stream, it should set the encoding attribute. Setting the
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * encoding in this way will override any encoding specified in an XML
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * declaration in the data.
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public Writer getCharacterStream(){
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return fCharStream;
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * An attribute of a language and binding dependent type that represents a
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * writable stream of bytes. If the application knows the character encoding
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * of the byte stream, it should set the encoding attribute. Setting the
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * encoding in this way will override any encoding specified in an XML
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * declaration in the data.
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public void setCharacterStream(Writer characterStream){
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        fCharStream = characterStream;
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Depending on the language binding in use, this attribute may not be
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * available. An attribute of a language and binding dependent type that
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * represents a writable stream to which 16-bit units can be output. The
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * application must encode the stream using UTF-16 (defined in [Unicode] and
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  Amendment 1 of [ISO/IEC 10646]).
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public OutputStream getByteStream(){
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return fByteStream;
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Depending on the language binding in use, this attribute may not be
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * available. An attribute of a language and binding dependent type that
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * represents a writable stream to which 16-bit units can be output. The
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * application must encode the stream using UTF-16 (defined in [Unicode] and
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  Amendment 1 of [ISO/IEC 10646]).
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public void setByteStream(OutputStream byteStream){
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        fByteStream = byteStream;
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The system identifier, a URI reference [IETF RFC 2396], for this output
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  destination. If the application knows the character encoding of the
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  object pointed to by the system identifier, it can set the encoding
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  using the encoding attribute. If the system ID is a relative URI
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  reference (see section 5 in [IETF RFC 2396]), the behavior is
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  implementation dependent.
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public String getSystemId(){
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return fSystemId;
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The system identifier, a URI reference [IETF RFC 2396], for this output
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  destination. If the application knows the character encoding of the
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  object pointed to by the system identifier, it can set the encoding
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  using the encoding attribute. If the system ID is a relative URI
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  reference (see section 5 in [IETF RFC 2396]), the behavior is
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  implementation dependent.
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public void setSystemId(String systemId){
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        fSystemId = systemId;
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The character encoding, if known. The encoding must be a string
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * "Character Encoding in Entities"). This attribute has no effect when the
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * application provides a character stream or string data. For other sources
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * of input, an encoding specified by means of this attribute will override
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * any encoding specified in the XML declaration or the Text declaration, or
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * an encoding obtained from a higher level protocol, such as HTTP
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * [IETF RFC 2616].
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public String getEncoding(){
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return fEncoding;
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The character encoding, if known. The encoding must be a string
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * "Character Encoding in Entities"). This attribute has no effect when the
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * application provides a character stream or string data. For other sources
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * of input, an encoding specified by means of this attribute will override
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * any encoding specified in the XML declaration or the Text declaration, or
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * an encoding obtained from a higher level protocol, such as HTTP
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * [IETF RFC 2616].
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public void setEncoding(String encoding){
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        fEncoding = encoding;
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    };
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}//DOMOutputImpl
178