[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2002 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: SGXMLScanner.hpp,v $
|
---|
| 59 | * Revision 1.16 2004/01/29 11:46:30 cargilld
|
---|
| 60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.15 2003/11/28 19:54:31 knoaman
|
---|
| 63 | * PSVIElement update
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.14 2003/11/27 22:52:37 knoaman
|
---|
| 66 | * PSVIElement implementation
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.13 2003/11/27 06:10:31 neilg
|
---|
| 69 | * PSVIAttribute implementation
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.12 2003/11/26 16:20:00 knoaman
|
---|
| 72 | * Store XSModel.
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.11 2003/11/24 05:09:38 neilg
|
---|
| 75 | * implement new, statless, method for detecting duplicate attributes
|
---|
| 76 | *
|
---|
| 77 | * Revision 1.10 2003/10/22 20:22:30 knoaman
|
---|
| 78 | * Prepare for annotation support.
|
---|
| 79 | *
|
---|
| 80 | * Revision 1.9 2003/09/22 19:51:41 neilg
|
---|
| 81 | * scanners should maintain their own pools of undeclared elements, rather than requiring grammars to do this. This makes grammar objects stateless with regard to validation.
|
---|
| 82 | *
|
---|
| 83 | * Revision 1.8 2003/07/10 19:47:23 peiyongz
|
---|
| 84 | * Stateless Grammar: Initialize scanner with grammarResolver,
|
---|
| 85 | * creating grammar through grammarPool
|
---|
| 86 | *
|
---|
| 87 | * Revision 1.7 2003/05/16 21:36:57 knoaman
|
---|
| 88 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
| 89 | *
|
---|
| 90 | * Revision 1.6 2003/05/15 18:26:29 knoaman
|
---|
| 91 | * Partial implementation of the configurable memory manager.
|
---|
| 92 | *
|
---|
| 93 | * Revision 1.5 2003/03/07 18:08:58 tng
|
---|
| 94 | * Return a reference instead of void for operator=
|
---|
| 95 | *
|
---|
| 96 | * Revision 1.4 2003/01/29 19:59:35 gareth
|
---|
| 97 | * we now detect when elements and attributes are validated/ the result of the validation and store that information.
|
---|
| 98 | *
|
---|
| 99 | * Revision 1.3 2003/01/15 15:49:49 knoaman
|
---|
| 100 | * Change constant declaration name to match its value.
|
---|
| 101 | *
|
---|
| 102 | * Revision 1.2 2003/01/13 16:30:18 knoaman
|
---|
| 103 | * [Bug 14469] Validator doesn't enforce xsd:key.
|
---|
| 104 | *
|
---|
| 105 | * Revision 1.1 2002/12/05 16:19:27 knoaman
|
---|
| 106 | * Initial check-in.
|
---|
| 107 | *
|
---|
| 108 | */
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | #if !defined(SGXMLSCANNER_HPP)
|
---|
| 112 | #define SGXMLSCANNER_HPP
|
---|
| 113 |
|
---|
| 114 | #include <xercesc/internal/XMLScanner.hpp>
|
---|
| 115 | #include <xercesc/util/KVStringPair.hpp>
|
---|
| 116 | #include <xercesc/util/ValueHashTableOf.hpp>
|
---|
| 117 | #include <xercesc/util/RefHash3KeysIdPool.hpp>
|
---|
| 118 | #include <xercesc/validators/common/Grammar.hpp>
|
---|
| 119 | #include <xercesc/validators/schema/SchemaElementDecl.hpp>
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 123 |
|
---|
| 124 | class SchemaGrammar;
|
---|
| 125 | class SchemaValidator;
|
---|
| 126 | class ValueStoreCache;
|
---|
| 127 | class XPathMatcherStack;
|
---|
| 128 | class FieldActivator;
|
---|
| 129 | class IdentityConstraint;
|
---|
| 130 | class ContentLeafNameTypeVector;
|
---|
| 131 | class SchemaAttDef;
|
---|
| 132 | class XMLContentModel;
|
---|
| 133 | class XSModel;
|
---|
| 134 | class PSVIAttributeList;
|
---|
| 135 | class PSVIElement;
|
---|
| 136 |
|
---|
| 137 | // This is a scanner class, which process XML Schema grammar.
|
---|
| 138 | class XMLPARSER_EXPORT SGXMLScanner : public XMLScanner
|
---|
| 139 | {
|
---|
| 140 | public :
|
---|
| 141 | // -----------------------------------------------------------------------
|
---|
| 142 | // Constructors and Destructor
|
---|
| 143 | // -----------------------------------------------------------------------
|
---|
| 144 | SGXMLScanner
|
---|
| 145 | (
|
---|
| 146 | XMLValidator* const valToAdopt
|
---|
| 147 | , GrammarResolver* const grammarResolver
|
---|
| 148 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 149 | );
|
---|
| 150 | SGXMLScanner
|
---|
| 151 | (
|
---|
| 152 | XMLDocumentHandler* const docHandler
|
---|
| 153 | , DocTypeHandler* const docTypeHandler
|
---|
| 154 | , XMLEntityHandler* const entityHandler
|
---|
| 155 | , XMLErrorReporter* const errReporter
|
---|
| 156 | , XMLValidator* const valToAdopt
|
---|
| 157 | , GrammarResolver* const grammarResolver
|
---|
| 158 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 159 | );
|
---|
| 160 | virtual ~SGXMLScanner();
|
---|
| 161 |
|
---|
| 162 | // -----------------------------------------------------------------------
|
---|
| 163 | // XMLScanner public virtual methods
|
---|
| 164 | // -----------------------------------------------------------------------
|
---|
| 165 | virtual const XMLCh* getName() const;
|
---|
| 166 | virtual NameIdPool<DTDEntityDecl>* getEntityDeclPool();
|
---|
| 167 | virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
|
---|
| 168 | virtual unsigned int resolveQName
|
---|
| 169 | (
|
---|
| 170 | const XMLCh* const qName
|
---|
| 171 | , XMLBuffer& prefixBufToFill
|
---|
| 172 | , const short mode
|
---|
| 173 | , int& prefixColonPos
|
---|
| 174 | );
|
---|
| 175 | virtual void scanDocument
|
---|
| 176 | (
|
---|
| 177 | const InputSource& src
|
---|
| 178 | );
|
---|
| 179 | virtual bool scanNext(XMLPScanToken& toFill);
|
---|
| 180 | virtual Grammar* loadGrammar
|
---|
| 181 | (
|
---|
| 182 | const InputSource& src
|
---|
| 183 | , const short grammarType
|
---|
| 184 | , const bool toCache = false
|
---|
| 185 | );
|
---|
| 186 |
|
---|
| 187 | private :
|
---|
| 188 | // -----------------------------------------------------------------------
|
---|
| 189 | // Unimplemented constructors and operators
|
---|
| 190 | // -----------------------------------------------------------------------
|
---|
| 191 | SGXMLScanner();
|
---|
| 192 | SGXMLScanner(const SGXMLScanner&);
|
---|
| 193 | SGXMLScanner& operator=(const SGXMLScanner&);
|
---|
| 194 |
|
---|
| 195 | // -----------------------------------------------------------------------
|
---|
| 196 | // XMLScanner virtual methods
|
---|
| 197 | // -----------------------------------------------------------------------
|
---|
| 198 | virtual void scanCDSection();
|
---|
| 199 | virtual void scanCharData(XMLBuffer& toToUse);
|
---|
| 200 | virtual EntityExpRes scanEntityRef
|
---|
| 201 | (
|
---|
| 202 | const bool inAttVal
|
---|
| 203 | , XMLCh& firstCh
|
---|
| 204 | , XMLCh& secondCh
|
---|
| 205 | , bool& escaped
|
---|
| 206 | );
|
---|
| 207 | virtual void scanDocTypeDecl();
|
---|
| 208 | virtual void scanReset(const InputSource& src);
|
---|
| 209 | virtual void sendCharData(XMLBuffer& toSend);
|
---|
| 210 |
|
---|
| 211 | // -----------------------------------------------------------------------
|
---|
| 212 | // Private helper methods
|
---|
| 213 | // -----------------------------------------------------------------------
|
---|
| 214 | void commonInit();
|
---|
| 215 | void cleanUp();
|
---|
| 216 | InputSource* resolveSystemId(const XMLCh* const sysId); // return owned by caller
|
---|
| 217 |
|
---|
| 218 | // Spaces are not allowed in URI, so %20 is used instead.
|
---|
| 219 | // Convert %20 to spaces before resolving the URI
|
---|
| 220 | void normalizeURI(const XMLCh* const systemURI, XMLBuffer& normalizedURI);
|
---|
| 221 |
|
---|
| 222 | unsigned int buildAttList
|
---|
| 223 | (
|
---|
| 224 | const RefVectorOf<KVStringPair>& providedAttrs
|
---|
| 225 | , const unsigned int attCount
|
---|
| 226 | , XMLElementDecl* elemDecl
|
---|
| 227 | , RefVectorOf<XMLAttr>& toFill
|
---|
| 228 | );
|
---|
| 229 | bool normalizeAttValue
|
---|
| 230 | (
|
---|
| 231 | const XMLAttDef* const attDef
|
---|
| 232 | , const XMLCh* const attrName
|
---|
| 233 | , const XMLCh* const value
|
---|
| 234 | , XMLBuffer& toFill
|
---|
| 235 | );
|
---|
| 236 | bool normalizeAttRawValue
|
---|
| 237 | (
|
---|
| 238 | const XMLCh* const attrName
|
---|
| 239 | , const XMLCh* const value
|
---|
| 240 | , XMLBuffer& toFill
|
---|
| 241 | );
|
---|
| 242 | unsigned int resolvePrefix
|
---|
| 243 | (
|
---|
| 244 | const XMLCh* const prefix
|
---|
| 245 | , const ElemStack::MapModes mode
|
---|
| 246 | );
|
---|
| 247 | unsigned int resolvePrefix
|
---|
| 248 | (
|
---|
| 249 | const XMLCh* const prefix
|
---|
| 250 | , XMLBuffer& uriBufToFill
|
---|
| 251 | , const ElemStack::MapModes mode
|
---|
| 252 | );
|
---|
| 253 | void updateNSMap
|
---|
| 254 | (
|
---|
| 255 | const XMLCh* const attrName
|
---|
| 256 | , const XMLCh* const attrValue
|
---|
| 257 | );
|
---|
| 258 | void scanRawAttrListforNameSpaces(int attCount);
|
---|
| 259 | void parseSchemaLocation(const XMLCh* const schemaLocationStr);
|
---|
| 260 | void resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri);
|
---|
| 261 | bool switchGrammar(const XMLCh* const newGrammarNameSpace);
|
---|
| 262 | bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv,
|
---|
| 263 | const XMLContentModel* const cm,
|
---|
| 264 | const unsigned int parentElemDepth);
|
---|
| 265 | bool anyAttributeValidation(SchemaAttDef* attWildCard,
|
---|
| 266 | unsigned int uriId,
|
---|
| 267 | bool& skipThisOne,
|
---|
| 268 | bool& laxThisOne);
|
---|
| 269 | void resizeElemState();
|
---|
| 270 |
|
---|
| 271 | // -----------------------------------------------------------------------
|
---|
| 272 | // Private scanning methods
|
---|
| 273 | // -----------------------------------------------------------------------
|
---|
| 274 | bool basicAttrValueScan
|
---|
| 275 | (
|
---|
| 276 | const XMLCh* const attrName
|
---|
| 277 | , XMLBuffer& toFill
|
---|
| 278 | );
|
---|
| 279 | unsigned int rawAttrScan
|
---|
| 280 | (
|
---|
| 281 | const XMLCh* const elemName
|
---|
| 282 | , RefVectorOf<KVStringPair>& toFill
|
---|
| 283 | , bool& isEmpty
|
---|
| 284 | );
|
---|
| 285 | bool scanAttValue
|
---|
| 286 | (
|
---|
| 287 | const XMLAttDef* const attDef
|
---|
| 288 | , XMLBuffer& toFill
|
---|
| 289 | );
|
---|
| 290 | bool scanContent();
|
---|
| 291 | void scanEndTag(bool& gotData);
|
---|
| 292 | bool scanStartTag(bool& gotData);
|
---|
| 293 |
|
---|
| 294 | // -----------------------------------------------------------------------
|
---|
| 295 | // IdentityConstraints Activation methods
|
---|
| 296 | // -----------------------------------------------------------------------
|
---|
| 297 | void activateSelectorFor(IdentityConstraint* const ic, const int initialDepth);
|
---|
| 298 |
|
---|
| 299 | // -----------------------------------------------------------------------
|
---|
| 300 | // Grammar preparsing methods
|
---|
| 301 | // -----------------------------------------------------------------------
|
---|
| 302 | Grammar* loadXMLSchemaGrammar(const InputSource& src, const bool toCache = false);
|
---|
| 303 |
|
---|
| 304 | // -----------------------------------------------------------------------
|
---|
| 305 | // PSVI handling methods
|
---|
| 306 | // -----------------------------------------------------------------------
|
---|
| 307 | void endElementPSVI(SchemaElementDecl* const elemDecl,
|
---|
| 308 | DatatypeValidator* const memberDV);
|
---|
| 309 | void resetPSVIElemContext();
|
---|
| 310 |
|
---|
| 311 | // -----------------------------------------------------------------------
|
---|
| 312 | // Data members
|
---|
| 313 | //
|
---|
| 314 | // fRawAttrList
|
---|
| 315 | // During the initial scan of the attributes we can only do a raw
|
---|
| 316 | // scan for key/value pairs. So this vector is used to store them
|
---|
| 317 | // until they can be processed (and put into fAttrList.)
|
---|
| 318 | //
|
---|
| 319 | // fSchemaValidator
|
---|
| 320 | // The Schema validator instance.
|
---|
| 321 | //
|
---|
| 322 | // fSeeXsi
|
---|
| 323 | // This flag indicates a schema has been seen.
|
---|
| 324 | //
|
---|
| 325 | // fElemState
|
---|
| 326 | // fElemStateSize
|
---|
| 327 | // Stores an element next state from DFA content model - used for
|
---|
| 328 | // wildcard validation
|
---|
| 329 | //
|
---|
| 330 | // fMatcherStack
|
---|
| 331 | // Stack of active XPath matchers for identity constraints. All
|
---|
| 332 | // active XPath matchers are notified of startElement, characters
|
---|
| 333 | // and endElement callbacks in order to perform their matches.
|
---|
| 334 | //
|
---|
| 335 | // fValueStoreCache
|
---|
| 336 | // Cache of value stores for identity constraint fields.
|
---|
| 337 | //
|
---|
| 338 | // fFieldActivator
|
---|
| 339 | // Activates fields within a certain scope when a selector matches
|
---|
| 340 | // its xpath.
|
---|
| 341 | // fElemNonDeclPool
|
---|
| 342 | // registry for elements without decls in the grammar
|
---|
| 343 | // fElemCount
|
---|
| 344 | // count of the number of start tags seen so far (starts at 1).
|
---|
| 345 | // Used for duplicate attribute detection/processing of required/defaulted attributes
|
---|
| 346 | // fAttDefRegistry
|
---|
| 347 | // mapping from XMLAttDef instances to the count of the last
|
---|
| 348 | // start tag where they were utilized.
|
---|
| 349 | // fUndeclaredAttrRegistryNS
|
---|
| 350 | // mapping of namespaceId/localName pairs to the count of the last
|
---|
| 351 | // start tag in which they occurred.
|
---|
| 352 | // fPSVIAttrList
|
---|
| 353 | // PSVI attribute list implementation that needs to be
|
---|
| 354 | // filled when a PSVIHandler is registered
|
---|
| 355 | //
|
---|
| 356 | // -----------------------------------------------------------------------
|
---|
| 357 | bool fSeeXsi;
|
---|
| 358 | Grammar::GrammarType fGrammarType;
|
---|
| 359 | unsigned int fElemStateSize;
|
---|
| 360 | unsigned int* fElemState;
|
---|
| 361 | XMLBuffer fContent;
|
---|
| 362 | ValueHashTableOf<XMLCh>* fEntityTable;
|
---|
| 363 | RefVectorOf<KVStringPair>* fRawAttrList;
|
---|
| 364 | SchemaGrammar* fSchemaGrammar;
|
---|
| 365 | SchemaValidator* fSchemaValidator;
|
---|
| 366 | XPathMatcherStack* fMatcherStack;
|
---|
| 367 | ValueStoreCache* fValueStoreCache;
|
---|
| 368 | FieldActivator* fFieldActivator;
|
---|
| 369 | RefHash3KeysIdPool<SchemaElementDecl>* fElemNonDeclPool;
|
---|
| 370 | unsigned int fElemCount;
|
---|
| 371 | RefHashTableOf<unsigned int>* fAttDefRegistry;
|
---|
| 372 | RefHash2KeysTableOf<unsigned int>* fUndeclaredAttrRegistryNS;
|
---|
| 373 | PSVIAttributeList * fPSVIAttrList;
|
---|
| 374 | XSModel* fModel;
|
---|
| 375 | PSVIElement* fPSVIElement;
|
---|
| 376 | ValueStackOf<bool>* fErrorStack;
|
---|
| 377 | PSVIElemContext fPSVIElemContext;
|
---|
| 378 | };
|
---|
| 379 |
|
---|
| 380 | inline const XMLCh* SGXMLScanner::getName() const
|
---|
| 381 | {
|
---|
| 382 | return XMLUni::fgSGXMLScanner;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | XERCES_CPP_NAMESPACE_END
|
---|
| 386 |
|
---|
| 387 | #endif
|
---|