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: XMLEntityDecl.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(XMLENTITYDECL_HPP) |
---|
23 | #define XMLENTITYDECL_HPP |
---|
24 | |
---|
25 | #include <xercesc/util/XMemory.hpp> |
---|
26 | #include <xercesc/util/PlatformUtils.hpp> |
---|
27 | #include <xercesc/util/XMLString.hpp> |
---|
28 | #include <xercesc/internal/XSerializable.hpp> |
---|
29 | |
---|
30 | XERCES_CPP_NAMESPACE_BEGIN |
---|
31 | |
---|
32 | /** |
---|
33 | * This class defines that core information that defines an XML entity, no |
---|
34 | * matter what validator is used. Each validator will create a derivative |
---|
35 | * of this class which adds any extra information it requires. |
---|
36 | * |
---|
37 | * This class supports keyed collection semantics via the getKey() method |
---|
38 | * which extracts the key field, the entity name in this case. The name will |
---|
39 | * have whatever form is deemed appropriate for the type of validator in |
---|
40 | * use. |
---|
41 | * |
---|
42 | * When setting the fields of this class, you must make sure that you do |
---|
43 | * not set conflicting values. For instance, an internal entity cannot have |
---|
44 | * a notation name. And an external entity cannot have a value string. |
---|
45 | * These rules are defined by the XML specification. In most cases, these |
---|
46 | * objects are created by validator objects as they parse a DTD or Schema |
---|
47 | * or whatever, at which time they confirm the correctness of the data before |
---|
48 | * creating the entity decl object. |
---|
49 | */ |
---|
50 | class XMLPARSER_EXPORT XMLEntityDecl : public XSerializable, public XMemory |
---|
51 | { |
---|
52 | public: |
---|
53 | // ----------------------------------------------------------------------- |
---|
54 | // Constructors and Destructor |
---|
55 | // ----------------------------------------------------------------------- |
---|
56 | |
---|
57 | /** @name Constructors */ |
---|
58 | //@{ |
---|
59 | |
---|
60 | /** |
---|
61 | * Deafult Constructor |
---|
62 | */ |
---|
63 | XMLEntityDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
64 | |
---|
65 | /** Constructor with a const entity name |
---|
66 | * |
---|
67 | * @param entName The new name to give to this entity. |
---|
68 | * @param manager Pointer to the memory manager to be used to |
---|
69 | * allocate objects. |
---|
70 | */ |
---|
71 | XMLEntityDecl |
---|
72 | ( |
---|
73 | const XMLCh* const entName |
---|
74 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
75 | ); |
---|
76 | |
---|
77 | /** |
---|
78 | * Constructor with a const entity name and value |
---|
79 | * |
---|
80 | * @param entName The new name to give to this entity. |
---|
81 | * @param value The new value to give to this entity name. |
---|
82 | * @param manager Pointer to the memory manager to be used to |
---|
83 | * allocate objects. |
---|
84 | */ |
---|
85 | XMLEntityDecl |
---|
86 | ( |
---|
87 | const XMLCh* const entName |
---|
88 | , const XMLCh* const value |
---|
89 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
90 | ); |
---|
91 | |
---|
92 | /** |
---|
93 | * Constructor with a const entity name and single XMLCh value |
---|
94 | * |
---|
95 | * @param entName The new name to give to this entity. |
---|
96 | * @param value The new value to give to this entity name. |
---|
97 | * @param manager Pointer to the memory manager to be used to |
---|
98 | * allocate objects. |
---|
99 | */ |
---|
100 | XMLEntityDecl |
---|
101 | ( |
---|
102 | const XMLCh* const entName |
---|
103 | , const XMLCh value |
---|
104 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
105 | ); |
---|
106 | //@} |
---|
107 | |
---|
108 | /** @name Destructor */ |
---|
109 | //@{ |
---|
110 | |
---|
111 | /** |
---|
112 | * Default destructor |
---|
113 | */ |
---|
114 | virtual ~XMLEntityDecl(); |
---|
115 | |
---|
116 | //@} |
---|
117 | |
---|
118 | |
---|
119 | // ----------------------------------------------------------------------- |
---|
120 | // Virtual entity decl interface |
---|
121 | // ----------------------------------------------------------------------- |
---|
122 | |
---|
123 | /** @name The pure virtual methods in this interface. */ |
---|
124 | //@{ |
---|
125 | |
---|
126 | /** Get the 'declared in internal subset' flag |
---|
127 | * |
---|
128 | * Gets the state of the flag which indicates whether the entity was |
---|
129 | * declared in the internal or external subset. Some structural |
---|
130 | * description languages might not have an internal subset concept, in |
---|
131 | * which case this will always return false. |
---|
132 | */ |
---|
133 | virtual bool getDeclaredInIntSubset() const = 0; |
---|
134 | |
---|
135 | /** Get the 'is parameter entity' flag |
---|
136 | * |
---|
137 | * Gets the state of the flag which indicates whether this entity is |
---|
138 | * a parameter entity. If not, then its a general entity. |
---|
139 | */ |
---|
140 | virtual bool getIsParameter() const = 0; |
---|
141 | |
---|
142 | /** Get the 'is special char entity' flag |
---|
143 | * |
---|
144 | * Gets the state of the flag that indicates whether this entity is |
---|
145 | * one of the special, intrinsically supported character entities. |
---|
146 | */ |
---|
147 | virtual bool getIsSpecialChar() const = 0; |
---|
148 | |
---|
149 | //@} |
---|
150 | |
---|
151 | |
---|
152 | // ----------------------------------------------------------------------- |
---|
153 | // Getter methods |
---|
154 | // ----------------------------------------------------------------------- |
---|
155 | |
---|
156 | /** @name Getter methods */ |
---|
157 | //@{ |
---|
158 | |
---|
159 | /** |
---|
160 | * Gets the pool id of this entity. Validators maintain all decls in |
---|
161 | * pools, from which they can be quickly extracted via id. |
---|
162 | */ |
---|
163 | unsigned int getId() const; |
---|
164 | |
---|
165 | /** |
---|
166 | * Returns a const pointer to the name of this entity decl. This name |
---|
167 | * will be in whatever format is appropriate for the type of validator |
---|
168 | * in use. |
---|
169 | */ |
---|
170 | const XMLCh* getName() const; |
---|
171 | |
---|
172 | /** |
---|
173 | * Gets the notation name, if any, declared for this entity. If this |
---|
174 | * entity is not a notation type entity, it will be a null pointer. |
---|
175 | */ |
---|
176 | const XMLCh* getNotationName() const; |
---|
177 | |
---|
178 | /** |
---|
179 | * Gets the public id declared for this entity. Public ids are optional |
---|
180 | * so it can be a null pointer. |
---|
181 | */ |
---|
182 | const XMLCh* getPublicId() const; |
---|
183 | |
---|
184 | /** |
---|
185 | * Gets the system id declared for this entity. The system id is required |
---|
186 | * so this method should never return a null pointers. |
---|
187 | */ |
---|
188 | const XMLCh* getSystemId() const; |
---|
189 | |
---|
190 | /** |
---|
191 | * Gets the base URI for this entity. |
---|
192 | */ |
---|
193 | const XMLCh* getBaseURI() const; |
---|
194 | |
---|
195 | /** |
---|
196 | * This method returns the value of an internal entity. If this is not |
---|
197 | * an internal entity (i.e. its external), then this will be a null |
---|
198 | * pointer. |
---|
199 | */ |
---|
200 | const XMLCh* getValue() const; |
---|
201 | |
---|
202 | /** |
---|
203 | * This method returns the number of characters in the value returned |
---|
204 | * by getValue(). If this entity is external, this will be zero since |
---|
205 | * an external entity has no internal value. |
---|
206 | */ |
---|
207 | unsigned int getValueLen() const; |
---|
208 | |
---|
209 | /** |
---|
210 | * Indicates that this entity is an external entity. If not, then it is |
---|
211 | * assumed to be an internal entity, suprise. |
---|
212 | */ |
---|
213 | bool isExternal() const; |
---|
214 | |
---|
215 | /** |
---|
216 | * Indicates whether this entity is unparsed. This is meaningless for |
---|
217 | * internal entities. Some external entities are unparsed in that they |
---|
218 | * refer to something other than XML source. |
---|
219 | */ |
---|
220 | bool isUnparsed() const; |
---|
221 | |
---|
222 | /** Get the plugged-in memory manager |
---|
223 | * |
---|
224 | * This method returns the plugged-in memory manager user for dynamic |
---|
225 | * memory allocation/deallocation. |
---|
226 | * |
---|
227 | * @return the plugged-in memory manager |
---|
228 | */ |
---|
229 | MemoryManager* getMemoryManager() const; |
---|
230 | |
---|
231 | //@} |
---|
232 | |
---|
233 | |
---|
234 | // ----------------------------------------------------------------------- |
---|
235 | // Setter methods |
---|
236 | // ----------------------------------------------------------------------- |
---|
237 | |
---|
238 | /** @name Setter methods */ |
---|
239 | //@{ |
---|
240 | |
---|
241 | /** |
---|
242 | * This method will set the entity name. The format of this name is |
---|
243 | * defined by the particular validator in use, since it will be the |
---|
244 | * one who creates entity definitions as it parses the DTD, Schema, |
---|
245 | * ect... |
---|
246 | * |
---|
247 | * @param entName The new name to give to this entity. |
---|
248 | */ |
---|
249 | void setName |
---|
250 | ( |
---|
251 | const XMLCh* const entName |
---|
252 | ); |
---|
253 | |
---|
254 | /** |
---|
255 | * This method will set the notation name for this entity. By setting |
---|
256 | * this, you are indicating that this is an unparsed external entity. |
---|
257 | * |
---|
258 | * @param newName The new notation name to give to this entity. |
---|
259 | */ |
---|
260 | void setNotationName(const XMLCh* const newName); |
---|
261 | |
---|
262 | /** |
---|
263 | * This method will set a new public id on this entity. The public id |
---|
264 | * has no particular form and is purely for client consumption. |
---|
265 | * |
---|
266 | * @param newId The new public id to give to this entity. |
---|
267 | */ |
---|
268 | void setPublicId(const XMLCh* const newId); |
---|
269 | |
---|
270 | /** |
---|
271 | * This method will set a new sysetm id on this entity. This will |
---|
272 | * then control where the source for this entity lives. If it is |
---|
273 | * an internal entity, then the system id is only for bookkeeping |
---|
274 | * purposes, and to allow any external entities referenced from |
---|
275 | * within the entity to be correctly resolved. |
---|
276 | * |
---|
277 | * @param newId The new system id to give to the entity. |
---|
278 | */ |
---|
279 | void setSystemId(const XMLCh* const newId); |
---|
280 | |
---|
281 | /** |
---|
282 | * This method will set a new baseURI on this entity. This will |
---|
283 | * then control the URI used to resolve the relative system Id. |
---|
284 | * |
---|
285 | * @param newId The new base URI to give to the entity. |
---|
286 | */ |
---|
287 | void setBaseURI(const XMLCh* const newId); |
---|
288 | |
---|
289 | /** |
---|
290 | * This method will set a new value for this entity. This is only |
---|
291 | * valid if the entity is to be an internal entity. By setting this |
---|
292 | * field, you are indicating that the entity is internal. |
---|
293 | * |
---|
294 | * @param newValue The new value to give to this entity. |
---|
295 | */ |
---|
296 | void setValue(const XMLCh* const newValue); |
---|
297 | |
---|
298 | //@} |
---|
299 | |
---|
300 | /* For internal use only */ |
---|
301 | void setId(const unsigned int newId); |
---|
302 | |
---|
303 | |
---|
304 | // ----------------------------------------------------------------------- |
---|
305 | // Support named pool syntax |
---|
306 | // ----------------------------------------------------------------------- |
---|
307 | |
---|
308 | /** @name Setter methods */ |
---|
309 | //@{ |
---|
310 | |
---|
311 | /** |
---|
312 | * This method allows objects of this class to be used within a standard |
---|
313 | * keyed collection used commonly within the parser system. The collection |
---|
314 | * calls this method to get the key (usually to hash it) by which the |
---|
315 | * object is to be stored. |
---|
316 | */ |
---|
317 | const XMLCh* getKey() const; |
---|
318 | |
---|
319 | //@} |
---|
320 | |
---|
321 | /*** |
---|
322 | * Support for Serialization/De-serialization |
---|
323 | ***/ |
---|
324 | DECL_XSERIALIZABLE(XMLEntityDecl) |
---|
325 | |
---|
326 | private : |
---|
327 | // ----------------------------------------------------------------------- |
---|
328 | // Unimplemented constructors and operators |
---|
329 | // ----------------------------------------------------------------------- |
---|
330 | XMLEntityDecl(const XMLEntityDecl&); |
---|
331 | XMLEntityDecl& operator=(XMLEntityDecl&); |
---|
332 | |
---|
333 | |
---|
334 | // ----------------------------------------------------------------------- |
---|
335 | // XMLEntityDecl: Private helper methods |
---|
336 | // ----------------------------------------------------------------------- |
---|
337 | void cleanUp(); |
---|
338 | |
---|
339 | |
---|
340 | // ----------------------------------------------------------------------- |
---|
341 | // Private data members |
---|
342 | // |
---|
343 | // fId |
---|
344 | // This is the unique id given to this entity decl. |
---|
345 | // |
---|
346 | // fName |
---|
347 | // The name of the enitity. Entity names are never namespace based. |
---|
348 | // |
---|
349 | // fNotationName |
---|
350 | // The optional notation of the entity. If there was none, then its |
---|
351 | // empty. |
---|
352 | // |
---|
353 | // fPublicId |
---|
354 | // The public id of the entity, which can be empty. |
---|
355 | // |
---|
356 | // fSystemId |
---|
357 | // The system id of the entity. |
---|
358 | // |
---|
359 | // fValue |
---|
360 | // fValueLen |
---|
361 | // The entity's value and length, which is only valid if its an |
---|
362 | // internal style entity. |
---|
363 | // |
---|
364 | // fBaseURI |
---|
365 | // The base URI of the entity. According to XML InfoSet, such value |
---|
366 | // is the URI where it is declared (NOT referenced). |
---|
367 | // ----------------------------------------------------------------------- |
---|
368 | unsigned int fId; |
---|
369 | unsigned int fValueLen; |
---|
370 | XMLCh* fValue; |
---|
371 | XMLCh* fName; |
---|
372 | XMLCh* fNotationName; |
---|
373 | XMLCh* fPublicId; |
---|
374 | XMLCh* fSystemId; |
---|
375 | XMLCh* fBaseURI; |
---|
376 | MemoryManager* fMemoryManager; |
---|
377 | }; |
---|
378 | |
---|
379 | |
---|
380 | // --------------------------------------------------------------------------- |
---|
381 | // XMLEntityDecl: Getter methods |
---|
382 | // --------------------------------------------------------------------------- |
---|
383 | inline unsigned int XMLEntityDecl::getId() const |
---|
384 | { |
---|
385 | return fId; |
---|
386 | } |
---|
387 | |
---|
388 | inline const XMLCh* XMLEntityDecl::getName() const |
---|
389 | { |
---|
390 | return fName; |
---|
391 | } |
---|
392 | |
---|
393 | inline const XMLCh* XMLEntityDecl::getNotationName() const |
---|
394 | { |
---|
395 | return fNotationName; |
---|
396 | } |
---|
397 | |
---|
398 | inline const XMLCh* XMLEntityDecl::getPublicId() const |
---|
399 | { |
---|
400 | return fPublicId; |
---|
401 | } |
---|
402 | |
---|
403 | inline const XMLCh* XMLEntityDecl::getSystemId() const |
---|
404 | { |
---|
405 | return fSystemId; |
---|
406 | } |
---|
407 | |
---|
408 | inline const XMLCh* XMLEntityDecl::getBaseURI() const |
---|
409 | { |
---|
410 | return fBaseURI; |
---|
411 | } |
---|
412 | |
---|
413 | inline const XMLCh* XMLEntityDecl::getValue() const |
---|
414 | { |
---|
415 | return fValue; |
---|
416 | } |
---|
417 | |
---|
418 | inline unsigned int XMLEntityDecl::getValueLen() const |
---|
419 | { |
---|
420 | return fValueLen; |
---|
421 | } |
---|
422 | |
---|
423 | inline bool XMLEntityDecl::isExternal() const |
---|
424 | { |
---|
425 | // If it has a system or public id, its external |
---|
426 | return ((fPublicId != 0) || (fSystemId != 0)); |
---|
427 | } |
---|
428 | |
---|
429 | inline bool XMLEntityDecl::isUnparsed() const |
---|
430 | { |
---|
431 | // If it has a notation, its unparsed |
---|
432 | return (fNotationName != 0); |
---|
433 | } |
---|
434 | |
---|
435 | inline MemoryManager* XMLEntityDecl::getMemoryManager() const |
---|
436 | { |
---|
437 | return fMemoryManager; |
---|
438 | } |
---|
439 | |
---|
440 | // --------------------------------------------------------------------------- |
---|
441 | // XMLEntityDecl: Setter methods |
---|
442 | // --------------------------------------------------------------------------- |
---|
443 | inline void XMLEntityDecl::setId(const unsigned int newId) |
---|
444 | { |
---|
445 | fId = newId; |
---|
446 | } |
---|
447 | |
---|
448 | inline void XMLEntityDecl::setNotationName(const XMLCh* const newName) |
---|
449 | { |
---|
450 | if (fNotationName) |
---|
451 | fMemoryManager->deallocate(fNotationName); |
---|
452 | |
---|
453 | fNotationName = XMLString::replicate(newName, fMemoryManager); |
---|
454 | } |
---|
455 | |
---|
456 | inline void XMLEntityDecl::setPublicId(const XMLCh* const newId) |
---|
457 | { |
---|
458 | if (fPublicId) |
---|
459 | fMemoryManager->deallocate(fPublicId); |
---|
460 | |
---|
461 | fPublicId = XMLString::replicate(newId, fMemoryManager); |
---|
462 | } |
---|
463 | |
---|
464 | inline void XMLEntityDecl::setSystemId(const XMLCh* const newId) |
---|
465 | { |
---|
466 | if (fSystemId) |
---|
467 | fMemoryManager->deallocate(fSystemId); |
---|
468 | |
---|
469 | fSystemId = XMLString::replicate(newId, fMemoryManager); |
---|
470 | } |
---|
471 | |
---|
472 | inline void XMLEntityDecl::setBaseURI(const XMLCh* const newId) |
---|
473 | { |
---|
474 | if (fBaseURI) |
---|
475 | fMemoryManager->deallocate(fBaseURI); |
---|
476 | |
---|
477 | fBaseURI = XMLString::replicate(newId, fMemoryManager); |
---|
478 | } |
---|
479 | |
---|
480 | inline void XMLEntityDecl::setValue(const XMLCh* const newValue) |
---|
481 | { |
---|
482 | if (fValue) |
---|
483 | fMemoryManager->deallocate(fValue); |
---|
484 | |
---|
485 | fValue = XMLString::replicate(newValue, fMemoryManager); |
---|
486 | fValueLen = XMLString::stringLen(newValue); |
---|
487 | } |
---|
488 | |
---|
489 | |
---|
490 | // --------------------------------------------------------------------------- |
---|
491 | // XMLEntityDecl: Support named pool syntax |
---|
492 | // --------------------------------------------------------------------------- |
---|
493 | inline const XMLCh* XMLEntityDecl::getKey() const |
---|
494 | { |
---|
495 | return fName; |
---|
496 | } |
---|
497 | |
---|
498 | XERCES_CPP_NAMESPACE_END |
---|
499 | |
---|
500 | #endif |
---|