KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > xni > parser > XMLInputSource


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.xni.parser;
59
60 import com.sun.org.apache.xerces.internal.util.XMLInputSourceAdaptor;
61 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
62
63 import java.io.InputStream JavaDoc;
64 import java.io.Reader JavaDoc;
65
66 import javax.xml.transform.stream.StreamSource JavaDoc;
67
68 /**
69  * This class represents an input source for an XML document. The
70  * basic properties of an input source are the following:
71  * <ul>
72  * <li>public identifier</li>
73  * <li>system identifier</li>
74  * <li>byte stream or character stream</li>
75  * <li>
76  * </ul>
77  *
78  * @author Andy Clark, IBM
79  *
80  * @version $Id: XMLInputSource.java,v 1.4 2002/01/29 01:15:19 lehors Exp $
81  */

82 public class XMLInputSource {
83
84     //
85
// Data
86
//
87

88     /** Public identifier. */
89     protected String JavaDoc fPublicId;
90
91     /** System identifier. */
92     protected String JavaDoc fSystemId;
93
94     /** Base system identifier. */
95     protected String JavaDoc fBaseSystemId;
96
97     /** Byte stream. */
98     protected InputStream JavaDoc fByteStream;
99
100     /** Character stream. */
101     protected Reader JavaDoc fCharStream;
102
103     /** Encoding. */
104     protected String JavaDoc fEncoding;
105
106     //
107
// Constructors
108
//
109

110     /**
111      * Constructs an input source from just the public and system
112      * identifiers, leaving resolution of the entity and opening of
113      * the input stream up to the caller.
114      *
115      * @param publicId The public identifier, if known.
116      * @param systemId The system identifier. This value should
117      * always be set, if possible, and can be
118      * relative or absolute. If the system identifier
119      * is relative, then the base system identifier
120      * should be set.
121      * @param baseSystemId The base system identifier. This value should
122      * always be set to the fully expanded URI of the
123      * base system identifier, if possible.
124      */

125     public XMLInputSource(String JavaDoc publicId, String JavaDoc systemId,
126                           String JavaDoc baseSystemId) {
127         fPublicId = publicId;
128         fSystemId = systemId;
129         fBaseSystemId = baseSystemId;
130     } // <init>(String,String,String)
131

132     /**
133      * Constructs an input source from a XMLResourceIdentifier
134      * object, leaving resolution of the entity and opening of
135      * the input stream up to the caller.
136      *
137      * @param resourceIdentifier the XMLResourceIdentifier containing the information
138      */

139     public XMLInputSource(XMLResourceIdentifier resourceIdentifier) {
140
141         fPublicId = resourceIdentifier.getPublicId();
142         fSystemId = resourceIdentifier.getLiteralSystemId();
143         fBaseSystemId = resourceIdentifier.getBaseSystemId();
144     } // <init>(XMLResourceIdentifier)
145

146     /**
147      * Constructs an input source from a byte stream.
148      *
149      * @param publicId The public identifier, if known.
150      * @param systemId The system identifier. This value should
151      * always be set, if possible, and can be
152      * relative or absolute. If the system identifier
153      * is relative, then the base system identifier
154      * should be set.
155      * @param baseSystemId The base system identifier. This value should
156      * always be set to the fully expanded URI of the
157      * base system identifier, if possible.
158      * @param byteStream The byte stream.
159      * @param encoding The encoding of the byte stream, if known.
160      */

161     public XMLInputSource(String JavaDoc publicId, String JavaDoc systemId,
162                           String JavaDoc baseSystemId, InputStream JavaDoc byteStream,
163                           String JavaDoc encoding) {
164         fPublicId = publicId;
165         fSystemId = systemId;
166         fBaseSystemId = baseSystemId;
167         fByteStream = byteStream;
168         fEncoding = encoding;
169     } // <init>(String,String,String,InputStream,String)
170

171     /**
172      * Constructs an input source from a character stream.
173      *
174      * @param publicId The public identifier, if known.
175      * @param systemId The system identifier. This value should
176      * always be set, if possible, and can be
177      * relative or absolute. If the system identifier
178      * is relative, then the base system identifier
179      * should be set.
180      * @param baseSystemId The base system identifier. This value should
181      * always be set to the fully expanded URI of the
182      * base system identifier, if possible.
183      * @param charStream The character stream.
184      * @param encoding The original encoding of the byte stream
185      * used by the reader, if known.
186      */

187     public XMLInputSource(String JavaDoc publicId, String JavaDoc systemId,
188                           String JavaDoc baseSystemId, Reader JavaDoc charStream,
189                           String JavaDoc encoding) {
190         fPublicId = publicId;
191         fSystemId = systemId;
192         fBaseSystemId = baseSystemId;
193         fCharStream = charStream;
194         fEncoding = encoding;
195     } // <init>(String,String,String,Reader,String)
196

197     /**
198      * Constructs an input source from {@link StreamSource}.
199      */

200     public XMLInputSource( StreamSource JavaDoc source ) {
201         fPublicId = source.getPublicId();
202         fSystemId = source.getSystemId();
203         fCharStream = source.getReader();
204         fByteStream = source.getInputStream();
205     }
206     
207     //
208
// Public methods
209
//
210

211     /**
212      * Sets the public identifier.
213      *
214      * @param publicId The new public identifier.
215      */

216     public void setPublicId(String JavaDoc publicId) {
217         fPublicId = publicId;
218     } // setPublicId(String)
219

220     /** Returns the public identifier. */
221     public String JavaDoc getPublicId() {
222         return fPublicId;
223     } // getPublicId():String
224

225     /**
226      * Sets the system identifier.
227      *
228      * @param systemId The new system identifier.
229      */

230     public void setSystemId(String JavaDoc systemId) {
231         fSystemId = systemId;
232     } // setSystemId(String)
233

234     /** Returns the system identifier. */
235     public String JavaDoc getSystemId() {
236         return fSystemId;
237     } // getSystemId():String
238

239     /**
240      * Sets the base system identifier.
241      *
242      * @param baseSystemId The new base system identifier.
243      */

244     public void setBaseSystemId(String JavaDoc baseSystemId) {
245         fBaseSystemId = baseSystemId;
246     } // setBaseSystemId(String)
247

248     /** Returns the base system identifier. */
249     public String JavaDoc getBaseSystemId() {
250         return fBaseSystemId;
251     } // getBaseSystemId():String
252

253     /**
254      * Sets the byte stream. If the byte stream is not already opened
255      * when this object is instantiated, then the code that opens the
256      * stream should also set the byte stream on this object. Also, if
257      * the encoding is auto-detected, then the encoding should also be
258      * set on this object.
259      *
260      * @param byteStream The new byte stream.
261      */

262     public void setByteStream(InputStream JavaDoc byteStream) {
263         fByteStream = byteStream;
264     } // setByteStream(InputSource)
265

266     /** Returns the byte stream. */
267     public InputStream JavaDoc getByteStream() {
268         return fByteStream;
269     } // getByteStream():InputStream
270

271     /**
272      * Sets the character stream. If the character stream is not already
273      * opened when this object is instantiated, then the code that opens
274      * the stream should also set the character stream on this object.
275      * Also, the encoding of the byte stream used by the reader should
276      * also be set on this object, if known.
277      *
278      * @param charStream The new character stream.
279      *
280      * @see #setEncoding
281      */

282     public void setCharacterStream(Reader JavaDoc charStream) {
283         fCharStream = charStream;
284     } // setCharacterStream(Reader)
285

286     /** Returns the character stream. */
287     public Reader JavaDoc getCharacterStream() {
288         return fCharStream;
289     } // getCharacterStream():Reader
290

291     /**
292      * Sets the encoding of the stream.
293      *
294      * @param encoding The new encoding.
295      */

296     public void setEncoding(String JavaDoc encoding) {
297         fEncoding = encoding;
298     } // setEncoding(String)
299

300     /** Returns the encoding of the stream, or null if not known. */
301     public String JavaDoc getEncoding() {
302         return fEncoding;
303     } // getEncoding():String
304

305     /**
306      * Wraps this object into a {@link Source} object.
307      */

308     public final XMLInputSourceAdaptor toSource() {
309         return new XMLInputSourceAdaptor(this);
310     }
311 } // class XMLInputSource
312
Popular Tags