|
||||
File indexing completed on 2025-01-30 10:27:05
0001 /* 0002 * Licensed to the Apache Software Foundation (ASF) under one or more 0003 * contributor license agreements. See the NOTICE file distributed with 0004 * this work for additional information regarding copyright ownership. 0005 * The ASF licenses this file to You under the Apache License, Version 2.0 0006 * (the "License"); you may not use this file except in compliance with 0007 * the License. You may obtain a copy of the License at 0008 * 0009 * http://www.apache.org/licenses/LICENSE-2.0 0010 * 0011 * Unless required by applicable law or agreed to in writing, software 0012 * distributed under the License is distributed on an "AS IS" BASIS, 0013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0014 * See the License for the specific language governing permissions and 0015 * limitations under the License. 0016 */ 0017 0018 /* 0019 * $Id$ 0020 */ 0021 0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLENTITYDECL_HPP) 0023 #define XERCESC_INCLUDE_GUARD_XMLENTITYDECL_HPP 0024 0025 #include <xercesc/util/XMemory.hpp> 0026 #include <xercesc/util/PlatformUtils.hpp> 0027 #include <xercesc/util/XMLString.hpp> 0028 #include <xercesc/internal/XSerializable.hpp> 0029 0030 XERCES_CPP_NAMESPACE_BEGIN 0031 0032 /** 0033 * This class defines that core information that defines an XML entity, no 0034 * matter what validator is used. Each validator will create a derivative 0035 * of this class which adds any extra information it requires. 0036 * 0037 * This class supports keyed collection semantics via the getKey() method 0038 * which extracts the key field, the entity name in this case. The name will 0039 * have whatever form is deemed appropriate for the type of validator in 0040 * use. 0041 * 0042 * When setting the fields of this class, you must make sure that you do 0043 * not set conflicting values. For instance, an internal entity cannot have 0044 * a notation name. And an external entity cannot have a value string. 0045 * These rules are defined by the XML specification. In most cases, these 0046 * objects are created by validator objects as they parse a DTD or Schema 0047 * or whatever, at which time they confirm the correctness of the data before 0048 * creating the entity decl object. 0049 */ 0050 class XMLPARSER_EXPORT XMLEntityDecl : public XSerializable, public XMemory 0051 { 0052 public: 0053 // ----------------------------------------------------------------------- 0054 // Constructors and Destructor 0055 // ----------------------------------------------------------------------- 0056 0057 /** @name Constructors */ 0058 //@{ 0059 0060 /** 0061 * Default Constructor 0062 */ 0063 XMLEntityDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0064 0065 /** Constructor with a const entity name 0066 * 0067 * @param entName The new name to give to this entity. 0068 * @param manager Pointer to the memory manager to be used to 0069 * allocate objects. 0070 */ 0071 XMLEntityDecl 0072 ( 0073 const XMLCh* const entName 0074 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0075 ); 0076 0077 /** 0078 * Constructor with a const entity name and value 0079 * 0080 * @param entName The new name to give to this entity. 0081 * @param value The new value to give to this entity name. 0082 * @param manager Pointer to the memory manager to be used to 0083 * allocate objects. 0084 */ 0085 XMLEntityDecl 0086 ( 0087 const XMLCh* const entName 0088 , const XMLCh* const value 0089 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0090 ); 0091 0092 /** 0093 * Constructor with a const entity name and single XMLCh value 0094 * 0095 * @param entName The new name to give to this entity. 0096 * @param value The new value to give to this entity name. 0097 * @param manager Pointer to the memory manager to be used to 0098 * allocate objects. 0099 */ 0100 XMLEntityDecl 0101 ( 0102 const XMLCh* const entName 0103 , const XMLCh value 0104 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0105 ); 0106 //@} 0107 0108 /** @name Destructor */ 0109 //@{ 0110 0111 /** 0112 * Default destructor 0113 */ 0114 virtual ~XMLEntityDecl(); 0115 0116 //@} 0117 0118 0119 // ----------------------------------------------------------------------- 0120 // Virtual entity decl interface 0121 // ----------------------------------------------------------------------- 0122 0123 /** @name The pure virtual methods in this interface. */ 0124 //@{ 0125 0126 /** Get the 'declared in internal subset' flag 0127 * 0128 * Gets the state of the flag which indicates whether the entity was 0129 * declared in the internal or external subset. Some structural 0130 * description languages might not have an internal subset concept, in 0131 * which case this will always return false. 0132 */ 0133 virtual bool getDeclaredInIntSubset() const = 0; 0134 0135 /** Get the 'is parameter entity' flag 0136 * 0137 * Gets the state of the flag which indicates whether this entity is 0138 * a parameter entity. If not, then its a general entity. 0139 */ 0140 virtual bool getIsParameter() const = 0; 0141 0142 /** Get the 'is special char entity' flag 0143 * 0144 * Gets the state of the flag that indicates whether this entity is 0145 * one of the special, intrinsically supported character entities. 0146 */ 0147 virtual bool getIsSpecialChar() const = 0; 0148 0149 //@} 0150 0151 0152 // ----------------------------------------------------------------------- 0153 // Getter methods 0154 // ----------------------------------------------------------------------- 0155 0156 /** @name Getter methods */ 0157 //@{ 0158 0159 /** 0160 * Gets the pool id of this entity. Validators maintain all decls in 0161 * pools, from which they can be quickly extracted via id. 0162 */ 0163 XMLSize_t getId() const; 0164 0165 /** 0166 * Returns a const pointer to the name of this entity decl. This name 0167 * will be in whatever format is appropriate for the type of validator 0168 * in use. 0169 */ 0170 const XMLCh* getName() const; 0171 0172 /** 0173 * Gets the notation name, if any, declared for this entity. If this 0174 * entity is not a notation type entity, it will be a null pointer. 0175 */ 0176 const XMLCh* getNotationName() const; 0177 0178 /** 0179 * Gets the public id declared for this entity. Public ids are optional 0180 * so it can be a null pointer. 0181 */ 0182 const XMLCh* getPublicId() const; 0183 0184 /** 0185 * Gets the system id declared for this entity. The system id is required 0186 * so this method should never return a null pointers. 0187 */ 0188 const XMLCh* getSystemId() const; 0189 0190 /** 0191 * Gets the base URI for this entity. 0192 */ 0193 const XMLCh* getBaseURI() const; 0194 0195 /** 0196 * This method returns the value of an internal entity. If this is not 0197 * an internal entity (i.e. its external), then this will be a null 0198 * pointer. 0199 */ 0200 const XMLCh* getValue() const; 0201 0202 /** 0203 * This method returns the number of characters in the value returned 0204 * by getValue(). If this entity is external, this will be zero since 0205 * an external entity has no internal value. 0206 */ 0207 XMLSize_t getValueLen() const; 0208 0209 /** 0210 * Indicates that this entity is an external entity. If not, then it is 0211 * assumed to be an internal entity, surprise. 0212 */ 0213 bool isExternal() const; 0214 0215 /** 0216 * Indicates whether this entity is unparsed. This is meaningless for 0217 * internal entities. Some external entities are unparsed in that they 0218 * refer to something other than XML source. 0219 */ 0220 bool isUnparsed() const; 0221 0222 /** Get the plugged-in memory manager 0223 * 0224 * This method returns the plugged-in memory manager user for dynamic 0225 * memory allocation/deallocation. 0226 * 0227 * @return the plugged-in memory manager 0228 */ 0229 MemoryManager* getMemoryManager() const; 0230 0231 //@} 0232 0233 0234 // ----------------------------------------------------------------------- 0235 // Setter methods 0236 // ----------------------------------------------------------------------- 0237 0238 /** @name Setter methods */ 0239 //@{ 0240 0241 /** 0242 * This method will set the entity name. The format of this name is 0243 * defined by the particular validator in use, since it will be the 0244 * one who creates entity definitions as it parses the DTD, Schema, 0245 * ect... 0246 * 0247 * @param entName The new name to give to this entity. 0248 */ 0249 void setName 0250 ( 0251 const XMLCh* const entName 0252 ); 0253 0254 /** 0255 * This method will mark whether the entity is external. 0256 * 0257 * @param value The new value for the 'is external' flag. 0258 */ 0259 void setIsExternal(bool value); 0260 0261 /** 0262 * This method will set the notation name for this entity. By setting 0263 * this, you are indicating that this is an unparsed external entity. 0264 * 0265 * @param newName The new notation name to give to this entity. 0266 */ 0267 void setNotationName(const XMLCh* const newName); 0268 0269 /** 0270 * This method will set a new public id on this entity. The public id 0271 * has no particular form and is purely for client consumption. 0272 * 0273 * @param newId The new public id to give to this entity. 0274 */ 0275 void setPublicId(const XMLCh* const newId); 0276 0277 /** 0278 * This method will set a new sysetm id on this entity. This will 0279 * then control where the source for this entity lives. If it is 0280 * an internal entity, then the system id is only for bookkeeping 0281 * purposes, and to allow any external entities referenced from 0282 * within the entity to be correctly resolved. 0283 * 0284 * @param newId The new system id to give to the entity. 0285 */ 0286 void setSystemId(const XMLCh* const newId); 0287 0288 /** 0289 * This method will set a new baseURI on this entity. This will 0290 * then control the URI used to resolve the relative system Id. 0291 * 0292 * @param newId The new base URI to give to the entity. 0293 */ 0294 void setBaseURI(const XMLCh* const newId); 0295 0296 /** 0297 * This method will set a new value for this entity. This is only 0298 * valid if the entity is to be an internal entity. By setting this 0299 * field, you are indicating that the entity is internal. 0300 * 0301 * @param newValue The new value to give to this entity. 0302 */ 0303 void setValue(const XMLCh* const newValue); 0304 0305 //@} 0306 0307 /* For internal use only */ 0308 void setId(const XMLSize_t newId); 0309 0310 0311 // ----------------------------------------------------------------------- 0312 // Support named pool syntax 0313 // ----------------------------------------------------------------------- 0314 0315 /** @name Setter methods */ 0316 //@{ 0317 0318 /** 0319 * This method allows objects of this class to be used within a standard 0320 * keyed collection used commonly within the parser system. The collection 0321 * calls this method to get the key (usually to hash it) by which the 0322 * object is to be stored. 0323 */ 0324 const XMLCh* getKey() const; 0325 0326 //@} 0327 0328 /*** 0329 * Support for Serialization/De-serialization 0330 ***/ 0331 DECL_XSERIALIZABLE(XMLEntityDecl) 0332 0333 private : 0334 // ----------------------------------------------------------------------- 0335 // Unimplemented constructors and operators 0336 // ----------------------------------------------------------------------- 0337 XMLEntityDecl(const XMLEntityDecl&); 0338 XMLEntityDecl& operator=(XMLEntityDecl&); 0339 0340 0341 // ----------------------------------------------------------------------- 0342 // XMLEntityDecl: Private helper methods 0343 // ----------------------------------------------------------------------- 0344 void cleanUp(); 0345 0346 0347 // ----------------------------------------------------------------------- 0348 // Private data members 0349 // 0350 // fId 0351 // This is the unique id given to this entity decl. 0352 // 0353 // fName 0354 // The name of the entity. Entity names are never namespace based. 0355 // 0356 // fNotationName 0357 // The optional notation of the entity. If there was none, then its 0358 // empty. 0359 // 0360 // fPublicId 0361 // The public id of the entity, which can be empty. 0362 // 0363 // fSystemId 0364 // The system id of the entity. 0365 // 0366 // fValue 0367 // fValueLen 0368 // The entity's value and length, which is only valid if its an 0369 // internal style entity. 0370 // 0371 // fBaseURI 0372 // The base URI of the entity. According to XML InfoSet, such value 0373 // is the URI where it is declared (NOT referenced). 0374 // ----------------------------------------------------------------------- 0375 XMLSize_t fId; 0376 XMLSize_t fValueLen; 0377 XMLCh* fValue; 0378 XMLCh* fName; 0379 XMLCh* fNotationName; 0380 XMLCh* fPublicId; 0381 XMLCh* fSystemId; 0382 XMLCh* fBaseURI; 0383 bool fIsExternal; 0384 MemoryManager* fMemoryManager; 0385 }; 0386 0387 0388 // --------------------------------------------------------------------------- 0389 // XMLEntityDecl: Getter methods 0390 // --------------------------------------------------------------------------- 0391 inline XMLSize_t XMLEntityDecl::getId() const 0392 { 0393 return fId; 0394 } 0395 0396 inline const XMLCh* XMLEntityDecl::getName() const 0397 { 0398 return fName; 0399 } 0400 0401 inline const XMLCh* XMLEntityDecl::getNotationName() const 0402 { 0403 return fNotationName; 0404 } 0405 0406 inline const XMLCh* XMLEntityDecl::getPublicId() const 0407 { 0408 return fPublicId; 0409 } 0410 0411 inline const XMLCh* XMLEntityDecl::getSystemId() const 0412 { 0413 return fSystemId; 0414 } 0415 0416 inline const XMLCh* XMLEntityDecl::getBaseURI() const 0417 { 0418 return fBaseURI; 0419 } 0420 0421 inline const XMLCh* XMLEntityDecl::getValue() const 0422 { 0423 return fValue; 0424 } 0425 0426 inline XMLSize_t XMLEntityDecl::getValueLen() const 0427 { 0428 return fValueLen; 0429 } 0430 0431 inline bool XMLEntityDecl::isExternal() const 0432 { 0433 return fIsExternal; 0434 } 0435 0436 inline bool XMLEntityDecl::isUnparsed() const 0437 { 0438 // If it has a notation, its unparsed 0439 return (fNotationName != 0); 0440 } 0441 0442 inline MemoryManager* XMLEntityDecl::getMemoryManager() const 0443 { 0444 return fMemoryManager; 0445 } 0446 0447 // --------------------------------------------------------------------------- 0448 // XMLEntityDecl: Setter methods 0449 // --------------------------------------------------------------------------- 0450 inline void XMLEntityDecl::setId(const XMLSize_t newId) 0451 { 0452 fId = newId; 0453 } 0454 0455 inline void XMLEntityDecl::setIsExternal(bool value) 0456 { 0457 fIsExternal = value; 0458 } 0459 0460 inline void XMLEntityDecl::setNotationName(const XMLCh* const newName) 0461 { 0462 if (fNotationName) 0463 fMemoryManager->deallocate(fNotationName); 0464 0465 fNotationName = XMLString::replicate(newName, fMemoryManager); 0466 } 0467 0468 inline void XMLEntityDecl::setPublicId(const XMLCh* const newId) 0469 { 0470 if (fPublicId) 0471 fMemoryManager->deallocate(fPublicId); 0472 0473 fPublicId = XMLString::replicate(newId, fMemoryManager); 0474 } 0475 0476 inline void XMLEntityDecl::setSystemId(const XMLCh* const newId) 0477 { 0478 if (fSystemId) 0479 fMemoryManager->deallocate(fSystemId); 0480 0481 fSystemId = XMLString::replicate(newId, fMemoryManager); 0482 } 0483 0484 inline void XMLEntityDecl::setBaseURI(const XMLCh* const newId) 0485 { 0486 if (fBaseURI) 0487 fMemoryManager->deallocate(fBaseURI); 0488 0489 fBaseURI = XMLString::replicate(newId, fMemoryManager); 0490 } 0491 0492 inline void XMLEntityDecl::setValue(const XMLCh* const newValue) 0493 { 0494 if (fValue) 0495 fMemoryManager->deallocate(fValue); 0496 0497 fValue = XMLString::replicate(newValue, fMemoryManager); 0498 fValueLen = XMLString::stringLen(newValue); 0499 } 0500 0501 0502 // --------------------------------------------------------------------------- 0503 // XMLEntityDecl: Support named pool syntax 0504 // --------------------------------------------------------------------------- 0505 inline const XMLCh* XMLEntityDecl::getKey() const 0506 { 0507 return fName; 0508 } 0509 0510 XERCES_CPP_NAMESPACE_END 0511 0512 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |