source: icXML/icXML-devel/src/xercesc/sax/InputSource.hpp @ 2777

Last change on this file since 2777 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 11.1 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: InputSource.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_INPUTSOURCE_HPP)
23#define XERCESC_INCLUDE_GUARD_INPUTSOURCE_HPP
24
25#include <icxercesc/util/PlatformUtils.hpp>
26
27XERCES_CPP_NAMESPACE_BEGIN
28
29class BinInputStream;
30
31
32/**
33  * A single input source for an XML entity.
34  *
35  * <p>This class encapsulates information about an input source in a
36  * single object, which may include a public identifier or a system
37  * identifier</p>
38  *
39  * <p>There are two places that the application will deliver this input
40  * source to the parser: as the argument to the Parser::parse method, or as
41  * the return value of the EntityResolver::resolveEntity method.</p>
42  *
43  * <p>InputSource is never used directly, but is the base class for a number
44  * of derived classes for particular types of input sources. Derivatives are
45  * provided (in the framework/ directory) for URL input sources, memory buffer
46  * input sources, and so on.</p>
47  *
48  * <p>When it is time to parse the input described by an input source, it
49  * will be asked to create a binary stream for that source. That stream will
50  * be used to input the data of the source. The derived class provides the
51  * implementation of the makeStream() method, and provides a type of stream
52  * of the correct type for the input source it represents.
53  *
54  * <p>An InputSource object belongs to the application: the parser never
55  * modifies them in any way. They are always passed by const reference so
56  * the parser will make a copy of any input sources that it must keep
57  * around beyond the call.</p>
58  *
59  * @see Parser#parse
60  * @see EntityResolver#resolveEntity
61  */
62class SAX_EXPORT InputSource : public XMemory
63{
64public:
65    // -----------------------------------------------------------------------
66    //  All constructors are hidden, just the destructor is available
67    // -----------------------------------------------------------------------
68    /** @name Destructor */
69    //@{
70  /**
71    * Destructor
72    *
73    */
74    virtual ~InputSource();
75    //@}
76
77
78    // -----------------------------------------------------------------------
79    /** @name Virtual input source interface */
80    //@{
81  /**
82    * Makes the byte stream for this input source.
83    *
84    * <p>The derived class must create and return a binary input stream of an
85    * appropriate type for its kind of data source. The returned stream must
86    * be dynamically allocated and becomes the parser's property.
87    * </p>
88    *
89    * @see BinInputStream
90    */
91    virtual BinInputStream* makeStream() const = 0;
92
93    //@}
94
95
96    // -----------------------------------------------------------------------
97    /** @name Getter methods */
98    //@{
99  /**
100    * An input source can be set to force the parser to assume a particular
101    * encoding for the data that input source represents, via the setEncoding()
102    * method. This method returns name of the encoding that is to be forced.
103    * If the encoding has never been forced, it returns a null pointer.
104    *
105    * @return The forced encoding, or null if none was supplied.
106    * @see #setEncoding
107    */
108    virtual const XMLCh* getEncoding() const;
109
110
111  /**
112    * Get the public identifier for this input source.
113    *
114    * @return The public identifier, or null if none was supplied.
115    * @see #setPublicId
116    */
117    virtual const XMLCh* getPublicId() const;
118
119
120  /**
121    * Get the system identifier for this input source.
122    *
123    * <p>If the system ID is a URL, it will be fully resolved.</p>
124    *
125    * @return The system identifier.
126    * @see #setSystemId
127    */
128    virtual const XMLCh* getSystemId() const;
129
130  /**
131    * Get the flag that indicates if the parser should issue fatal error if this input source
132    * is not found.
133    *
134    * @return True if the parser should issue fatal error if this input source is not found.
135    *         False if the parser issue warning message instead.
136    * @see #setIssueFatalErrorIfNotFound
137    */
138    virtual bool getIssueFatalErrorIfNotFound() const;
139
140    MemoryManager* getMemoryManager() const;
141
142    //@}
143
144
145    // -----------------------------------------------------------------------
146    /** @name Setter methods */
147    //@{
148
149  /**
150    * Set the encoding which will be required for use with the XML text read
151    * via a stream opened by this input source.
152    *
153    * <p>This is usually not set, allowing the encoding to be sensed in the
154    * usual XML way. However, in some cases, the encoding in the file is known
155    * to be incorrect because of intermediate transcoding, for instance
156    * encapsulation within a MIME document.
157    *
158    * @param encodingStr The name of the encoding to force.
159    */
160    virtual void setEncoding(const XMLCh* const encodingStr);
161
162
163  /**
164    * Set the public identifier for this input source.
165    *
166    * <p>The public identifier is always optional: if the application writer
167    * includes one, it will be provided as part of the location information.</p>
168    *
169    * @param publicId The public identifier as a string.
170    * @see Locator#getPublicId
171    * @see SAXParseException#getPublicId
172    * @see #getPublicId
173    */
174    virtual void setPublicId(const XMLCh* const publicId);
175
176  /**
177    * Set the system identifier for this input source.
178    *
179    * <p>Set the system identifier for this input source.
180    *
181    * </p>The system id is always required. The public id may be used to map
182    * to another system id, but the system id must always be present as a fall
183    * back.
184    *
185    * <p>If the system ID is a URL, it must be fully resolved.</p>
186    *
187    * @param systemId The system identifier as a string.
188    * @see #getSystemId
189    * @see Locator#getSystemId
190    * @see SAXParseException#getSystemId
191    */
192    virtual void setSystemId(const XMLCh* const systemId);
193
194  /**
195    * Indicates if the parser should issue fatal error if this input source
196    * is not found.  If set to false, the parser issue warning message instead.
197    *
198    * @param  flag True if the parser should issue fatal error if this input source is not found.
199    *               If set to false, the parser issue warning message instead.  (Default: true)
200    *
201    * @see #getIssueFatalErrorIfNotFound
202    */
203    virtual void setIssueFatalErrorIfNotFound(const bool flag);
204
205    //@}
206
207
208protected :
209    // -----------------------------------------------------------------------
210    //  Hidden constructors
211    // -----------------------------------------------------------------------
212    /** @name Constructors and Destructor */
213    //@{
214    /** Default constructor */
215    InputSource(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
216
217    /** Constructor with a system identifier as XMLCh type.
218      * @param systemId The system identifier (URI).
219      * @param manager    Pointer to the memory manager to be used to
220      *                   allocate objects.
221      */
222    InputSource(const XMLCh* const systemId,
223                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
224
225    /** Constructor with a system and public identifiers
226      * @param systemId The system identifier (URI).
227      * @param publicId The public identifier as in the entity definition.
228      * @param manager    Pointer to the memory manager to be used to
229      *                   allocate objects.
230      */
231    InputSource
232    (
233        const   XMLCh* const   systemId
234        , const XMLCh* const   publicId
235        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
236    );
237
238    /** Constructor witha system identifier as string
239      * @param systemId The system identifier (URI).
240      * @param manager    Pointer to the memory manager to be used to
241      *                   allocate objects.
242      */
243    InputSource(const char* const systemId,
244                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
245
246    /** Constructor witha system and public identifiers. Both as string
247      * @param systemId The system identifier (URI).
248      * @param publicId The public identifier as in the entity definition.
249      * @param manager    Pointer to the memory manager to be used to
250      *                   allocate objects.
251      */
252    InputSource
253    (
254        const   char* const systemId
255        , const char* const publicId
256        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
257    );
258
259    //@}
260
261
262
263
264
265private:
266    // -----------------------------------------------------------------------
267    //  Unimplemented constructors and operators
268    // -----------------------------------------------------------------------
269    InputSource(const InputSource&);
270    InputSource& operator=(const InputSource&);
271
272
273    // -----------------------------------------------------------------------
274    //  Private data members
275    //
276    //  fEncoding
277    //      This is the encoding to use. Usually this is null, which means
278    //      to use the information found in the file itself. But, if set,
279    //      this encoding will be used without question.
280    //
281    //  fPublicId
282    //      This is the optional public id for the input source. It can be
283    //      null if none is desired.
284    //
285    //  fSystemId
286    //      This is the system id for the input source. This is what is
287    //      actually used to open the source.
288    //
289    //  fFatalErrorIfNotFound
290    // -----------------------------------------------------------------------
291    MemoryManager* const fMemoryManager;
292    XMLCh*         fEncoding;
293    XMLCh*         fPublicId;
294    XMLCh*         fSystemId;
295    bool           fFatalErrorIfNotFound;
296};
297
298
299// ---------------------------------------------------------------------------
300//  InputSource: Getter methods
301// ---------------------------------------------------------------------------
302inline const XMLCh* InputSource::getEncoding() const
303{
304    return fEncoding;
305}
306
307inline const XMLCh* InputSource::getPublicId() const
308{
309    return fPublicId;
310}
311
312inline const XMLCh* InputSource::getSystemId() const
313{
314    return fSystemId;
315}
316
317inline bool InputSource::getIssueFatalErrorIfNotFound() const
318{
319    return fFatalErrorIfNotFound;
320}
321
322inline MemoryManager* InputSource::getMemoryManager() const
323{
324    return fMemoryManager;
325}
326
327// ---------------------------------------------------------------------------
328//  InputSource: Setter methods
329// ---------------------------------------------------------------------------
330inline void InputSource::setIssueFatalErrorIfNotFound(const bool flag)
331{
332    fFatalErrorIfNotFound = flag;
333}
334
335XERCES_CPP_NAMESPACE_END
336
337#endif
Note: See TracBrowser for help on using the repository browser.