diff --git a/Projects/OS2/VACPP40/xerces_validators.icc b/Projects/OS2/VACPP40/xerces_validators.icc index 093aba91da84219e3ae1ff3688f9026df643ef4f..b384a1884a6835d6def71788d4a3fcdd51cea72c 100644 --- a/Projects/OS2/VACPP40/xerces_validators.icc +++ b/Projects/OS2/VACPP40/xerces_validators.icc @@ -17,6 +17,7 @@ group xerces_validators = BASE_DIR "\\src\\validators\\datatype\\StringDatatypeValidator.cpp", BASE_DIR "\\src\\validators\\datatype\\IDDatatypeValidator.cpp", BASE_DIR "\\src\\validators\\datatype\\IDREFDatatypeValidator.cpp", + BASE_DIR "\\src\\validators\\datatype\\NOTATIONDatatypeValidator.cpp", BASE_DIR "\\src\\validators\\DTD\\DTDAttDef.cpp", BASE_DIR "\\src\\validators\\DTD\\DTDAttDefList.cpp", BASE_DIR "\\src\\validators\\DTD\\DTDElementDecl.cpp", diff --git a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp index 9c242643884cb95971d7a5d7fe324be0fad9ab5a..d20a07aa1a81acabe2e4c84522803bafc3b9f848 100644 --- a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp +++ b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp @@ -1759,6 +1759,14 @@ SOURCE=..\..\..\..\..\src\validators\datatype\InvalidDatatypeValueException.hpp # End Source File # Begin Source File +SOURCE=..\..\..\..\..\src\validators\datatype\NOTATIONDatatypeValidator.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\..\src\validators\datatype\NOTATIONDatatypeValidator.hpp +# End Source File +# Begin Source File + SOURCE=..\..\..\..\..\src\validators\datatype\StringDatatypeValidator.cpp # End Source File # Begin Source File diff --git a/src/validators/datatype/DatatypeValidatorFactory.cpp b/src/validators/datatype/DatatypeValidatorFactory.cpp index 7411de4c7805a5f1495bf5fc974d7c9711ea2839..f794ef88c6ff9ed4d762294e73c5848676ce82bb 100644 --- a/src/validators/datatype/DatatypeValidatorFactory.cpp +++ b/src/validators/datatype/DatatypeValidatorFactory.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.13 2001/07/05 20:15:25 peiyongz + * NOTATIONDatatypeValidator + * * Revision 1.12 2001/07/04 20:16:31 peiyongz * IDREFDatatypeValidator * @@ -112,6 +115,7 @@ #include <validators/datatype/Base64BinaryDatatypeValidator.hpp> #include <validators/datatype/IDDatatypeValidator.hpp> #include <validators/datatype/IDREFDatatypeValidator.hpp> +#include <validators/datatype/NOTATIONDatatypeValidator.hpp> #include <util/PlatformUtils.hpp> #include <util/XMLDeleterFor.hpp> @@ -324,9 +328,10 @@ void DatatypeValidatorFactory::initializeDTDRegistry() /* fBuiltInRegistry->put((void*) XMLUni::fgEntityString, new ENTITYDatatypeValidator()); + */ fBuiltInRegistry->put((void*) XMLUni::fgNotationString, new NOTATIONDatatypeValidator()); - */ + // Create 'IDREFS' datatype validator createDatatypeValidator(XMLUni::fgIDRefsString, diff --git a/src/validators/datatype/Makefile.in b/src/validators/datatype/Makefile.in index 023d7e6e0145604f6dc3b6e55718856e1c02c795..cd706be9278b981a205672e47d40096b8905af03 100644 --- a/src/validators/datatype/Makefile.in +++ b/src/validators/datatype/Makefile.in @@ -55,6 +55,9 @@ # # # $Log$ +# Revision 1.10 2001/07/05 20:15:26 peiyongz +# NOTATIONDatatypeValidator +# # Revision 1.9 2001/07/04 20:16:31 peiyongz # IDREFDatatypeValidator # @@ -116,6 +119,7 @@ VALIDATORS_DATATYPE_CPP_PUBHEADERS = \ HexBinaryDatatypeValidator.hpp \ StringDatatypeValidator.hpp \ IDDatatypeValidator.hpp \ + NOTATIONDatatypeValidator.hpp \ IDREFDatatypeValidator.hpp VALIDATORS_DATATYPE_CPP_PRIVHEADERS = @@ -131,6 +135,7 @@ VALIDATORS_DATATYPE_CPP_OBJECTS = \ HexBinaryDatatypeValidator.$(TO) \ StringDatatypeValidator.$(TO) \ IDDatatypeValidator.$(TO) \ + NOTATIONDatatypeValidator.$(TO) \ IDREFDatatypeValidator.$(TO) all:: includes $(VALIDATORS_DATATYPE_CPP_OBJECTS) diff --git a/src/validators/datatype/NOTATIONDatatypeValidator.cpp b/src/validators/datatype/NOTATIONDatatypeValidator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2a02b8e5de77675144f0c5dedc3db82c99031d4 --- /dev/null +++ b/src/validators/datatype/NOTATIONDatatypeValidator.cpp @@ -0,0 +1,586 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 2001, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +/* + * $Id$ + * $Log$ + * Revision 1.1 2001/07/05 20:15:27 peiyongz + * NOTATIONDatatypeValidator + * + */ + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <validators/datatype/NOTATIONDatatypeValidator.hpp> +#include <validators/datatype/InvalidDatatypeFacetException.hpp> +#include <validators/datatype/InvalidDatatypeValueException.hpp> +#include <util/NumberFormatException.hpp> + + +static const int BUF_LEN = 64; +static XMLCh value1[BUF_LEN+1]; +static XMLCh value2[BUF_LEN+1]; + +// --------------------------------------------------------------------------- +// Constructors and Destructor +// --------------------------------------------------------------------------- +NOTATIONDatatypeValidator::NOTATIONDatatypeValidator( + DatatypeValidator* const baseValidator + , RefHashTableOf<KVStringPair>* const facets + , RefVectorOf<XMLCh>* const enums + , const int finalSet) +:DatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::NOTATION) +,fLength(0) +,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE) +,fMinLength(0) +,fEnumerationInherited(false) +,fEnumeration(0) +{ + try + { + init(baseValidator, facets, enums); + } + catch (XMLException&) + { + cleanUp(); + throw; + } +} + +void NOTATIONDatatypeValidator::init(DatatypeValidator* const baseValidator + , RefHashTableOf<KVStringPair>* const facets + , RefVectorOf<XMLCh>* const enums ) +{ + + // Set Facets if any defined + if (facets) + { + if (enums) + setEnumeration(enums, false); + + XMLCh* key; + XMLCh* value; + RefHashTableOfEnumerator<KVStringPair> e(facets); + + while (e.hasMoreElements()) + { + KVStringPair pair = e.nextElement(); + key = pair.getKey(); + value = pair.getValue(); + + if (XMLString::compareString(key, SchemaSymbols::fgELT_LENGTH)==0) + { + int val; + try + { + val = XMLString::parseInt(value); + } + catch (NumberFormatException nfe) + { + ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value); + } + + if ( val < 0 ) + ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value); + + setLength(val); + setFacetsDefined(DatatypeValidator::FACET_LENGTH); + } + else if (XMLString::compareString(key, SchemaSymbols::fgELT_MINLENGTH)==0) + { + int val; + try + { + val = XMLString::parseInt(value); + } + catch (NumberFormatException nfe) + { + ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value); + } + + if ( val < 0 ) + ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value); + + setMinLength(val); + setFacetsDefined(DatatypeValidator::FACET_MINLENGTH); + } + else if (XMLString::compareString(key, SchemaSymbols::fgELT_MAXLENGTH)==0) + { + int val; + try + { + val = XMLString::parseInt(value); + } + catch (NumberFormatException nfe) + { + ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value); + } + + if ( val < 0 ) + ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value); + + setMaxLength(val); + setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH); + } + else if (XMLString::compareString(key, SchemaSymbols::fgELT_PATTERN)==0) + { + setPattern(value); + if (getPattern()) + setFacetsDefined(DatatypeValidator::FACET_PATTERN); + // do not construct regex until needed + } + else if (XMLString::compareString(key, SchemaSymbols::fgATT_FIXED)==0) + { + unsigned int val; + bool retStatus; + try + { + retStatus = XMLString::textToBin(value, val); + } + catch (RuntimeException) + { + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed); + } + + if (!retStatus) + { + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed); + } + + setFixed(val); + //no setFacetsDefined here + } + else + { + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Tag); + } + }//while + + /*** + Schema constraint: Part I -- self checking + ***/ + + // check 4.3.1.c1 error: length & (maxLength | minLength) + if ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) + { + if ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0) + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen); + else if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0)) + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen); + } + + // check 4.3.2.c1 must: minLength <= maxLength + if ((getFacetsDefined() & (DatatypeValidator::FACET_MINLENGTH + |DatatypeValidator::FACET_MAXLENGTH)) != 0) + { + if ( getMinLength() > getMaxLength() ) + { + XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10); + XMLString::binToText(getMinLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_maxLen_minLen + , value1 + , value2); + } + } + + /*** + Schema constraint: Part II base vs derived checking + ***/ + if (baseValidator !=0) + { + /*** + check facets against base.facets + Note: later we need to check the "fix" option of the base type + and apply that to every individual facet. + ***/ + NOTATIONDatatypeValidator *pBaseValidator = (NOTATIONDatatypeValidator*) baseValidator; + + /*** + Non coexistence of derived' length and base' (minLength | maxLength) + base' length and derived' (minLength | maxLength) + ***/ + + // check 4.3.1.c1 error: length & (base.maxLength | base.minLength) + if ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0) + { + if ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen); + else if ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen); + } + + // check 4.3.1.c1 error: base.length & (maxLength | minLength) + if ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0) + { + if ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen); + else if ((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) + ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen); + } + + // check 4.3.1.c2 error: length != base.length + if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0) && + ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0)) + { + if ( getLength() != pBaseValidator->getLength() ) + { + XMLString::binToText(getLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_Len_baseLen + , value1 + , value2); + } + } + + /*** + |--- derived ---| + base.minLength <= minLength <= maxLength <= base.maxLength + |------------------- base -------------------| + ***/ + + // check 4.3.2.c1 must: minLength <= base.maxLength + if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH ) != 0) && + ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH ) != 0)) + { + if ( getMinLength() > pBaseValidator->getMaxLength() ) + { + XMLString::binToText(getMinLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_minLen_baseminLen + , value1 + , value2); + } + } + + // check 4.3.2.c2 error: minLength < base.minLength + if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) && + ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0)) + { + if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MINLENGTH) !=0) + { + if ( getMinLength() != pBaseValidator->getMinLength() ) + { + XMLString::binToText(getMinLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_minLen_base_fixed + , value1 + , value2); + } + } + else + { + if ( getMinLength() < pBaseValidator->getMinLength() ) + { + XMLString::binToText(getMinLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_minLen_basemaxLen + , value1 + , value2); + } + } + } + + // check 4.3.2.c1 must: base.minLength <= maxLength + if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) && + ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0)) + { + if ( pBaseValidator->getMinLength() > getMaxLength() ) + { + XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_maxLen_baseminLen + , value1 + , value2); + } + } + + // check 4.3.3.c1 error: maxLength > base.maxLength + if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) && + ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0)) + { + if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MAXLENGTH) !=0) + { + if ( getMaxLength() != pBaseValidator->getMaxLength() ) + { + XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_maxLen_base_fixed + , value1 + , value2); + } + } + else + { + if ( getMaxLength() > pBaseValidator->getMaxLength() ) + { + XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10); + XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10); + + ThrowXML2(InvalidDatatypeFacetException + , XMLExcepts::FACET_maxLen_basemaxLen + , value1 + , value2); + } + } + } + + // check 4.3.5.c0 must: enumeration values from the value space of base + if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) && + (getEnumeration() !=0)) + { + int i = 0; + int enumLength = getEnumeration()->size(); + try + { + for ( ; i < enumLength; i++) + // ask parent do a complete check + pBaseValidator->checkContent(getEnumeration()->elementAt(i), false); + // REVISIT: enum shall pass this->checkContent() as well. + //checkContent(getEnumeration()->elementAt(i), false); + } + + catch ( XMLException& ) + { + ThrowXML1(InvalidDatatypeFacetException + , XMLExcepts::FACET_enum_base + , getEnumeration()->elementAt(i)); + } + } + + } //if baseValidator + + }// End of Facet setting + + if (baseValidator ) + { + NOTATIONDatatypeValidator *pBaseValidator = (NOTATIONDatatypeValidator*) baseValidator; + + /*** + Inherit facets from base.facets + + The reason of this inheriting (or copying values) is to ease + schema constraint checking, so that we need NOT trace back to our + very first base validator in the hierachy. Instead, we are pretty + sure checking against immediate base validator is enough. + ***/ + + // inherit length + if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) && + ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) == 0)) + { + setLength(pBaseValidator->getLength()); + setFacetsDefined(DatatypeValidator::FACET_LENGTH); + } + + // inherit minLength + if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) && + ((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) == 0)) + { + setMinLength(pBaseValidator->getMinLength()); + setFacetsDefined(DatatypeValidator::FACET_MINLENGTH); + } + + // inherit maxLength + if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) && + ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) == 0)) + { + setMaxLength(pBaseValidator->getMaxLength()); + setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH); + } + + // inherit enumeration + if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) !=0) && + ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) == 0)) + { + setEnumeration(pBaseValidator->getEnumeration(), true); + } + + // we don't inherit pattern + + // inherit "fixed" option + setFixed(getFixed() | pBaseValidator->getFixed()); + + } // end of inheritance + +} + +void NOTATIONDatatypeValidator::checkContent( const XMLCh* const content, bool asBase) +{ + + //validate against base validator if any + NOTATIONDatatypeValidator *pBaseValidator = (NOTATIONDatatypeValidator*) this->getBaseValidator(); + if (pBaseValidator != 0) + pBaseValidator->checkContent(content, true); + + // we check pattern first + if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) + { + // lazy construction + if (getRegex() ==0) { + try { + setRegex(new RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption)); + } + catch (XMLException &e) + { + ThrowXML1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage()); + } + } + + if (getRegex()->matches(content) ==false) + { + ThrowXML2(InvalidDatatypeValueException + , XMLExcepts::VALUE_NotMatch_Pattern + , content + , getPattern()); + } + } + + // if this is a base validator, we only need to check pattern facet + // all other facet were inherited by the derived type + if (asBase) + return; + + unsigned int notationLen = XMLString::stringLen(content); + + if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0) && + (notationLen > getMaxLength())) + { + XMLString::binToText(notationLen, value1, BUF_LEN, 10); + XMLString::binToText(getMaxLength(), value2, BUF_LEN, 10); + + ThrowXML3(InvalidDatatypeValueException + , XMLExcepts::VALUE_GT_maxLen + , content + , value1 + , value2); + } + + if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0) && + (notationLen < getMinLength())) + { + XMLString::binToText(notationLen, value1, BUF_LEN, 10); + XMLString::binToText(getMinLength(), value2, BUF_LEN, 10); + + ThrowXML3(InvalidDatatypeValueException + , XMLExcepts::VALUE_LT_minLen + , content + , value1 + , value2); + } + + if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) && + (notationLen != getLength())) + { + XMLString::binToText(notationLen, value1, BUF_LEN, 10); + XMLString::binToText(getLength(), value2, BUF_LEN, 10); + + ThrowXML3(InvalidDatatypeValueException + , XMLExcepts::VALUE_NE_Len + , content + , value1 + , value2); + } + + if ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0 && + (getEnumeration() != 0)) + { + int i=0; + int enumLength = getEnumeration()->size(); + for ( ; i < enumLength; i++) + { + if (XMLString::compareString(content, getEnumeration()->elementAt(i))==0) + break; + } + + if (i == enumLength) + ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content); + } + + // REVISIT: do we need to check 3.2.19: "anyURI:NCName"? + /* + try + { + int posColon = content.lastIndexOf(':'); + if (posColon >= 0) + fgURIValidator.validate(content.substring(0,posColon), null); + fgStrValidator.validate(content.substring(posColon+1), null); + } + catch (InvalidDatatypeValueException idve) + { + ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content); + //("Value '"+content+"' is not a valid NOTATION"); + } + */ +} + +/** + * End of file NOTATIONDatatypeValidator.cpp + */ diff --git a/src/validators/datatype/NOTATIONDatatypeValidator.hpp b/src/validators/datatype/NOTATIONDatatypeValidator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c527014995fddbbb0192105416e67039309c0483 --- /dev/null +++ b/src/validators/datatype/NOTATIONDatatypeValidator.hpp @@ -0,0 +1,294 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 1999, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +/* + * $Id$ + * $Log$ + * Revision 1.1 2001/07/05 20:15:27 peiyongz + * NOTATIONDatatypeValidator + * + */ + +#if !defined(NOTATION_DATATYPEVALIDATOR_HPP) +#define NOTATION_DATATYPEVALIDATOR_HPP + +#include <validators/datatype/DatatypeValidator.hpp> +#include <validators/schema/SchemaSymbols.hpp> +#include <util/RefVectorOf.hpp> + +class VALIDATORS_EXPORT NOTATIONDatatypeValidator : public DatatypeValidator +{ +public: + + // ----------------------------------------------------------------------- + // Public ctor/dtor + // ----------------------------------------------------------------------- + /** @name Constructor. */ + //@{ + + NOTATIONDatatypeValidator(); + + NOTATIONDatatypeValidator(DatatypeValidator* const baseValidator + , RefHashTableOf<KVStringPair>* const facets + , RefVectorOf<XMLCh>* const enums + , const int finalSet); + + virtual ~NOTATIONDatatypeValidator(); + + //@} + + // ----------------------------------------------------------------------- + // Validation methods + // ----------------------------------------------------------------------- + /** @name Validation Function */ + //@{ + + /** + * validate that a string matches the boolean datatype + * @param content A string containing the content to be validated + * + * @exception throws InvalidDatatypeException if the content is + * is not valid. + */ + + void validate(const XMLCh* const content); + + //@} + + // ----------------------------------------------------------------------- + // Compare methods + // ----------------------------------------------------------------------- + /** @name Compare Function */ + //@{ + + /** + * Compare two boolean data types + * + * @param content1 + * @param content2 + * @return + */ + int compare(const XMLCh* const, const XMLCh* const); + + //@} + + /** + * Returns an instance of the base datatype validator class + * Used by the DatatypeValidatorFactory. + */ + DatatypeValidator* newInstance(DatatypeValidator* const baseValidator + , RefHashTableOf<KVStringPair>* const facets + , RefVectorOf<XMLCh>* const enums + , const int finalSet); + + +private: + + void checkContent( const XMLCh* const content, bool asBase); + + void init(DatatypeValidator* const baseValidator + , RefHashTableOf<KVStringPair>* const facets + , RefVectorOf<XMLCh>* const enums); + + void cleanUp(); + +// ----------------------------------------------------------------------- +// Getter methods +// ----------------------------------------------------------------------- + + unsigned int getLength() const; + + unsigned int getMaxLength() const; + + unsigned int getMinLength() const; + + RefVectorOf<XMLCh>* getEnumeration() const; + +// ----------------------------------------------------------------------- +// Setter methods +// ----------------------------------------------------------------------- + + void setLength(unsigned int); + + void setMaxLength(unsigned int); + + void setMinLength(unsigned int); + + void setEnumeration(RefVectorOf<XMLCh>*, bool); + + // ----------------------------------------------------------------------- + // Private data members + // + // + // . + // + // ----------------------------------------------------------------------- + int fLength; + int fMaxLength; + int fMinLength; + bool fEnumerationInherited; + RefVectorOf<XMLCh>* fEnumeration; + +}; + +// --------------------------------------------------------------------------- +// Constructors and Destructor +// --------------------------------------------------------------------------- +inline NOTATIONDatatypeValidator::NOTATIONDatatypeValidator() +:DatatypeValidator(0, 0, 0, DatatypeValidator::NOTATION) +,fLength(0) +,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE) +,fMinLength(0) +,fEnumerationInherited(false) +,fEnumeration(0) +{} + +inline NOTATIONDatatypeValidator::~NOTATIONDatatypeValidator() +{ + cleanUp(); +} + +// ----------------------------------------------------------------------- +// Compare methods +// ----------------------------------------------------------------------- +inline int NOTATIONDatatypeValidator::compare(const XMLCh* const lValue + , const XMLCh* const rValue) +{ + return ( XMLString::compareString(lValue, rValue) ==0? 0: -1); +} + +inline DatatypeValidator* NOTATIONDatatypeValidator::newInstance( + DatatypeValidator* const baseValidator + , RefHashTableOf<KVStringPair>* const facets + , RefVectorOf<XMLCh>* const enums + , const int finalSet) +{ + return (DatatypeValidator*) new NOTATIONDatatypeValidator(baseValidator, facets, enums, finalSet); +} + +inline void NOTATIONDatatypeValidator::validate( const XMLCh* const content) +{ + checkContent(content, false); +} + +inline void NOTATIONDatatypeValidator::cleanUp() +{ + //~RefVectorOf will delete all adopted elements + if (fEnumeration && !fEnumerationInherited) + delete fEnumeration; +} + +// ----------------------------------------------------------------------- +// Getter methods +// ----------------------------------------------------------------------- + +inline unsigned int NOTATIONDatatypeValidator::getLength() const +{ + return fLength; +} + +inline unsigned int NOTATIONDatatypeValidator::getMaxLength() const +{ + return fMaxLength; +} + +inline unsigned int NOTATIONDatatypeValidator::getMinLength() const +{ + return fMinLength; +} + +inline RefVectorOf<XMLCh>* NOTATIONDatatypeValidator:: getEnumeration() const +{ + return fEnumeration; +} + +// ----------------------------------------------------------------------- +// Setter methods +// ----------------------------------------------------------------------- + +inline void NOTATIONDatatypeValidator::setLength(unsigned int newLength) +{ + fLength = newLength; +} + +inline void NOTATIONDatatypeValidator::setMaxLength(unsigned int newMaxLength) +{ + fMaxLength = newMaxLength; +} + +inline void NOTATIONDatatypeValidator::setMinLength(unsigned int newMinLength) +{ + fMinLength = newMinLength; +} + +inline void NOTATIONDatatypeValidator::setEnumeration(RefVectorOf<XMLCh>* enums + , bool inherited) +{ + if (enums) + { + if (fEnumeration && !fEnumerationInherited) + delete fEnumeration; + + fEnumeration = enums; + fEnumerationInherited = inherited; + setFacetsDefined(DatatypeValidator::FACET_ENUMERATION); + } +} + +/** + * End of file NOTATIONDatatypeValidator.hpp + */ +#endif