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