KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > dom > DOMInputImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001, 2002 The Apache Software Foundation.
6  * All rights 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) 2001, 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.dom;
59
60 import org.w3c.dom.ls.LSInput JavaDoc;
61
62 import java.io.Reader JavaDoc;
63 import java.io.InputStream JavaDoc;
64
65 /**
66  * This Class <code>DOMInputImpl</code> represents a single input source for an XML entity.
67  * <p> This Class allows an application to encapsulate information about
68  * an input source in a single object, which may include a public
69  * identifier, a system identifier, a byte stream (possibly with a specified
70  * encoding), and/or a character stream.
71  * <p> The exact definitions of a byte stream and a character stream are
72  * binding dependent.
73  * <p> There are two places that the application will deliver this input
74  * source to the parser: as the argument to the <code>parse</code> method,
75  * or as the return value of the <code>DOMResourceResolver.resolveEntity</code>
76  * method.
77  * <p> The <code>DOMParser</code> will use the <code>LSInput</code>
78  * object to determine how to read XML input. If there is a character stream
79  * available, the parser will read that stream directly; if not, the parser
80  * will use a byte stream, if available; if neither a character stream nor a
81  * byte stream is available, the parser will attempt to open a URI
82  * connection to the resource identified by the system identifier.
83  * <p> An <code>LSInput</code> object belongs to the application: the
84  * parser shall never modify it in any way (it may modify a copy if
85  * necessary). Eventhough all attributes in this interface are writable the
86  * DOM implementation is expected to never mutate a LSInput.
87  * <p>See also the <a HREF='http://www.w3.org/TR/2001/WD-DOM-Level-3-ASLS-20011025'>Document Object Model (DOM) Level 3 Abstract Schemas and Load
88 and Save Specification</a>.
89  *
90  *
91  * @author Gopal Sharma, SUN Microsystems Inc.
92  * @version $Id: DOMInputImpl.java,v 1.2 2003/11/17 13:48:40 venu Exp $
93  */

94
95 // REVISIT:
96
// 1. it should be possible to do the following
97
// DOMInputImpl extends XMLInputSource implements LSInput
98
// 2. we probably need only the default constructor. -- el
99

100 public class DOMInputImpl implements LSInput JavaDoc {
101
102     //
103
// Data
104
//
105

106     protected String JavaDoc fPublicId = null;
107     protected String JavaDoc fSystemId = null;
108     protected String JavaDoc fBaseSystemId = null;
109
110     protected InputStream JavaDoc fByteStream = null;
111     protected Reader JavaDoc fCharStream = null;
112     protected String JavaDoc fData = null;
113
114     protected String JavaDoc fEncoding = null;
115
116         protected boolean fCertifiedText = false;
117
118    /**
119      * Default Constructor, constructs an input source
120      *
121      *
122      */

123      public DOMInputImpl() {}
124
125    /**
126      * Constructs an input source from just the public and system
127      * identifiers, leaving resolution of the entity and opening of
128      * the input stream up to the caller.
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      */

140
141     public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
142                           String JavaDoc baseSystemId) {
143
144         fPublicId = publicId;
145         fSystemId = systemId;
146         fBaseSystemId = baseSystemId;
147
148     } // DOMInputImpl(String,String,String)
149

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

165
166     public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
167                           String JavaDoc baseSystemId, InputStream JavaDoc byteStream,
168                           String JavaDoc encoding) {
169
170         fPublicId = publicId;
171         fSystemId = systemId;
172         fBaseSystemId = baseSystemId;
173         fByteStream = byteStream;
174         fEncoding = encoding;
175
176     } // DOMInputImpl(String,String,String,InputStream,String)
177

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

194
195      public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
196                           String JavaDoc baseSystemId, Reader JavaDoc charStream,
197                           String JavaDoc encoding) {
198
199         fPublicId = publicId;
200         fSystemId = systemId;
201         fBaseSystemId = baseSystemId;
202         fCharStream = charStream;
203         fEncoding = encoding;
204
205      } // DOMInputImpl(String,String,String,Reader,String)
206

