[2674] | 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: DTDScanner.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | #if !defined(DTDSCANNER_HPP) |
---|
| 25 | #define DTDSCANNER_HPP |
---|
| 26 | |
---|
| 27 | #include <xercesc/validators/DTD/DTDGrammar.hpp> |
---|
| 28 | #include <xercesc/validators/DTD/DTDEntityDecl.hpp> |
---|
| 29 | |
---|
| 30 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 31 | |
---|
| 32 | class XMLScanner; |
---|
| 33 | |
---|
| 34 | /* |
---|
| 35 | * Default implementation of an XML DTD scanner. |
---|
| 36 | */ |
---|
| 37 | class DocTypeHandler; |
---|
| 38 | |
---|
| 39 | class VALIDATORS_EXPORT DTDScanner : public XMemory |
---|
| 40 | { |
---|
| 41 | public: |
---|
| 42 | // ----------------------------------------------------------------------- |
---|
| 43 | // Class specific types |
---|
| 44 | // |
---|
| 45 | // EntityExpRes |
---|
| 46 | // Returned from scanEntityRef() to indicate how the expanded text |
---|
| 47 | // was treated. |
---|
| 48 | // |
---|
| 49 | // IDTypes |
---|
| 50 | // Type of the ID |
---|
| 51 | // ----------------------------------------------------------------------- |
---|
| 52 | enum EntityExpRes |
---|
| 53 | { |
---|
| 54 | EntityExp_Failed |
---|
| 55 | , EntityExp_Pushed |
---|
| 56 | , EntityExp_Returned |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | enum IDTypes |
---|
| 60 | { |
---|
| 61 | IDType_Public |
---|
| 62 | , IDType_External |
---|
| 63 | , IDType_Either |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | // ----------------------------------------------------------------------- |
---|
| 69 | // Constructors and Destructor |
---|
| 70 | // ----------------------------------------------------------------------- |
---|
| 71 | DTDScanner |
---|
| 72 | ( |
---|
| 73 | DTDGrammar* dtdGrammar |
---|
| 74 | , DocTypeHandler* const docTypeHandler |
---|
| 75 | , MemoryManager* const grammarPoolMemoryManager |
---|
| 76 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 77 | ); |
---|
| 78 | virtual ~DTDScanner(); |
---|
| 79 | |
---|
| 80 | // ----------------------------------------------------------------------- |
---|
| 81 | // Getter methods |
---|
| 82 | // ----------------------------------------------------------------------- |
---|
| 83 | DocTypeHandler* getDocTypeHandler(); |
---|
| 84 | const DocTypeHandler* getDocTypeHandler() const; |
---|
| 85 | |
---|
| 86 | // ----------------------------------------------------------------------- |
---|
| 87 | // Setter methods |
---|
| 88 | // |
---|
| 89 | // setScannerInfo() is called by the scanner to tell the DTDScanner |
---|
| 90 | // about the stuff it needs to have access to. |
---|
| 91 | // ----------------------------------------------------------------------- |
---|
| 92 | void setScannerInfo |
---|
| 93 | ( |
---|
| 94 | XMLScanner* const owningScanner |
---|
| 95 | , ReaderMgr* const readerMgr |
---|
| 96 | , XMLBufferMgr* const bufMgr |
---|
| 97 | ); |
---|
| 98 | |
---|
| 99 | void setDocTypeHandler |
---|
| 100 | ( |
---|
| 101 | DocTypeHandler* const handlerToSet |
---|
| 102 | ); |
---|
| 103 | |
---|
| 104 | void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD); |
---|
| 105 | bool scanInternalSubset(); |
---|
| 106 | bool scanId |
---|
| 107 | ( |
---|
| 108 | XMLBuffer& pubIdToFill |
---|
| 109 | , XMLBuffer& sysIdToFill |
---|
| 110 | , const IDTypes whatKind |
---|
| 111 | ); |
---|
| 112 | |
---|
| 113 | private: |
---|
| 114 | // ----------------------------------------------------------------------- |
---|
| 115 | // Unimplemented constructors and operators |
---|
| 116 | // ----------------------------------------------------------------------- |
---|
| 117 | DTDScanner(const DTDScanner &); |
---|
| 118 | DTDScanner& operator = (const DTDScanner&); |
---|
| 119 | |
---|
| 120 | // ----------------------------------------------------------------------- |
---|
| 121 | // Private DTD scanning methods. These are all in XMLValidator2.cpp |
---|
| 122 | // ----------------------------------------------------------------------- |
---|
| 123 | bool checkForPERef |
---|
| 124 | ( |
---|
| 125 | const bool inLiteral |
---|
| 126 | , const bool inMarkup |
---|
| 127 | ); |
---|
| 128 | bool expandPERef |
---|
| 129 | ( |
---|
| 130 | const bool scanExternal |
---|
| 131 | , const bool inLiteral |
---|
| 132 | , const bool inMarkup |
---|
| 133 | , const bool throwEndOfExt = false |
---|
| 134 | ); |
---|
| 135 | bool getQuotedString(XMLBuffer& toFill); |
---|
| 136 | XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse); |
---|
| 137 | bool scanAttValue |
---|
| 138 | ( |
---|
| 139 | const XMLCh* const attrName |
---|
| 140 | , XMLBuffer& toFill |
---|
| 141 | , const XMLAttDef::AttTypes type |
---|
| 142 | ); |
---|
| 143 | void scanAttListDecl(); |
---|
| 144 | ContentSpecNode* scanChildren |
---|
| 145 | ( |
---|
| 146 | const DTDElementDecl& elemDecl |
---|
| 147 | , XMLBuffer& bufToUse |
---|
| 148 | ); |
---|
| 149 | bool scanCharRef(XMLCh& toFill, XMLCh& second); |
---|
| 150 | void scanComment(); |
---|
| 151 | bool scanContentSpec(DTDElementDecl& toFill); |
---|
| 152 | void scanDefaultDecl(DTDAttDef& toFill); |
---|
| 153 | void scanElementDecl(); |
---|
| 154 | void scanEntityDecl(); |
---|
| 155 | bool scanEntityDef(); |
---|
| 156 | bool scanEntityLiteral(XMLBuffer& toFill); |
---|
| 157 | bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl); |
---|
| 158 | EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped); |
---|
| 159 | bool scanEnumeration |
---|
| 160 | ( |
---|
| 161 | const DTDAttDef& attDef |
---|
| 162 | , XMLBuffer& toFill |
---|
| 163 | , const bool notation |
---|
| 164 | ); |
---|
| 165 | bool scanEq(); |
---|
| 166 | void scanIgnoredSection(); |
---|
| 167 | void scanMarkupDecl(const bool parseTextDecl); |
---|
| 168 | bool scanMixed(DTDElementDecl& toFill); |
---|
| 169 | void scanNotationDecl(); |
---|
| 170 | void scanPI(); |
---|
| 171 | bool scanPublicLiteral(XMLBuffer& toFill); |
---|
| 172 | bool scanSystemLiteral(XMLBuffer& toFill); |
---|
| 173 | void scanTextDecl(); |
---|
| 174 | bool isReadingExternalEntity(); |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | // ----------------------------------------------------------------------- |
---|
| 178 | // Private data members |
---|
| 179 | // |
---|
| 180 | // fDocTypeHandler |
---|
| 181 | // This holds the optional doc type handler that can be installed |
---|
| 182 | // and used to call back for all markup events. It is DTD specific. |
---|
| 183 | // |
---|
| 184 | // fDumAttDef |
---|
| 185 | // fDumElemDecl |
---|
| 186 | // fDumEntityDecl |
---|
| 187 | // These are dummy objects into which mark decls are parsed when |
---|
| 188 | // they are just overrides of previously declared markup decls. In |
---|
| 189 | // such situations, the first one wins but we need to have somewhere |
---|
| 190 | // to parse them into. So these are lazily created and used as needed |
---|
| 191 | // when such markup decls are seen. |
---|
| 192 | // |
---|
| 193 | // fInternalSubset |
---|
| 194 | // This is used to track whether we are in the internal subset or not, |
---|
| 195 | // in which case we are in the external subset. |
---|
| 196 | // |
---|
| 197 | // fNextAttrId |
---|
| 198 | // Since att defs are per-element, we don't have a validator wide |
---|
| 199 | // attribute def pool. So we use a simpler data structure in each |
---|
| 200 | // element decl to store its att defs, and we use this simple counter |
---|
| 201 | // to apply a unique id to each new attribute. |
---|
| 202 | // |
---|
| 203 | // fDTDGrammar |
---|
| 204 | // The DTD information we scanned like element decl, attribute decl |
---|
| 205 | // are stored in this Grammar. |
---|
| 206 | // |
---|
| 207 | // fBufMgr |
---|
| 208 | // This is the buffer manager of the scanner. This is provided as a |
---|
| 209 | // convenience so that the DTDScanner doesn't have to create its own |
---|
| 210 | // buffer manager during the parse process. |
---|
| 211 | // |
---|
| 212 | // fReaderMgr |
---|
| 213 | // This is a pointer to the reader manager that is being used by the scanner. |
---|
| 214 | // |
---|
| 215 | // fScanner |
---|
| 216 | // The pointer to the scanner to which this DTDScanner belongs |
---|
| 217 | // |
---|
| 218 | // fPEntityDeclPool |
---|
| 219 | // This is a pool of EntityDecl objects, which contains all of the |
---|
| 220 | // parameter entities that are declared in the DTD subsets. |
---|
| 221 | // |
---|
| 222 | // fEmptyNamespaceId |
---|
| 223 | // The uri for all DTD decls |
---|
| 224 | // |
---|
| 225 | // fDocTypeReaderId |
---|
| 226 | // The original reader in the fReaderMgr - to be compared against the |
---|
| 227 | // current reader to decide whether we are processing an external/internal |
---|
| 228 | // declaration |
---|
| 229 | // ----------------------------------------------------------------------- |
---|
| 230 | MemoryManager* fMemoryManager; |
---|
| 231 | MemoryManager* fGrammarPoolMemoryManager; |
---|
| 232 | DocTypeHandler* fDocTypeHandler; |
---|
| 233 | DTDAttDef* fDumAttDef; |
---|
| 234 | DTDElementDecl* fDumElemDecl; |
---|
| 235 | DTDEntityDecl* fDumEntityDecl; |
---|
| 236 | bool fInternalSubset; |
---|
| 237 | unsigned int fNextAttrId; |
---|
| 238 | DTDGrammar* fDTDGrammar; |
---|
| 239 | XMLBufferMgr* fBufMgr; |
---|
| 240 | ReaderMgr* fReaderMgr; |
---|
| 241 | XMLScanner* fScanner; |
---|
| 242 | NameIdPool<DTDEntityDecl>* fPEntityDeclPool; |
---|
| 243 | unsigned int fEmptyNamespaceId; |
---|
| 244 | unsigned int fDocTypeReaderId; |
---|
| 245 | }; |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | // --------------------------------------------------------------------------- |
---|
| 249 | // DTDScanner: Getter methods |
---|
| 250 | // --------------------------------------------------------------------------- |
---|
| 251 | inline DocTypeHandler* DTDScanner::getDocTypeHandler() |
---|
| 252 | { |
---|
| 253 | return fDocTypeHandler; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const |
---|
| 257 | { |
---|
| 258 | return fDocTypeHandler; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | // --------------------------------------------------------------------------- |
---|
| 263 | // DTDScanner: Setter methods |
---|
| 264 | // --------------------------------------------------------------------------- |
---|
| 265 | inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet) |
---|
| 266 | { |
---|
| 267 | fDocTypeHandler = handlerToSet; |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | // ----------------------------------------------------------------------- |
---|
| 271 | // Helper methods |
---|
| 272 | // ----------------------------------------------------------------------- |
---|
| 273 | inline bool DTDScanner::isReadingExternalEntity() { |
---|
| 274 | return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum()); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | XERCES_CPP_NAMESPACE_END |
---|
| 278 | |
---|
| 279 | #endif |
---|