View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2000-2002,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.xni.parser;
22  
23  import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
24  
25  import java.io.InputStream;
26  import java.io.Reader;
27  
28  /**
29   * This class represents an input source for an XML document. The
30   * basic properties of an input source are the following:
31   * <ul>
32   *  <li>public identifier</li>
33   *  <li>system identifier</li>
34   *  <li>byte stream or character stream</li>
35   *  <li>
36   * </ul>
37   *
38   * @author Andy Clark, IBM
39   *
40   */
41  public class XMLInputSource {
42  
43      //
44      // Data
45      //
46  
47      /** Public identifier. */
48      protected String fPublicId;
49  
50      /** System identifier. */
51      protected String fSystemId;
52  
53      /** Base system identifier. */
54      protected String fBaseSystemId;
55  
56      /** Byte stream. */
57      protected InputStream fByteStream;
58  
59      /** Character stream. */
60      protected Reader fCharStream;
61  
62      /** Encoding. */
63      protected String fEncoding;
64  
65      //
66      // Constructors
67      //
68  
69      /**
70       * Constructs an input source from just the public and system
71       * identifiers, leaving resolution of the entity and opening of
72       * the input stream up to the caller.
73       *
74       * @param publicId     The public identifier, if known.
75       * @param systemId     The system identifier. This value should
76       *                     always be set, if possible, and can be
77       *                     relative or absolute. If the system identifier
78       *                     is relative, then the base system identifier
79       *                     should be set.
80       * @param baseSystemId The base system identifier. This value should
81       *                     always be set to the fully expanded URI of the
82       *                     base system identifier, if possible.
83       */
84      public XMLInputSource(String publicId, String systemId,
85                            String baseSystemId) {
86          fPublicId = publicId;
87          fSystemId = systemId;
88          fBaseSystemId = baseSystemId;
89      } // <init>(String,String,String)
90  
91      /**
92       * Constructs an input source from a XMLResourceIdentifier
93       * object, leaving resolution of the entity and opening of
94       * the input stream up to the caller.
95       *
96       * @param resourceIdentifier    the XMLResourceIdentifier containing the information
97       */
98      public XMLInputSource(XMLResourceIdentifier resourceIdentifier) {
99  
100         fPublicId = resourceIdentifier.getPublicId();
101         fSystemId = resourceIdentifier.getLiteralSystemId();
102         fBaseSystemId = resourceIdentifier.getBaseSystemId();
103     } // <init>(XMLResourceIdentifier)
104 
105     /**
106      * Constructs an input source from a byte stream.
107      *
108      * @param publicId     The public identifier, if known.
109      * @param systemId     The system identifier. This value should
110      *                     always be set, if possible, and can be
111      *                     relative or absolute. If the system identifier
112      *                     is relative, then the base system identifier
113      *                     should be set.
114      * @param baseSystemId The base system identifier. This value should
115      *                     always be set to the fully expanded URI of the
116      *                     base system identifier, if possible.
117      * @param byteStream   The byte stream.
118      * @param encoding     The encoding of the byte stream, if known.
119      */
120     public XMLInputSource(String publicId, String systemId,
121                           String baseSystemId, InputStream byteStream,
122                           String encoding) {
123         fPublicId = publicId;
124         fSystemId = systemId;
125         fBaseSystemId = baseSystemId;
126         fByteStream = byteStream;
127         fEncoding = encoding;
128     } // <init>(String,String,String,InputStream,String)
129 
130     /**
131      * Constructs an input source from a character stream.
132      *
133      * @param publicId     The public identifier, if known.
134      * @param systemId     The system identifier. This value should
135      *                     always be set, if possible, and can be
136      *                     relative or absolute. If the system identifier
137      *                     is relative, then the base system identifier
138      *                     should be set.
139      * @param baseSystemId The base system identifier. This value should
140      *                     always be set to the fully expanded URI of the
141      *                     base system identifier, if possible.
142      * @param charStream   The character stream.
143      * @param encoding     The original encoding of the byte stream
144      *                     used by the reader, if known.
145      */
146     public XMLInputSource(String publicId, String systemId,
147                           String baseSystemId, Reader charStream,
148                           String encoding) {
149         fPublicId = publicId;
150         fSystemId = systemId;
151         fBaseSystemId = baseSystemId;
152         fCharStream = charStream;
153         fEncoding = encoding;
154     } // <init>(String,String,String,Reader,String)
155 
156     //
157     // Public methods
158     //
159 
160     /**
161      * Sets the public identifier.
162      *
163      * @param publicId The new public identifier.
164      */
165     public void setPublicId(String publicId) {
166         fPublicId = publicId;
167     } // setPublicId(String)
168 
169     /** Returns the public identifier. */
170     public String getPublicId() {
171         return fPublicId;
172     } // getPublicId():String
173 
174     /**
175      * Sets the system identifier.
176      *
177      * @param systemId The new system identifier.
178      */
179     public void setSystemId(String systemId) {
180         fSystemId = systemId;
181     } // setSystemId(String)
182 
183     /** Returns the system identifier. */
184     public String getSystemId() {
185         return fSystemId;
186     } // getSystemId():String
187 
188     /**
189      * Sets the base system identifier.
190      *
191      * @param baseSystemId The new base system identifier.
192      */
193     public void setBaseSystemId(String baseSystemId) {
194         fBaseSystemId = baseSystemId;
195     } // setBaseSystemId(String)
196 
197     /** Returns the base system identifier. */
198     public String getBaseSystemId() {
199         return fBaseSystemId;
200     } // getBaseSystemId():String
201 
202     /**
203      * Sets the byte stream. If the byte stream is not already opened
204      * when this object is instantiated, then the code that opens the
205      * stream should also set the byte stream on this object. Also, if
206      * the encoding is auto-detected, then the encoding should also be
207      * set on this object.
208      *
209      * @param byteStream The new byte stream.
210      */
211     public void setByteStream(InputStream byteStream) {
212         fByteStream = byteStream;
213     } // setByteStream(InputSource)
214 
215     /** Returns the byte stream. */
216     public InputStream getByteStream() {
217         return fByteStream;
218     } // getByteStream():InputStream
219 
220     /**
221      * Sets the character stream. If the character stream is not already
222      * opened when this object is instantiated, then the code that opens
223      * the stream should also set the character stream on this object.
224      * Also, the encoding of the byte stream used by the reader should
225      * also be set on this object, if known.
226      *
227      * @param charStream The new character stream.
228      *
229      * @see #setEncoding
230      */
231     public void setCharacterStream(Reader charStream) {
232         fCharStream = charStream;
233     } // setCharacterStream(Reader)
234 
235     /** Returns the character stream. */
236     public Reader getCharacterStream() {
237         return fCharStream;
238     } // getCharacterStream():Reader
239 
240     /**
241      * Sets the encoding of the stream.
242      *
243      * @param encoding The new encoding.
244      */
245     public void setEncoding(String encoding) {
246         fEncoding = encoding;
247     } // setEncoding(String)
248 
249     /** Returns the encoding of the stream, or null if not known. */
250     public String getEncoding() {
251         return fEncoding;
252     } // getEncoding():String
253 
254 } // class XMLInputSource