207    /**
208      * Constructs an input source from a String.
209      *
210      * @param publicId The public identifier, if known.
211      * @param systemId The system identifier. This value should
212      * always be set, if possible, and can be
213      * relative or absolute. If the system identifier
214      * is relative, then the base system identifier
215      * should be set.
216      * @param baseSystemId The base system identifier. This value should
217      * always be set to the fully expanded URI of the
218      * base system identifier, if possible.
219      * @param data The String Data.
220      * @param encoding The original encoding of the byte stream
221      * used by the reader, if known.
222      */

223
224      public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
225                           String JavaDoc baseSystemId, String JavaDoc data,
226                           String JavaDoc encoding) {
227                 fPublicId = publicId;
228         fSystemId = systemId;
229         fBaseSystemId = baseSystemId;
230         fData = data;
231         fEncoding = encoding;
232      } // DOMInputImpl(String,String,String,String,String)
233

234    /**
235      * An attribute of a language-binding dependent type that represents a
236      * stream of bytes.
237      * <br>The parser will ignore this if there is also a character stream
238      * specified, but it will use a byte stream in preference to opening a
239      * URI connection itself.
240      * <br>If the application knows the character encoding of the byte stream,
241      * it should set the encoding property. Setting the encoding in this way
242      * will override any encoding specified in the XML declaration itself.
243      */

244
245     public InputStream JavaDoc getByteStream(){
246     return fByteStream;
247     }
248
249     /**
250      * An attribute of a language-binding dependent type that represents a
251      * stream of bytes.
252      * <br>The parser will ignore this if there is also a character stream
253      * specified, but it will use a byte stream in preference to opening a
254      * URI connection itself.
255      * <br>If the application knows the character encoding of the byte stream,
256      * it should set the encoding property. Setting the encoding in this way
257      * will override any encoding specified in the XML declaration itself.
258      */

259
260      public void setByteStream(InputStream JavaDoc byteStream){
261     fByteStream = byteStream;
262      }
263
264     /**
265      * An attribute of a language-binding dependent type that represents a
266      * stream of 16-bit units. Application must encode the stream using
267      * UTF-16 (defined in and Amendment 1 of ).
268      * <br>If a character stream is specified, the parser will ignore any byte
269      * stream and will not attempt to open a URI connection to the system
270      * identifier.
271      */

272     public Reader JavaDoc getCharacterStream(){
273     return fCharStream;
274     }
275     /**
276      * An attribute of a language-binding dependent type that represents a
277      * stream of 16-bit units. Application must encode the stream using
278      * UTF-16 (defined in and Amendment 1 of ).
279      * <br>If a character stream is specified, the parser will ignore any byte
280      * stream and will not attempt to open a URI connection to the system
281      * identifier.
282      */

283
284      public void setCharacterStream(Reader JavaDoc characterStream){
285     fCharStream = characterStream;
286      }
287
288     /**
289      * A string attribute that represents a sequence of 16 bit units (utf-16
290      * encoded characters).
291      * <br>If string data is available in the input source, the parser will
292      * ignore the character stream and the byte stream and will not attempt
293      * to open a URI connection to the system identifier.
294      */

295     public String JavaDoc getStringData(){
296     return fData;
297     }
298
299    /**
300      * A string attribute that represents a sequence of 16 bit units (utf-16
301      * encoded characters).
302      * <br>If string data is available in the input source, the parser will
303      * ignore the character stream and the byte stream and will not attempt
304      * to open a URI connection to the system identifier.
305      */

306
307      public void setStringData(String JavaDoc stringData){
308         fData = stringData;
309      }
310
311     /**
312      * The character encoding, if known. The encoding must be a string
313      * acceptable for an XML encoding declaration ( section 4.3.3 "Character
314      * Encoding in Entities").
315      * <br>This attribute has no effect when the application provides a
316      * character stream. For other sources of input, an encoding specified
317      * by means of this attribute will override any encoding specified in
318      * the XML claration or the Text Declaration, or an encoding obtained
319      * from a higher level protocol, such as HTTP .
320      */

321
322     public String JavaDoc getEncoding(){
323     return fEncoding;
324     }
325
326     /**
327      * The character encoding, if known. The encoding must be a string
328      * acceptable for an XML encoding declaration ( section 4.3.3 "Character
329      * Encoding in Entities").
330      * <br>This attribute has no effect when the application provides a
331      * character stream. For other sources of input, an encoding specified
332      * by means of this attribute will override any encoding specified in
333      * the XML claration or the Text Declaration, or an encoding obtained
334      * from a higher level protocol, such as HTTP .
335      */

336     public void setEncoding(String JavaDoc encoding){
337     fEncoding = encoding;
338     }
339
340     /**
341      * The public identifier for this input source. The public identifier is
342      * always optional: if the application writer includes one, it will be
343      * provided as part of the location information.
344      */

345     public String JavaDoc getPublicId(){
346     return fPublicId;
347     }
348     /**
349      * The public identifier for this input source. The public identifier is
350      * always optional: if the application writer includes one, it will be
351      * provided as part of the location information.
352      */

353     public void setPublicId(String JavaDoc publicId){
354     fPublicId = publicId;
355     }
356
357     /**
358      * The system identifier, a URI reference , for this input source. The
359      * system identifier is optional if there is a byte stream or a
360      * character stream, but it is still useful to provide one, since the
361      * application can use it to resolve relative URIs and can include it in
362      * error messages and warnings (the parser will attempt to fetch the
363      * ressource identifier by the URI reference only if there is no byte
364      * stream or character stream specified).
365      * <br>If the application knows the character encoding of the object
366      * pointed to by the system identifier, it can register the encoding by
367      * setting the encoding attribute.
368      * <br>If the system ID is a relative URI reference (see section 5 in ),
369      * the behavior is implementation dependent.
370      */

371     public String JavaDoc getSystemId(){
372     return fSystemId;
373     }
374     /**
375      * The system identifier, a URI reference , for this input source. The
376      * system identifier is optional if there is a byte stream or a
377      * character stream, but it is still useful to provide one, since the
378      * application can use it to resolve relative URIs and can include it in
379      * error messages and warnings (the parser will attempt to fetch the
380      * ressource identifier by the URI reference only if there is no byte
381      * stream or character stream specified).
382      * <br>If the application knows the character encoding of the object
383      * pointed to by the system identifier, it can register the encoding by
384      * setting the encoding attribute.
385      * <br>If the system ID is a relative URI reference (see section 5 in ),
386      * the behavior is implementation dependent.
387      */

388     public void setSystemId(String JavaDoc systemId){
389     fSystemId = systemId;
390     }
391
392     /**
393      * The base URI to be used (see section 5.1.4 in ) for resolving relative
394      * URIs to absolute URIs. If the baseURI is itself a relative URI, the
395      * behavior is implementation dependent.
396      */

397     public String JavaDoc getBaseURI(){
398     return fBaseSystemId;
399     }
400     /**
401      * The base URI to be used (see section 5.1.4 in ) for resolving relative
402      * URIs to absolute URIs. If the baseURI is itself a relative URI, the
403      * behavior is implementation dependent.
404      */

405     public void setBaseURI(String JavaDoc baseURI){
406     fBaseSystemId = baseURI;
407     }
408
409     /**
410       * If set to true, assume that the input is certified (see section 2.13
411       * in [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when
412       * parsing [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>].
413       */

414     public boolean getCertifiedText(){
415       return fCertifiedText;
416     }
417
418     /**
419       * If set to true, assume that the input is certified (see section 2.13
420       * in [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when
421       * parsing [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>].
422       */

423
424     public void setCertifiedText(boolean certifiedText){
425       fCertifiedText = certifiedText;
426     }
427
428 }// class DOMInputImpl
429
Popular Tags