KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > xni > parser > XMLInputSource


1 /*
2  * Copyright 2000-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.xni.parser;
18
19 import org.apache.xerces.xni.XMLResourceIdentifier;
20
21 import java.io.InputStream JavaDoc;
22 import java.io.Reader JavaDoc;
23
24 /**
25  * This class represents an input source for an XML document. The
26  * basic properties of an input source are the following:
27  * <ul>
28  * <li>public identifier</li>
29  * <li>system identifier</li>
30  * <li>byte stream or character stream</li>
31  * <li>
32  * </ul>
33  *
34  * @author Andy Clark, IBM
35  *
36  * @version $Id: XMLInputSource.java,v 1.5 2004/02/24 23:15:56 mrglavas Exp $
37  */

38 public class XMLInputSource {
39
40     //
41
// Data
42
//
43

44     /** Public identifier. */
45     protected String JavaDoc fPublicId;
46
47     /** System identifier. */
48     protected String JavaDoc fSystemId;
49
50     /** Base system identifier. */
51     protected String JavaDoc fBaseSystemId;
52
53     /** Byte stream. */
54     protected InputStream JavaDoc fByteStream;
55
56     /** Character stream. */
57     protected Reader JavaDoc fCharStream;
58
59     /** Encoding. */
60     protected String JavaDoc fEncoding;
61
62     //
63
// Constructors
64
//
65

66     /**
67      * Constructs an input source from just the public and system
68      * identifiers, leaving resolution of the entity and opening of
69      * the input stream up to the caller.
70      *
71      * @param publicId The public identifier, if known.
72      * @param systemId The system identifier. This value should
73      * always be set, if possible, and can be
74      * relative or absolute. If the system identifier
75      * is relative, then the base system identifier
76      * should be set.
77      * @param baseSystemId The base system identifier. This value should
78      * always be set to the fully expanded URI of the
79      * base system identifier, if possible.
80      */

81     public XMLInputSource(String JavaDoc publicId, String JavaDoc systemId,
82                           String JavaDoc baseSystemId) {
83         fPublicId = publicId;
84         fSystemId = systemId;
85         fBaseSystemId = baseSystemId;
86     } // <init>(String,String,String)
87

88     /**
89      * Constructs an input source from a XMLResourceIdentifier
90      * object, leaving resolution of the entity and opening of
91      * the input stream up to the caller.
92      *
93      * @param resourceIdentifier the XMLResourceIdentifier containing the information
94      */

95     public XMLInputSource(XMLResourceIdentifier resourceIdentifier) {
96
97         fPublicId = resourceIdentifier.getPublicId();
98         fSystemId = resourceIdentifier.getLiteralSystemId();
99         fBaseSystemId = resourceIdentifier.getBaseSystemId();
100     } // <init>(XMLResourceIdentifier)
101

102     /**
103      * Constructs an input source from a byte stream.
104      *
105      * @param publicId The public identifier, if known.
106      * @param systemId The system identifier. This value should
107      * always be set, if possible, and can be
108      * relative or absolute. If the system identifier
109      * is relative, then the base system identifier
110      * should be set.
111      * @param baseSystemId The base system identifier. This value should
112      * always be set to the fully expanded URI of the
113      * base system identifier, if possible.
114      * @param byteStream The byte stream.
115      * @param encoding The encoding of the byte stream, if known.
116      */

117     public XMLInputSource(String JavaDoc publicId, String JavaDoc systemId,
118                           String JavaDoc baseSystemId, InputStream JavaDoc byteStream,
119                           String JavaDoc encoding) {
120         fPublicId = publicId;
121         fSystemId = systemId;
122         fBaseSystemId = baseSystemId;
123         fByteStream = byteStream;
124         fEncoding = encoding;
125     } // <init>(String,String,String,InputStream,String)
126

127     /**
128      * Constructs an input source from a character stream.
129      *
130      * @param publicId The public identifier, if known.
131      * @param systemId The system identifier. This value should
132      * always be set, if possible, and can be
133      * relative or absolute. If the system identifier
134      * is relative, then the base system identifier
135      * should be set.
136      * @param baseSystemId The base system identifier. This value should
137      * always be set to the fully expanded URI of the
138      * base system identifier, if possible.
139      * @param charStream The character stream.
140      * @param encoding The original encoding of the byte stream
141      * used by the reader, if known.
142      */

143     public XMLInputSource(String JavaDoc publicId, String JavaDoc systemId,
144                           String JavaDoc baseSystemId, Reader JavaDoc charStream,
145                           String JavaDoc encoding) {
146         fPublicId = publicId;
147         fSystemId = systemId;
148         fBaseSystemId = baseSystemId;
149         fCharStream = charStream;
150         fEncoding = encoding;
151     } // <init>(String,String,String,Reader,String)
152

153     //
154
// Public methods
155
//
156

157     /**
158      * Sets the public identifier.
159      *
160      * @param publicId The new public identifier.
161      */

162     public void setPublicId(String JavaDoc publicId) {
163         fPublicId = publicId;
164     } // setPublicId(String)
165

166     /** Returns the public identifier. */
167     public String JavaDoc getPublicId() {
168         return fPublicId;
169     } // getPublicId():String
170

171     /**
172      * Sets the system identifier.
173      *
174      * @param systemId The new system identifier.
175      */

176     public void setSystemId(String JavaDoc systemId) {
177         fSystemId = systemId;
178     } // setSystemId(String)
179

180     /** Returns the system identifier. */
181     public String JavaDoc getSystemId() {
182         return fSystemId;
183     } // getSystemId():String
184

185     /**
186      * Sets the base system identifier.
187      *
188      * @param baseSystemId The new base system identifier.
189      */

190     public void setBaseSystemId(String JavaDoc baseSystemId) {
191         fBaseSystemId = baseSystemId;
192     } // setBaseSystemId(String)
193

194     /** Returns the base system identifier. */
195     public String JavaDoc getBaseSystemId() {
196         return fBaseSystemId;
197     } // getBaseSystemId():String
198

199     /**
200      * Sets the byte stream. If the byte stream is not already opened
201      * when this object is instantiated, then the code that opens the
202      * stream should also set the byte stream on this object. Also, if
203      * the encoding is auto-detected, then the encoding should also be
204      * set on this object.
205      *
206      * @param byteStream The new byte stream.
207      */

208     public void setByteStream(InputStream JavaDoc byteStream) {
209         fByteStream = byteStream;
210     } // setByteStream(InputSource)
211

212     /** Returns the byte stream. */
213     public InputStream JavaDoc getByteStream() {
214         return fByteStream;
215     } // getByteStream():InputStream
216

217     /**
218      * Sets the character stream. If the character stream is not already
219      * opened when this object is instantiated, then the code that opens
220      * the stream should also set the character stream on this object.
221      * Also, the encoding of the byte stream used by the reader should
222      * also be set on this object, if known.
223      *
224      * @param charStream The new character stream.
225      *
226      * @see #setEncoding
227      */

228     public void setCharacterStream(Reader JavaDoc charStream) {
229         fCharStream = charStream;
230     } // setCharacterStream(Reader)
231

232     /** Returns the character stream. */
233     public Reader JavaDoc getCharacterStream() {
234         return fCharStream;
235     } // getCharacterStream():Reader
236

237     /**
238      * Sets the encoding of the stream.
239      *
240      * @param encoding The new encoding.
241      */

242     public void setEncoding(String JavaDoc encoding) {
243         fEncoding = encoding;
244     } // setEncoding(String)
245

246     /** Returns the encoding of the stream, or null if not known. */
247     public String JavaDoc getEncoding() {
248         return fEncoding;
249     } // getEncoding():String
250

251 } // class XMLInputSource
252
Popular Tags