KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > DOMInputImpl


1 /*
2  * Copyright 2001, 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.dom;
18
19 import org.w3c.dom.ls.LSInput JavaDoc;
20
21 import java.io.Reader JavaDoc;
22 import java.io.InputStream JavaDoc;
23
24 /**
25  * This Class <code>DOMInputImpl</code> represents a single input source for an XML entity.
26  * <p> This Class allows an application to encapsulate information about
27  * an input source in a single object, which may include a public
28  * identifier, a system identifier, a byte stream (possibly with a specified
29  * encoding), and/or a character stream.
30  * <p> The exact definitions of a byte stream and a character stream are
31  * binding dependent.
32  * <p> There are two places that the application will deliver this input
33  * source to the parser: as the argument to the <code>parse</code> method,
34  * or as the return value of the <code>DOMResourceResolver.resolveEntity</code>
35  * method.
36  * <p> The <code>DOMParser</code> will use the <code>LSInput</code>
37  * object to determine how to read XML input. If there is a character stream
38  * available, the parser will read that stream directly; if not, the parser
39  * will use a byte stream, if available; if neither a character stream nor a
40  * byte stream is available, the parser will attempt to open a URI
41  * connection to the resource identified by the system identifier.
42  * <p> An <code>LSInput</code> object belongs to the application: the
43  * parser shall never modify it in any way (it may modify a copy if
44  * necessary). Eventhough all attributes in this interface are writable the
45  * DOM implementation is expected to never mutate a LSInput.
46  * <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
47 and Save Specification</a>.
48  *
49  * @xerces.internal
50  *
51  * @author Gopal Sharma, SUN Microsystems Inc.
52  * @version $Id: DOMInputImpl.java,v 1.4 2004/10/05 17:12:50 mrglavas Exp $
53  */

54
55 // REVISIT:
56
// 1. it should be possible to do the following
57
// DOMInputImpl extends XMLInputSource implements LSInput
58
// 2. we probably need only the default constructor. -- el
59

60 public class DOMInputImpl implements LSInput JavaDoc {
61
62     //
63
// Data
64
//
65

66     protected String JavaDoc fPublicId = null;
67     protected String JavaDoc fSystemId = null;
68     protected String JavaDoc fBaseSystemId = null;
69
70     protected InputStream JavaDoc fByteStream = null;
71     protected Reader JavaDoc fCharStream = null;
72     protected String JavaDoc fData = null;
73
74     protected String JavaDoc fEncoding = null;
75
76         protected boolean fCertifiedText = false;
77
78    /**
79      * Default Constructor, constructs an input source
80      *
81      *
82      */

83      public DOMInputImpl() {}
84
85    /**
86      * Constructs an input source from just the public and system
87      * identifiers, leaving resolution of the entity and opening of
88      * the input stream up to the caller.
89      *
90      * @param publicId The public identifier, if known.
91      * @param systemId The system identifier. This value should
92      * always be set, if possible, and can be
93      * relative or absolute. If the system identifier
94      * is relative, then the base system identifier
95      * should be set.
96      * @param baseSystemId The base system identifier. This value should
97      * always be set to the fully expanded URI of the
98      * base system identifier, if possible.
99      */

100
101     public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
102                           String JavaDoc baseSystemId) {
103
104         fPublicId = publicId;
105         fSystemId = systemId;
106         fBaseSystemId = baseSystemId;
107
108     } // DOMInputImpl(String,String,String)
109

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

125
126     public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
127                           String JavaDoc baseSystemId, InputStream JavaDoc byteStream,
128                           String JavaDoc encoding) {
129
130         fPublicId = publicId;
131         fSystemId = systemId;
132         fBaseSystemId = baseSystemId;
133         fByteStream = byteStream;
134         fEncoding = encoding;
135
136     } // DOMInputImpl(String,String,String,InputStream,String)
137

