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