listdatatypevalidator.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 486 行 · 第 1/2 页

CPP
486
字号
/* * Copyright 2001,2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: ListDatatypeValidator.cpp,v 1.23 2004/09/08 13:56:53 peiyongz Exp $ * $Log: ListDatatypeValidator.cpp,v $ * Revision 1.23  2004/09/08 13:56:53  peiyongz * Apache License Version 2.0 * * Revision 1.22  2004/01/29 11:51:22  cargilld * Code cleanup changes to get rid of various compiler diagnostic messages. * * Revision 1.21  2004/01/13 21:18:18  peiyongz * revert code back to previous version * * Revision 1.20  2004/01/12 16:25:09  neilg * remove use of static buffers * * Revision 1.19  2004/01/06 18:13:59  peiyongz * using the no-exception-thrown ctor * * Revision 1.18  2003/12/31 02:34:41  neilg * fix one more buffer overrun, affecting boolean lists * * Revision 1.17  2003/12/23 21:50:36  peiyongz * Absorb exception thrown in getCanonicalRepresentation and return 0, * only validate when required * * Revision 1.16  2003/12/17 20:41:47  neilg * fix a segfault and a possible buffer overflow condition * * Revision 1.15  2003/12/17 00:18:39  cargilld * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. * * Revision 1.14  2003/12/10 20:52:27  neilg * fixes for canonical value production; memory management was not implemented correctly * * Revision 1.13  2003/11/28 18:53:07  peiyongz * Support for getCanonicalRepresentation * * Revision 1.12  2003/11/12 20:32:03  peiyongz * Statless Grammar: ValidationContext * * Revision 1.11  2003/10/01 16:32:41  neilg * improve handling of out of memory conditions, bug #23415.  Thanks to David Cargill. * * Revision 1.10  2003/09/30 21:31:30  peiyongz * Implementation of Serialization/Deserialization * * Revision 1.9  2003/05/16 06:01:57  knoaman * Partial implementation of the configurable memory manager. * * Revision 1.8  2003/05/15 18:53:26  knoaman * Partial implementation of the configurable memory manager. * * Revision 1.7  2002/12/18 14:17:55  gareth * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf. * * Revision 1.6  2002/12/16 22:28:25  knoaman * Make isAtomic inline. * * Revision 1.5  2002/12/06 16:45:54  tng * header include cleanup. * * Revision 1.4  2002/11/20 19:57:44  peiyongz * validate content as a whole against pattern. * * Revision 1.3  2002/11/04 14:53:28  tng * C++ Namespace Support. * * Revision 1.2  2002/09/24 19:44:40  tng * Performance: use XMLString::equals instead of XMLString::compareString * * Revision 1.1.1.1  2002/02/01 22:22:42  peiyongz * sane_include * * Revision 1.8  2001/10/11 19:32:27  peiyongz * To overwrite inheritFacet() * * Revision 1.7  2001/10/09 20:56:21  peiyongz * inherit from AbstractStringValidator instead of DatatypeValidator to reuse * the code. * * Revision 1.6  2001/10/02 18:59:29  peiyongz * Invalid_Facet_Tag to display the tag name * * Revision 1.5  2001/09/20 13:11:42  knoaman * Regx  + misc. fixes * * Revision 1.4  2001/08/29 19:03:40  peiyongz * Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method * * Revision 1.3  2001/08/21 18:42:53  peiyongz * Bugzilla# 2816: cleanUp() declared with external linkage and called *                          before defined as inline * * Revision 1.2  2001/08/14 22:11:56  peiyongz * new exception message added * * Revision 1.1  2001/07/11 21:37:17  peiyongz * ListDatatypeDTV * * */// ---------------------------------------------------------------------------//  Includes// ---------------------------------------------------------------------------#include <xercesc/validators/datatype/ListDatatypeValidator.hpp>#include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>#include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>#include <xercesc/util/OutOfMemoryException.hpp>XERCES_CPP_NAMESPACE_BEGINstatic const int BUF_LEN = 64;// ---------------------------------------------------------------------------//  Constructors and Destructor// ---------------------------------------------------------------------------ListDatatypeValidator::ListDatatypeValidator(MemoryManager* const manager):AbstractStringValidator(0, 0, 0, DatatypeValidator::List, manager),fContent(0){}ListDatatypeValidator::ListDatatypeValidator(                          DatatypeValidator*            const baseValidator                        , RefHashTableOf<KVStringPair>* const facets                        , RefArrayVectorOf<XMLCh>*           const enums                        , const int                           finalSet                        , MemoryManager* const manager):AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::List, manager),fContent(0){    //    // baseValidator shall either    // an atomic DTV which servers as itemType, or    // another ListDTV from which, this ListDTV is derived by restriction.    //    // In either case, it shall be not null    //    if (!baseValidator)        ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_List_Null_baseValidator, manager);    init(enums, manager);}ListDatatypeValidator::~ListDatatypeValidator(){}DatatypeValidator* ListDatatypeValidator::newInstance(      RefHashTableOf<KVStringPair>* const facets    , RefArrayVectorOf<XMLCh>* const      enums    , const int                           finalSet    , MemoryManager* const                manager){    return (DatatypeValidator*) new (manager) ListDatatypeValidator(this, facets, enums, finalSet, manager);}int ListDatatypeValidator::compare(const XMLCh*     const lValue                                 , const XMLCh*     const rValue                                 , MemoryManager*   const manager){    DatatypeValidator* theItemTypeDTV = getItemTypeDTV();    BaseRefVectorOf<XMLCh>* lVector = XMLString::tokenizeString(lValue, manager);    Janitor<BaseRefVectorOf<XMLCh> > janl(lVector);    BaseRefVectorOf<XMLCh>* rVector = XMLString::tokenizeString(rValue, manager);    Janitor<BaseRefVectorOf<XMLCh> > janr(rVector);    int lNumberOfTokens = lVector->size();    int rNumberOfTokens = rVector->size();    if (lNumberOfTokens < rNumberOfTokens)        return -1;    else if (lNumberOfTokens > rNumberOfTokens)        return 1;    else    { //compare each token        for ( int i = 0; i < lNumberOfTokens; i++)        {            int returnValue = theItemTypeDTV->compare(lVector->elementAt(i), rVector->elementAt(i), manager);            if (returnValue != 0)                return returnValue; //REVISIT: does it make sense to return -1 or +1..?        }        return 0;    }}void ListDatatypeValidator::validate( const XMLCh*             const content                                    ,       ValidationContext* const context                                    ,       MemoryManager*     const manager){    setContent(content);    BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content, manager);    Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector);    checkContent(tokenVector, content, context, false, manager);}void ListDatatypeValidator::checkContent( const XMLCh*             const content                                         ,      ValidationContext* const context                                         ,      bool                     asBase                                         ,      MemoryManager*     const manager){    setContent(content);    BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content, manager);    Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector);    checkContent(tokenVector, content, context, asBase, manager);}//// here content is a list of items//void ListDatatypeValidator::checkContent(       BaseRefVectorOf<XMLCh>*       tokenVector                                        , const XMLCh*                  const content                                        ,       ValidationContext*      const context                                        ,       bool                          asBase                                        ,       MemoryManager*          const manager){    DatatypeValidator* bv = getBaseValidator();    if (bv->getType() == DatatypeValidator::List)        ((ListDatatypeValidator*)bv)->checkContent(tokenVector, content, context, true, manager);    else    {   // the ultimate itemType DTV        for (unsigned int i = 0; i < tokenVector->size(); i++)            bv->validate(tokenVector->elementAt(i), context, manager);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?