138    /**
139      * Constructs an input source from a character stream.
140      *
141      * @param publicId The public identifier, if known.
142      * @param systemId The system identifier. This value should
143      * always be set, if possible, and can be
144      * relative or absolute. If the system identifier
145      * is relative, then the base system identifier
146      * should be set.
147      * @param baseSystemId The base system identifier. This value should
148      * always be set to the fully expanded URI of the
149      * base system identifier, if possible.
150      * @param charStream The character stream.
151      * @param encoding The original encoding of the byte stream
152      * used by the reader, if known.
153      */

154
155      public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
156                           String JavaDoc baseSystemId, Reader JavaDoc charStream,
157                           String JavaDoc encoding) {
158
159         fPublicId = publicId;
160         fSystemId = systemId;
161         fBaseSystemId = baseSystemId;
162         fCharStream = charStream;
163         fEncoding = encoding;
164
165      } // DOMInputImpl(String,String,String,Reader,String)
166

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

183
184      public DOMInputImpl(String JavaDoc publicId, String JavaDoc systemId,
185                           String JavaDoc baseSystemId, String JavaDoc data,
186                           String JavaDoc encoding) {
187                 fPublicId = publicId;
188         fSystemId = systemId;
189         fBaseSystemId = baseSystemId;
190         fData = data;
191         fEncoding = encoding;
192      } // DOMInputImpl(String,String,String,String,String)
193

194    /**
195      * An attribute of a language-binding dependent type that represents a
196      * stream of bytes.
197      * <br>The parser will ignore this if there is also a character stream
198      * specified, but it will use a byte stream in preference to opening a
199      * URI connection itself.
200      * <br>If the application knows the character encoding of the byte stream,
201      * it should set the encoding property. Setting the encoding in this way
202      * will override any encoding specified in the XML declaration itself.
203      */

204
205     public InputStream JavaDoc getByteStream(){
206     return fByteStream;
207     }
208
209     /**
210      * An attribute of a language-binding dependent type that represents a
211      * stream of bytes.
212      * <br>The parser will ignore this if there is also a character stream
213      * specified, but it will use a byte stream in preference to opening a
214      * URI connection itself.
215      * <br>If the application knows the character encoding of the byte stream,
216      * it should set the encoding property. Setting the encoding in this way
217      * will override any encoding specified in the XML declaration itself.
218      */

219
220      public void setByteStream(InputStream JavaDoc byteStream){
221     fByteStream = byteStream;
222      }
223
224     /**
225      * An attribute of a language-binding dependent type that represents a
226      * stream of 16-bit units. Application must encode the stream using
227      * UTF-16 (defined in and Amendment 1 of ).
228      * <br>If a character stream is specified, the parser will ignore any byte
229      * stream and will not attempt to open a URI connection to the system
230      * identifier.
231      */

232     public Reader JavaDoc getCharacterStream(){
233     return fCharStream;
234     }
235     /**
236      * An attribute of a language-binding dependent type that represents a
237      * stream of 16-bit units. Application must encode the stream using
238      * UTF-16 (defined in and Amendment 1 of ).
239      * <br>If a character stream is specified, the parser will ignore any byte
240      * stream and will not attempt to open a URI connection to the system
241      * identifier.
242      */

243
244      public void setCharacterStream(Reader JavaDoc characterStream){
245     fCharStream = characterStream;
246      }
247
248     /**
249      * A string attribute that represents a sequence of 16 bit units (utf-16
250      * encoded characters).
251      * <br>If string data is available in the input source, the parser will
252      * ignore the character stream and the byte stream and will not attempt
253      * to open a URI connection to the system identifier.
254      */

255     public String JavaDoc getStringData(){
256     return fData;
257     }
258
259    /**
260      * A string attribute that represents a sequence of 16 bit units (utf-16
261      * encoded characters).
262      * <br>If string data is available in the input source, the parser will
263      * ignore the character stream and the byte stream and will not attempt
264      * to open a URI connection to the system identifier.
265      */

266
267      public void setStringData(String JavaDoc stringData){
268         fData = stringData;
269      }
270
271     /**
272      * The character encoding, if known. The encoding must be a string
273      * acceptable for an XML encoding declaration ( section 4.3.3 "Character
274      * Encoding in Entities").
275      * <br>This attribute has no effect when the application provides a
276      * character stream. For other sources of input, an encoding specified
277      * by means of this attribute will override any encoding specified in
278      * the XML claration or the Text Declaration, or an encoding obtained
279      * from a higher level protocol, such as HTTP .
280      */

