# XQilla Simple API Documentation

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# SchemaValidatorFilter.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001, 2008,
    00003  *     DecisionSoft Limited. All rights reserved.
    00004  * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved.
    00005  *
    00006  *
    00007  * Licensed under the Apache License, Version 2.0 (the "License");
    00008  * you may not use this file except in compliance with the License.
    00009  * You may obtain a copy of the License at
    00010  *
    00011  *     http://www.apache.org/licenses/LICENSE-2.0
    00012  *
    00013  * Unless required by applicable law or agreed to in writing, software
    00014  * distributed under the License is distributed on an "AS IS" BASIS,
    00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00016  * See the License for the specific language governing permissions and
    00017  * limitations under the License.
    00018  */
    00019
    00020 #ifndef _SCHEMAVALIDATORFILTER_HPP
    00021 #define _SCHEMAVALIDATORFILTER_HPP
    00022
    00023 #include <vector>
    00024
    00025 #include <xqilla/events/EventHandler.hpp>
    00026
    00027 #include <xercesc/framework/XMLDocumentHandler.hpp>
    00028 #include <xercesc/framework/XMLErrorReporter.hpp>
    00029 #include <xercesc/validators/schema/SchemaValidator.hpp>
    00030 #include <xercesc/validators/schema/identity/IdentityConstraintHandler.hpp>
    00031 #include <xercesc/internal/XMLScanner.hpp>
    00032 #include <xercesc/util/RefHash3KeysIdPool.hpp>
    00033
    00034 class DynamicContext;
    00035 class LocationInfo;
    00036
    00037 #if _XERCES_VERSION < 30000
    00038 typedef XMLSSize_t XMLFileLoc;
    00039 #endif
    00040
    00048 class XQILLA_API SchemaValidatorFilter : public EventFilter,
    00049                                          public XERCES_CPP_NAMESPACE_QUALIFIER XMLScanner,
    00050                                          private XERCES_CPP_NAMESPACE_QUALIFIER XMLDocumentHandler,
    00051                                          private XERCES_CPP_NAMESPACE_QUALIFIER XMLErrorReporter
    00052 {
    00053 public:
    00054   SchemaValidatorFilter(bool strictValidation, EventHandler *next, XERCES_CPP_NAMESPACE_QUALIFIER GrammarResolver *grammarResolver,
    00055                         XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *mm, const LocationInfo *info);
    00056   virtual ~SchemaValidatorFilter();
    00057
    00058   void reset();
    00059
    00060   virtual void startDocumentEvent(const XMLCh *documentURI, const XMLCh *encoding);
    00061   virtual void endDocumentEvent();
    00062   virtual void startElementEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname);
    00063   virtual void endElementEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname,
    00064                                const XMLCh *typeURI, const XMLCh *typeName);
    00065   virtual void piEvent(const XMLCh *target, const XMLCh *value);
    00066   virtual void textEvent(const XMLCh *value);
    00067   virtual void textEvent(const XMLCh *chars, unsigned int length);
    00068   virtual void commentEvent(const XMLCh *value);
    00069   virtual void attributeEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname, const XMLCh *value,
    00070                               const XMLCh *typeURI, const XMLCh *typeName);
    00071   virtual void namespaceEvent(const XMLCh *prefix, const XMLCh *uri);
    00072
    00073 private:
    00074   // XMLScanner
    00075   virtual const XMLCh *getName() const { return 0; }
    00076   virtual XERCES_CPP_NAMESPACE_QUALIFIER NameIdPool<XERCES_CPP_NAMESPACE_QUALIFIER DTDEntityDecl> *getEntityDeclPool() { return 0; }
    00077   virtual const XERCES_CPP_NAMESPACE_QUALIFIER NameIdPool<XERCES_CPP_NAMESPACE_QUALIFIER DTDEntityDecl> *getEntityDeclPool() const { return 0; }
    00078 #if _XERCES_VERSION < 30100
    00079   virtual unsigned int resolveQName(const XMLCh *const qName, XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &prefixBufToFill,
    00080                                     const short mode, int &prefixColonPos);
    00081 #endif
    00082   virtual void scanDocument(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource &src) {}
    00083   virtual bool scanNext(XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken &toFill) { return false; }
    00084   virtual XERCES_CPP_NAMESPACE_QUALIFIER Grammar *loadGrammar(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource &src,
    00085                                                               const short grammarType, const bool toCache) { return 0; }
    00086
    00087   virtual void scanCDSection() {}
    00088   virtual void scanCharData(XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &toToUse) {}
    00089   virtual EntityExpRes scanEntityRef(const bool inAttVal, XMLCh &firstCh, XMLCh &secondCh,
    00090                                      bool &escaped) { return EntityExp_Returned; }
    00091   virtual void scanDocTypeDecl() {}
    00092   virtual void scanReset(const XERCES_CPP_NAMESPACE_QUALIFIER InputSource &src) {}
    00093   virtual void sendCharData(XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &toSend) {}
    00094
    00095   // XMLDocumentHandler
    00096   virtual void startDocument() {}
    00097   virtual void endDocument() {}
    00098   virtual void resetDocument() {}
    00099 #if _XERCES_VERSION >= 30000
    00100   virtual void startElement(const XERCES_CPP_NAMESPACE_QUALIFIER XMLElementDecl& elemDecl, const unsigned int urlId,
    00101                             const XMLCh* const elemPrefix,
    00102                             const XERCES_CPP_NAMESPACE_QUALIFIER RefVectorOf<XERCES_CPP_NAMESPACE_QUALIFIER XMLAttr>& attrList,
    00103                             const XMLSize_t attrCount, const bool isEmpty, const bool isRoot) {}
    00104   virtual void docCharacters(const XMLCh* const chars, const XMLSize_t length, const bool cdataSection);
    00105   virtual void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length, const bool cdataSection) {}
    00106 #else
    00107   virtual void startElement(const XERCES_CPP_NAMESPACE_QUALIFIER XMLElementDecl& elemDecl, const unsigned int urlId,
    00108                             const XMLCh* const elemPrefix,
    00109                             const XERCES_CPP_NAMESPACE_QUALIFIER RefVectorOf<XERCES_CPP_NAMESPACE_QUALIFIER XMLAttr>& attrList,
    00110                             const unsigned int attrCount, const bool isEmpty, const bool isRoot) {}
    00111   virtual void docCharacters(const XMLCh* const chars, const unsigned int length, const bool cdataSection);
    00112   virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length, const bool cdataSection) {}
    00113 #endif
    00114   virtual void endElement(const XERCES_CPP_NAMESPACE_QUALIFIER XMLElementDecl& elemDecl, const unsigned int urlId,
    00115                           const bool isRoot, const XMLCh* const elemPrefix=0) {}
    00116   virtual void docComment(const XMLCh* const comment) {}
    00117   virtual void docPI(const XMLCh* const target, const XMLCh* const data) {}
    00118   virtual void startEntityReference(const XERCES_CPP_NAMESPACE_QUALIFIER XMLEntityDecl& entDecl) {}
    00119   virtual void endEntityReference(const XERCES_CPP_NAMESPACE_QUALIFIER XMLEntityDecl& entDecl) {}
    00120   virtual void XMLDecl(const XMLCh* const versionStr, const XMLCh* const encodingStr, const XMLCh* const standaloneStr,
    00121                        const XMLCh* const actualEncodingStr) {}
    00122
    00123   // XMLErrorReporter
    00124   virtual void resetErrors() {}
    00125   virtual void error(const unsigned int errCode, const XMLCh* const errDomain, const XMLErrorReporter::ErrTypes type, const XMLCh* const errorText,
    00126                      const XMLCh* const systemId, const XMLCh* const publicId, const XMLFileLoc lineNum, const XMLFileLoc colNum);
    00127
    00128 private:
    00129   void processStartElement();
    00130   void processAttrs(XERCES_CPP_NAMESPACE_QUALIFIER XMLElementDecl *elemDecl);
    00131
    00132   bool switchGrammar(const XMLCh *uri);
    00133   bool laxElementValidation(XERCES_CPP_NAMESPACE_QUALIFIER QName* element,
    00134                             XERCES_CPP_NAMESPACE_QUALIFIER ContentLeafNameTypeVector* cv,
    00135                             const XERCES_CPP_NAMESPACE_QUALIFIER XMLContentModel *cm,
    00136                             unsigned int parentElemDepth);
    00137   bool anyAttributeValidation(XERCES_CPP_NAMESPACE_QUALIFIER SchemaAttDef* attWildCard, unsigned int uriId, bool& skipThisOne, bool& laxThisOne);
    00138   XERCES_CPP_NAMESPACE_QUALIFIER XMLElementDecl *createElementDecl(unsigned int uriId, unsigned int currentScope,
    00139                                                                    bool laxThisOne);
    00140
    00141   const LocationInfo *info_;
    00142
    00143   XERCES_CPP_NAMESPACE_QUALIFIER SchemaValidator *fSchemaValidator;
    00144   XERCES_CPP_NAMESPACE_QUALIFIER SchemaGrammar *fSchemaGrammar;
    00145   XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer fContent;
    00146   XERCES_CPP_NAMESPACE_QUALIFIER IdentityConstraintHandler *fICHandler;
    00147   XERCES_CPP_NAMESPACE_QUALIFIER RefHash3KeysIdPool<XERCES_CPP_NAMESPACE_QUALIFIER SchemaElementDecl> *fElemNonDeclPool;
    00148
    00149   bool strictValidation_;
    00150   bool errorOccurred_;
    00151
    00152   XERCES_CPP_NAMESPACE_QUALIFIER ElemStack::StackElem *parentStack_;
    00153   unsigned int elemDepth_;
    00154   XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer prefix_;
    00155   XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer uri_;
    00156   XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer localname_;
    00157   bool elementToProcess_;
    00158   const XMLCh *xsiType_;
    00159   unsigned int attrCount_;
    00160 };
    00161
    00162 #endif