source: NonGTP/Xerces/xerces/include/xercesc/sax/InputSource.hpp @ 358

Revision 358, 13.9 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2000,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/*
18 * $Log: InputSource.hpp,v $
19 * Revision 1.12  2004/09/08 13:56:19  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.11  2003/12/17 00:18:35  cargilld
23 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
24 *
25 * Revision 1.10  2003/12/01 23:23:26  neilg
26 * fix for bug 25118; thanks to Jeroen Witmond
27 *
28 * Revision 1.9  2003/11/17 10:52:15  amassari
29 * Fixed documentation bug#24746
30 *
31 * Revision 1.8  2003/05/30 16:11:45  gareth
32 * Fixes so we compile under VC7.1. Patch by Alberto Massari.
33 *
34 * Revision 1.7  2003/05/16 21:36:59  knoaman
35 * Memory manager implementation: Modify constructors to pass in the memory manager.
36 *
37 * Revision 1.6  2003/05/15 18:27:05  knoaman
38 * Partial implementation of the configurable memory manager.
39 *
40 * Revision 1.5  2003/03/07 18:10:06  tng
41 * Return a reference instead of void for operator=
42 *
43 * Revision 1.4  2002/11/04 14:56:26  tng
44 * C++ Namespace Support.
45 *
46 * Revision 1.3  2002/09/30 18:26:18  tng
47 * Since the derived class Wrapper4DOMInputSource has overwritten the set/getEncoding, SystemId, PublicId ... etc., these functions has to be virtual for them to work.
48 *
49 * Revision 1.2  2002/02/20 18:17:01  tng
50 * [Bug 5977] Warnings on generating apiDocs.
51 *
52 * Revision 1.1.1.1  2002/02/01 22:22:08  peiyongz
53 * sane_include
54 *
55 * Revision 1.10  2001/11/21 16:14:32  tng
56 * Schema: New method InputSource::get/setIssueFatalErrorIfNotFound to tell the parser whether to issue fatal error or not if cannot find it (the InputSource).  This is required for schema processing as it shouldn't be a fatal error if the schema is not found.
57 *
58 * Revision 1.9  2000/03/02 19:54:35  roddey
59 * This checkin includes many changes done while waiting for the
60 * 1.1.0 code to be finished. I can't list them all here, but a list is
61 * available elsewhere.
62 *
63 * Revision 1.8  2000/02/24 20:12:55  abagchi
64 * Swat for removing Log from API docs
65 *
66 * Revision 1.7  2000/02/12 03:42:21  rahulj
67 * Fixed DOC++ documentation formatting errors.
68 *
69 * Revision 1.6  2000/02/12 03:31:55  rahulj
70 * Removed duplicate CVS Log entries.
71 *
72 * Revision 1.5  2000/02/12 01:27:19  aruna1
73 * Documentation updated
74 *
75 * Revision 1.4  2000/02/09 02:15:28  abagchi
76 * Documented destructor
77 *
78 * Revision 1.3  2000/02/06 07:47:58  rahulj
79 * Year 2K copyright swat.
80 *
81 * Revision 1.2  2000/01/12 00:15:39  roddey
82 * Changes to deal with multiply nested, relative pathed, entities and to deal
83 * with the new URL class changes.
84 *
85 * Revision 1.1.1.1  1999/11/09 01:07:46  twl
86 * Initial checkin
87 *
88 * Revision 1.2  1999/11/08 20:45:01  rahul
89 * Swat for adding in Product name and CVS comment log variable.
90 *
91 */
92
93
94#ifndef INPUTSOURCE_HPP
95#define INPUTSOURCE_HPP
96
97#include <xercesc/util/PlatformUtils.hpp>
98
99XERCES_CPP_NAMESPACE_BEGIN
100
101class BinInputStream;
102
103
104/**
105  * A single input source for an XML entity.
106  *
107  * <p>This class encapsulates information about an input source in a
108  * single object, which may include a public identifier or a system
109  * identifier</p>
110  *
111  * <p>There are two places that the application will deliver this input
112  * source to the parser: as the argument to the Parser::parse method, or as
113  * the return value of the EntityResolver::resolveEntity method.</p>
114  *
115  * <p>InputSource is never used directly, but is the base class for a number
116  * of derived classes for particular types of input sources. Derivatives are
117  * provided (in the framework/ directory) for URL input sources, memory buffer
118  * input sources, and so on.</p>
119  *
120  * <p>When it is time to parse the input described by an input source, it
121  * will be asked to create a binary stream for that source. That stream will
122  * be used to input the data of the source. The derived class provides the
123  * implementation of the makeStream() method, and provides a type of stream
124  * of the correct type for the input source it represents.
125  *
126  * <p>An InputSource object belongs to the application: the parser never
127  * modifies them in any way. They are always passed by const reference so
128  * the parser will make a copy of any input sources that it must keep
129  * around beyond the call.</p>
130  *
131  * @see Parser#parse
132  * @see EntityResolver#resolveEntity
133  */
134class SAX_EXPORT InputSource : public XMemory
135{
136public:
137    // -----------------------------------------------------------------------
138    //  All constructors are hidden, just the destructor is available
139    // -----------------------------------------------------------------------
140    /** @name Destructor */
141    //@{
142  /**
143    * Destructor
144    *
145    */
146    virtual ~InputSource();
147    //@}
148
149
150    // -----------------------------------------------------------------------
151    /** @name Virtual input source interface */
152    //@{
153  /**
154    * Makes the byte stream for this input source.
155    *
156    * <p>The derived class must create and return a binary input stream of an
157    * appropriate type for its kind of data source. The returned stream must
158    * be dynamically allocated and becomes the parser's property.
159    * </p>
160    *
161    * @see BinInputStream
162    */
163    virtual BinInputStream* makeStream() const = 0;
164
165    //@}
166
167
168    // -----------------------------------------------------------------------
169    /** @name Getter methods */
170    //@{
171  /**
172    * An input source can be set to force the parser to assume a particular
173    * encoding for the data that input source reprsents, via the setEncoding()
174    * method. This method returns name of the encoding that is to be forced.
175    * If the encoding has never been forced, it returns a null pointer.
176    *
177    * @return The forced encoding, or null if none was supplied.
178    * @see #setEncoding
179    */
180    virtual const XMLCh* getEncoding() const;
181
182
183  /**
184    * Get the public identifier for this input source.
185    *
186    * @return The public identifier, or null if none was supplied.
187    * @see #setPublicId
188    */
189    virtual const XMLCh* getPublicId() const;
190
191
192  /**
193    * Get the system identifier for this input source.
194    *
195    * <p>If the system ID is a URL, it will be fully resolved.</p>
196    *
197    * @return The system identifier.
198    * @see #setSystemId
199    */
200    virtual const XMLCh* getSystemId() const;
201
202  /**
203    * Get the flag that indicates if the parser should issue fatal error if this input source
204    * is not found.
205    *
206    * @return True if the parser should issue fatal error if this input source is not found.
207    *         False if the parser issue warning message instead.
208    * @see #setIssueFatalErrorIfNotFound
209    */
210    virtual bool getIssueFatalErrorIfNotFound() const;
211
212    MemoryManager* getMemoryManager() const;
213
214    //@}
215
216
217    // -----------------------------------------------------------------------
218    /** @name Setter methods */
219    //@{
220
221  /**
222    * Set the encoding which will be required for use with the XML text read
223    * via a stream opened by this input source.
224    *
225    * <p>This is usually not set, allowing the encoding to be sensed in the
226    * usual XML way. However, in some cases, the encoding in the file is known
227    * to be incorrect because of intermediate transcoding, for instance
228    * encapsulation within a MIME document.
229    *
230    * @param encodingStr The name of the encoding to force.
231    */
232    virtual void setEncoding(const XMLCh* const encodingStr);
233
234
235  /**
236    * Set the public identifier for this input source.
237    *
238    * <p>The public identifier is always optional: if the application writer
239    * includes one, it will be provided as part of the location information.</p>
240    *
241    * @param publicId The public identifier as a string.
242    * @see Locator#getPublicId
243    * @see SAXParseException#getPublicId
244    * @see #getPublicId
245    */
246    virtual void setPublicId(const XMLCh* const publicId);
247
248  /**
249    * Set the system identifier for this input source.
250    *
251    * <p>Set the system identifier for this input source.
252    *
253    * </p>The system id is always required. The public id may be used to map
254    * to another system id, but the system id must always be present as a fall
255    * back.
256    *
257    * <p>If the system ID is a URL, it must be fully resolved.</p>
258    *
259    * @param systemId The system identifier as a string.
260    * @see #getSystemId
261    * @see Locator#getSystemId
262    * @see SAXParseException#getSystemId
263    */
264    virtual void setSystemId(const XMLCh* const systemId);
265
266  /**
267    * Indicates if the parser should issue fatal error if this input source
268    * is not found.  If set to false, the parser issue warning message instead.
269    *
270    * @param  flag True if the parser should issue fatal error if this input source is not found.
271    *               If set to false, the parser issue warning message instead.  (Default: true)
272    *
273    * @see #getIssueFatalErrorIfNotFound
274    */
275    virtual void setIssueFatalErrorIfNotFound(const bool flag);
276
277    //@}
278
279
280protected :
281    // -----------------------------------------------------------------------
282    //  Hidden constructors
283    // -----------------------------------------------------------------------
284    /** @name Constructors and Destructor */
285    //@{
286    /** Default constructor */
287    InputSource(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
288
289    /** Constructor with a system identifier as XMLCh type.
290      * @param systemId The system identifier (URI).
291      * @param manager    Pointer to the memory manager to be used to
292      *                   allocate objects.
293      */
294    InputSource(const XMLCh* const systemId,
295                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
296
297    /** Constructor with a system and public identifiers
298      * @param systemId The system identifier (URI).
299      * @param publicId The public identifier as in the entity definition.
300      * @param manager    Pointer to the memory manager to be used to
301      *                   allocate objects.
302      */
303    InputSource
304    (
305        const   XMLCh* const   systemId
306        , const XMLCh* const   publicId
307        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
308    );
309
310    /** Constructor witha system identifier as string
311      * @param systemId The system identifier (URI).
312      * @param manager    Pointer to the memory manager to be used to
313      *                   allocate objects.
314      */
315    InputSource(const char* const systemId,
316                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
317
318    /** Constructor witha system and public identifiers. Both as string
319      * @param systemId The system identifier (URI).
320      * @param publicId The public identifier as in the entity definition.
321      * @param manager    Pointer to the memory manager to be used to
322      *                   allocate objects.
323      */
324    InputSource
325    (
326        const   char* const systemId
327        , const char* const publicId
328        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
329    );
330
331    //@}
332
333
334
335
336
337private:
338    // -----------------------------------------------------------------------
339    //  Unimplemented constructors and operators
340    // -----------------------------------------------------------------------
341    InputSource(const InputSource&);
342    InputSource& operator=(const InputSource&);
343
344
345    // -----------------------------------------------------------------------
346    //  Private data members
347    //
348    //  fEncoding
349    //      This is the encoding to use. Usually this is null, which means
350    //      to use the information found in the file itself. But, if set,
351    //      this encoding will be used without question.
352    //
353    //  fPublicId
354    //      This is the optional public id for the input source. It can be
355    //      null if none is desired.
356    //
357    //  fSystemId
358    //      This is the system id for the input source. This is what is
359    //      actually used to open the source.
360    //
361    //  fFatalErrorIfNotFound
362    // -----------------------------------------------------------------------
363    MemoryManager* const fMemoryManager;
364    XMLCh*         fEncoding;
365    XMLCh*         fPublicId;
366    XMLCh*         fSystemId;
367    bool           fFatalErrorIfNotFound;
368};
369
370
371// ---------------------------------------------------------------------------
372//  InputSource: Getter methods
373// ---------------------------------------------------------------------------
374inline const XMLCh* InputSource::getEncoding() const
375{
376    return fEncoding;
377}
378
379inline const XMLCh* InputSource::getPublicId() const
380{
381    return fPublicId;
382}
383
384inline const XMLCh* InputSource::getSystemId() const
385{
386    return fSystemId;
387}
388
389inline bool InputSource::getIssueFatalErrorIfNotFound() const
390{
391    return fFatalErrorIfNotFound;
392}
393
394inline MemoryManager* InputSource::getMemoryManager() const
395{
396    return fMemoryManager;
397}
398
399// ---------------------------------------------------------------------------
400//  InputSource: Setter methods
401// ---------------------------------------------------------------------------
402inline void InputSource::setIssueFatalErrorIfNotFound(const bool flag)
403{
404    fFatalErrorIfNotFound = flag;
405}
406
407XERCES_CPP_NAMESPACE_END
408
409#endif
Note: See TracBrowser for help on using the repository browser.