281
282     public String JavaDoc getEncoding(){
283     return fEncoding;
284     }
285
286     /**
287      * The character encoding, if known. The encoding must be a string
288      * acceptable for an XML encoding declaration ( section 4.3.3 "Character
289      * Encoding in Entities").
290      * <br>This attribute has no effect when the application provides a
291      * character stream. For other sources of input, an encoding specified
292      * by means of this attribute will override any encoding specified in
293      * the XML claration or the Text Declaration, or an encoding obtained
294      * from a higher level protocol, such as HTTP .
295      */

296     public void setEncoding(String JavaDoc encoding){
297     fEncoding = encoding;
298     }
299
300     /**
301      * The public identifier for this input source. The public identifier is
302      * always optional: if the application writer includes one, it will be
303      * provided as part of the location information.
304      */

305     public String JavaDoc getPublicId(){
306     return fPublicId;
307     }
308     /**
309      * The public identifier for this input source. The public identifier is
310      * always optional: if the application writer includes one, it will be
311      * provided as part of the location information.
312      */

313     public void setPublicId(String JavaDoc publicId){
314     fPublicId = publicId;
315     }
316
317     /**
318      * The system identifier, a URI reference , for this input source. The
319      * system identifier is optional if there is a byte stream or a
320      * character stream, but it is still useful to provide one, since the
321      * application can use it to resolve relative URIs and can include it in
322      * error messages and warnings (the parser will attempt to fetch the
323      * ressource identifier by the URI reference only if there is no byte
324      * stream or character stream specified).
325      * <br>If the application knows the character encoding of the object
326      * pointed to by the system identifier, it can register the encoding by
327      * setting the encoding attribute.
328      * <br>If the system ID is a relative URI reference (see section 5 in ),
329      * the behavior is implementation dependent.
330      */

331     public String JavaDoc getSystemId(){
332     return fSystemId;
333     }
334     /**
335      * The system identifier, a URI reference , for this input source. The
336      * system identifier is optional if there is a byte stream or a
337      * character stream, but it is still useful to provide one, since the
338      * application can use it to resolve relative URIs and can include it in
339      * error messages and warnings (the parser will attempt to fetch the
340      * ressource identifier by the URI reference only if there is no byte
341      * stream or character stream specified).
342      * <br>If the application knows the character encoding of the object
343      * pointed to by the system identifier, it can register the encoding by
344      * setting the encoding attribute.
345      * <br>If the system ID is a relative URI reference (see section 5 in ),
346      * the behavior is implementation dependent.
347      */

348     public void setSystemId(String JavaDoc systemId){
349     fSystemId = systemId;
350     }
351
352     /**
353      * The base URI to be used (see section 5.1.4 in ) for resolving relative
354      * URIs to absolute URIs. If the baseURI is itself a relative URI, the
355      * behavior is implementation dependent.
356      */

357     public String JavaDoc getBaseURI(){
358     return fBaseSystemId;
359     }
360     /**
361      * The base URI to be used (see section 5.1.4 in ) for resolving relative
362      * URIs to absolute URIs. If the baseURI is itself a relative URI, the
363      * behavior is implementation dependent.
364      */

365     public void setBaseURI(String JavaDoc baseURI){
366     fBaseSystemId = baseURI;
367     }
368
369     /**
370       * If set to true, assume that the input is certified (see section 2.13
371       * in [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when
372       * parsing [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>].
373       */

374     public boolean getCertifiedText(){
375       return fCertifiedText;
376     }
377
378     /**
379       * If set to true, assume that the input is certified (see section 2.13
380       * in [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when
381       * parsing [<a HREF='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>].
382       */

383
384     public void setCertifiedText(boolean certifiedText){
385       fCertifiedText = certifiedText;
386     }
387
388 }// class DOMInputImpl
389
Popular Tags