You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/05/09 20:43:54 UTC

cvs commit: xml-xerces/c/src/validators/schema SchemaSymbols.cpp SchemaSymbols.hpp

tng         01/05/09 11:43:53

  Modified:    c/Projects/Win32/VC6/xerces-all/XercesLib XercesLib.dsp
               c/src/util XMLString.cpp XMLString.hpp
               c/src/validators/datatype DatatypeValidator.cpp
                        DatatypeValidator.hpp DatatypeValidatorFactory.cpp
                        Makefile.in
               c/src/validators/schema SchemaSymbols.cpp SchemaSymbols.hpp
  Added:       c/src/validators/datatype BooleanDatatypeValidator.cpp
                        BooleanDatatypeValidator.hpp
                        StringDatatypeValidator.cpp
                        StringDatatypeValidator.hpp
  Log:
  Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  
  Revision  Changes    Path
  1.57      +23 -7     xml-xerces/c/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp
  
  Index: XercesLib.dsp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- XercesLib.dsp	2001/05/03 20:50:13	1.56
  +++ XercesLib.dsp	2001/05/09 18:43:23	1.57
  @@ -7,19 +7,19 @@
   CFG=XercesLib - Win32 Debug
   !MESSAGE This is not a valid makefile. To build this project using NMAKE,
   !MESSAGE use the Export Makefile command and run
  -!MESSAGE 
  +!MESSAGE
   !MESSAGE NMAKE /f "XercesLib.mak".
  -!MESSAGE 
  +!MESSAGE
   !MESSAGE You can specify a configuration when running NMAKE
   !MESSAGE by defining the macro CFG on the command line. For example:
  -!MESSAGE 
  +!MESSAGE
   !MESSAGE NMAKE /f "XercesLib.mak" CFG="XercesLib - Win32 Debug"
  -!MESSAGE 
  +!MESSAGE
   !MESSAGE Possible choices for configuration are:
  -!MESSAGE 
  +!MESSAGE
   !MESSAGE "XercesLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
   !MESSAGE "XercesLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
  -!MESSAGE 
  +!MESSAGE
   
   # Begin Project
   # PROP AllowPerConfigDependencies 0
  @@ -84,7 +84,7 @@
   # ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib /nologo /base:"0x12000000" /version:1.4 /subsystem:windows /dll /debug /machine:I386 /out:"..\..\..\..\..\Build\Win32\VC6\Debug/xerces-c_1_4D.dll" /implib:"..\..\..\..\..\Build\Win32\VC6\Debug/xerces-c_1D.lib" /pdbtype:sept
   # SUBTRACT LINK32 /pdb:none
   
  -!ENDIF 
  +!ENDIF
   
   # Begin Target
   
  @@ -1647,6 +1647,14 @@
   # PROP Default_Filter "*.cpp, *.hpp"
   # Begin Source File
   
  +SOURCE=..\..\..\..\..\src\validators\datatype\BooleanDatatypeValidator.cpp
  +# End Source File
  +# Begin Source File
  +
  +SOURCE=..\..\..\..\..\src\validators\datatype\BooleanDatatypeValidator.hpp
  +# End Source File
  +# Begin Source File
  +
   SOURCE=..\..\..\..\..\src\validators\datatype\DatatypeValidator.cpp
   # End Source File
   # Begin Source File
  @@ -1668,6 +1676,14 @@
   # Begin Source File
   
   SOURCE=..\..\..\..\..\src\validators\datatype\InvalidDatatypeValueException.hpp
  +# End Source File
  +# Begin Source File
  +
  +SOURCE=..\..\..\..\..\src\validators\datatype\StringDatatypeValidator.cpp
  +# End Source File
  +# Begin Source File
  +
  +SOURCE=..\..\..\..\..\src\validators\datatype\StringDatatypeValidator.hpp
   # End Source File
   # End Group
   # Begin Group "DTD"
  
  
  
  1.17      +93 -1     xml-xerces/c/src/util/XMLString.cpp
  
  Index: XMLString.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/XMLString.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- XMLString.cpp	2001/05/03 19:17:33	1.16
  +++ XMLString.cpp	2001/05/09 18:43:27	1.17
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: XMLString.cpp,v 1.16 2001/05/03 19:17:33 knoaman Exp $
  + * $Id: XMLString.cpp,v 1.17 2001/05/09 18:43:27 tng Exp $
    */
   
   
  @@ -66,6 +66,7 @@
   #include <ctype.h>
   #include <util/ArrayIndexOutOfBoundsException.hpp>
   #include <util/IllegalArgumentException.hpp>
  +#include <util/NumberFormatException.hpp>
   #include <util/Janitor.hpp>
   #include <util/PlatformUtils.hpp>
   #include <util/RuntimeException.hpp>
  @@ -75,6 +76,7 @@
   #include <util/XMLString.hpp>
   #include <util/XMLUniDefs.hpp>
   #include <util/XMLUni.hpp>
  +#include <internal/XMLReader.hpp>
   
   
   // ---------------------------------------------------------------------------
  @@ -603,6 +605,38 @@
   	targetStr[copySize] = 0;
   }
   
  +/**
  +  * isValidNCName
  +  *
  +  *    NCName::= (Letter | '_') (NCNameChar)*
  +  *    NCNameChar ::= Letter | Digit | '.' | '-' | '_'
  +  *                   | CombiningChar | Extender
  +  */
  +bool XMLString::isValidNCName(const XMLCh* const name) {
  +
  +    if (XMLString::stringLen(name) == 0
  +        || XMLString::indexOf(name, chColon) != -1) {
  +        return false;
  +    }
  +
  +    const XMLCh* tempName = name;
  +    XMLCh firstChar = *tempName++;
  +
  +    if (!XMLReader::isXMLLetter(firstChar) && firstChar != chUnderscore) {
  +
  +        return false;
  +    }
  +
  +    while(*tempName) {
  +
  +        if (!XMLReader::isNameChar(*tempName++)) {
  +            return false;
  +        }
  +    }
  +
  +    return true;
  +}
  +
   // ---------------------------------------------------------------------------
   //  Wide char versions of most of the string methods
   // ---------------------------------------------------------------------------
  @@ -1135,6 +1169,64 @@
       return true;
   }
   
  +int XMLString::parseInt(const XMLCh* const toConvert)
  +{
  +    // If no string, then its a failure
  +    if ((!toConvert) ||
  +        (!*toConvert))
  +        ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
  +        //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
  +
  +    // Scan past any whitespace. If we hit the end, then return failure
  +    const XMLCh* startPtr = toConvert;
  +    while (XMLPlatformUtils::fgTransService->isSpace(*startPtr))
  +        startPtr++;
  +
  +    if (!*startPtr)
  +        ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
  +        //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
  +
  +    // Start at the end and work back through any whitespace
  +    const XMLCh* endPtr = toConvert + XMLString::stringLen(toConvert);
  +    while (XMLPlatformUtils::fgTransService->isSpace(*(endPtr - 1)))
  +        endPtr--;
  +
  +    //
  +    //  Work through what remains and convert each char to a digit. 
  +    //
  +    int signValue = 1;
  +
  +    //
  +    // '+' or '-' is allowed only at the first position
  +    //
  +    if (*startPtr == chDash)
  +    {
  +        signValue = -1;
  +        startPtr++;  // skip the '-'
  +    }
  +    else if (*startPtr == chPlus)
  +        startPtr++;  // skip the '+'
  +
  +    unsigned long tmpVal = 0;   
  +    while (startPtr < endPtr)
  +    {
  +        // If not valid decimal digit, then an error
  +        if ((*startPtr < chDigit_0) || (*startPtr > chDigit_9))
  +            ThrowXML(NumberFormatException, XMLExcepts::CM_UnaryOpHadBinType);
  +            //ThrowXML(NumberFormatException, XMLExcepts::XMLINT_Invalid);
  +        
  +        const unsigned int nextVal = (unsigned int)(*startPtr - chDigit_0);
  +        tmpVal = (tmpVal * 10) + nextVal;
  +
  +        startPtr++;
  +    }
  +
  +    // Make sure it didn't overflow
  +    if (tmpVal > ~0UL)
  +        ThrowXML(NumberFormatException, XMLExcepts::Str_ConvertOverflow);
  +
  +    return (int) signValue*tmpVal;
  +}
   
   void XMLString::trim(XMLCh* const toTrim)
   {
  
  
  
  1.20      +28 -0     xml-xerces/c/src/util/XMLString.hpp
  
  Index: XMLString.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/XMLString.hpp,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- XMLString.hpp	2001/05/03 20:34:35	1.19
  +++ XMLString.hpp	2001/05/09 18:43:30	1.20
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: XMLString.hpp,v $
  + * Revision 1.20  2001/05/09 18:43:30  tng
  + * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  + *
    * Revision 1.19  2001/05/03 20:34:35  tng
    * Schema: SchemaValidator update
    *
  @@ -342,6 +345,24 @@
           const   XMLCh* const    toConvert
           ,       unsigned int&   toFill
       );
  +
  +    /**
  +      * Converts a string of decimal chars to a binary value
  +      *
  +      * Note that leading and trailng whitespace is legal and will be ignored,
  +      *
  +      * Only one and either of (+,-) after the leading whitespace, before
  +      * any other characters are allowed.
  +      *
  +      * but the remainder must be all decimal digits.
  +      *
  +      * @param toConvert The string of digits to convert
  +      */
  +    static int parseInt
  +    (
  +        const   XMLCh* const    toConvert
  +    );    
  +    
       //@}
   
       /** @name String concatenation functions */
  @@ -990,6 +1011,13 @@
         * @return Returns the length of the string
         */
       static unsigned int stringLen(const XMLCh* const src);
  +
  +    /**
  +      * Checks whether an name is a valid NCName.
  +      * @param name The string to check its NCName validity
  +      * @return Returns true if name is NCName valid, otherwise false
  +      */
  +    static bool isValidNCName(const XMLCh* const name);
       //@}
   
       /** @name Conversion functions */
  
  
  
  1.4       +3 -14     xml-xerces/c/src/validators/datatype/DatatypeValidator.cpp
  
  Index: DatatypeValidator.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/DatatypeValidator.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatatypeValidator.cpp	2001/05/03 21:09:52	1.3
  +++ DatatypeValidator.cpp	2001/05/09 18:43:38	1.4
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: DatatypeValidator.cpp,v $
  + * Revision 1.4  2001/05/09 18:43:38  tng
  + * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  + *
    * Revision 1.3  2001/05/03 21:09:52  tng
    * Schema: DatatypeValidator Update.  By Pei Yong Zhang.
    *
  @@ -94,20 +97,6 @@
   DatatypeValidator::~DatatypeValidator()
   {
   	cleanUp();
  -}
  -
  -
  -// ---------------------------------------------------------------------------
  -//  DatatypeValidators: Whitespace handling methods
  -// ---------------------------------------------------------------------------
  -void
  -DatatypeValidator::processWhiteSpace(RefHashTableOf<KVStringPair>* const facets)
  -{
  -    KVStringPair* value = facets->get(SchemaSymbols::fgELT_WHITESPACE);
  -
  -    if (value != 0) {
  -        facets->removeKey(SchemaSymbols::fgELT_WHITESPACE);
  -    }
   }
   
   /**
  
  
  
  1.4       +25 -42    xml-xerces/c/src/validators/datatype/DatatypeValidator.hpp
  
  Index: DatatypeValidator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/DatatypeValidator.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatatypeValidator.hpp	2001/05/03 21:09:54	1.3
  +++ DatatypeValidator.hpp	2001/05/09 18:43:39	1.4
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: DatatypeValidator.hpp,v 1.3 2001/05/03 21:09:54 tng Exp $
  + * $Id: DatatypeValidator.hpp,v 1.4 2001/05/09 18:43:39 tng Exp $
    */
   
   #if !defined(DATATYPEVALIDATOR_HPP)
  @@ -115,36 +115,18 @@
   
       enum ValidatorType {
           String,
  -        NormalizedString,
           AnyURI,
           QName,
  -        Token,
  -        Language,
  -        Name,
  -        NCName,
           Boolean,
           Float,
           Double,
           Decimal,
           HexBinary,
           Base64Binary,
  -        Integer,
  -        NonPositiveInteger,
  -        NegativeInteger,
  -        Long,
  -        Int,
  -        Short,
  -        Byte,
  -        NonNegativeInteger,
  -        UnsignedLong,
  -        UnsignedInt,
  -        UnsignedShort,
  -        UnsignedByte,
  -        PositiveInteger,
           Duration,
  -        Time,
           DateTime,
           Date,
  +        Time,
           MonthDay,
           YearMonth,
           Year,
  @@ -154,10 +136,8 @@
           IDREF,
           ENTITY,
           NOTATION,
  -        IDREFS,
  -        ENTITIES,
  -        NMTOKEN,
  -        NMTOKENS
  +        List,
  +        Union
       };
   
       // -----------------------------------------------------------------------
  @@ -290,16 +270,6 @@
   
   	friend class DatatypeValidatorFactory;
   
  -	/**
  -	  * Process the WHITESPACE facet if passed by user.
  -      * For all datatypes (exception of string), we don't need to pass
  -	  * the WHITESPACE facet as its value is always 'collapse' and cannot
  -	  * be reset by user.
  -	  *
  -	  * To be overwritten in the StringDatatypeValidator
  -      */
  -	virtual void processWhiteSpace(RefHashTableOf<KVStringPair>* const facets);
  -
       /**
         * facetDefined
   	  */
  @@ -311,7 +281,7 @@
         * fPattern
   	  */
       const XMLCh* getPattern() const;
  -	void         setPattern(const XMLCh* const);
  +	void         setPattern(const XMLCh* );
   
       /**
         * fRegex
  @@ -319,6 +289,11 @@
   	RegularExpression* getRegex() const;
   	void               setRegex(RegularExpression* const);
   
  +    /**
  +      * set fType
  +      */
  +    void setType(ValidatorType);
  +
   private:
       // -----------------------------------------------------------------------
       //  CleanUp methods
  @@ -345,7 +320,8 @@
       //      Stores the constaiting facets flag
       //
       //  fPattern
  -    //      the String of the pattern
  +    //      the pointer to the String of the pattern. The actual data is
  +    //      in the Facets.
       //
       //  fRegex
       //      pointer to the RegularExpress object
  @@ -364,7 +340,7 @@
   
       ValidatorType                 fType;
       int                           fFacetsDefined;
  -    DOMString                     fPattern;
  +    const XMLCh*                  fPattern;
       RegularExpression            *fRegex;
   
       //ValueVectorOf<bool>        *fFixed;
  @@ -399,22 +375,29 @@
       return fType;
   }
   
  +inline void DatatypeValidator::setType(ValidatorType theType)
  +{
  +    fType = theType;
  +}
  +
   // ---------------------------------------------------------------------------
   //  DatatypeValidator: CleanUp methods
   // ---------------------------------------------------------------------------
   inline void DatatypeValidator::cleanUp() {
   
   	delete fFacets;
  +    delete fRegex;
  +
   }
   
   
   // ---------------------------------------------------------------------------
   //  DatatypeValidators: Compare methods
   // ---------------------------------------------------------------------------
  -inline int DatatypeValidator::compare(const XMLCh* const value1,
  -                                      const XMLCh* const value2)
  +inline int DatatypeValidator::compare(const XMLCh* const lValue,
  +                                      const XMLCh* const rValue)
   {
  -    return XMLString::compareString(value1, value2);
  +    return XMLString::compareString(lValue, rValue);
   }
   
   // ---------------------------------------------------------------------------
  @@ -449,10 +432,10 @@
   
   inline const XMLCh* DatatypeValidator::getPattern() const
   {
  -    return fPattern.rawBuffer();
  +    return fPattern;
   }
   
  -inline void DatatypeValidator::setPattern(const XMLCh* const pattern)
  +inline void DatatypeValidator::setPattern(const XMLCh* pattern)
   {
       fPattern = pattern;
   }
  
  
  
  1.3       +83 -147   xml-xerces/c/src/validators/datatype/DatatypeValidatorFactory.cpp
  
  Index: DatatypeValidatorFactory.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/DatatypeValidatorFactory.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatatypeValidatorFactory.cpp	2001/05/03 19:17:47	1.2
  +++ DatatypeValidatorFactory.cpp	2001/05/09 18:43:40	1.3
  @@ -1,37 +1,37 @@
   /*
    * The Apache Software License, Version 1.1
  - * 
  + *
    * Copyright (c) 1999-2000 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. 
  - * 
  + *    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:  
  + *    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 
  + *    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
  @@ -45,7 +45,7 @@
    * 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
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: DatatypeValidatorFactory.cpp,v $
  + * Revision 1.3  2001/05/09 18:43:40  tng
  + * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  + *
    * Revision 1.2  2001/05/03 19:17:47  knoaman
    * TraverseSchema Part II.
    *
  @@ -72,18 +75,20 @@
   #include <validators/schema/SchemaSymbols.hpp>
   #include <util/XMLUniDefs.hpp>
   #include <util/Janitor.hpp>
  +#include <validators/datatype/StringDatatypeValidator.hpp>
  +#include <validators/datatype/BooleanDatatypeValidator.hpp>
   
   
   // ---------------------------------------------------------------------------
   //  DatatypeValidatorFactory: Local const data
   // ---------------------------------------------------------------------------
  -XMLCh fgTokPattern[] = 
  -{ 
  +const XMLCh fgTokPattern[] =
  +{
       chBackSlash, chLatin_c, chPlus, chNull
   };
   
   //"([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*"
  -const XMLCh fgLangPattern[] = 
  +const XMLCh fgLangPattern[] =
   {
       chOpenParen, chOpenSquare, chLatin_a, chDash, chLatin_z, chLatin_A, chDash,
       chLatin_Z, chCloseSquare, chOpenCurly, chDigit_2, chCloseCurly, chPipe,
  @@ -110,7 +115,7 @@
       chColon, chCloseSquare, chCloseSquare, chAsterisk, chNull
   };
   
  -const XMLCh fgValueZero[] = 
  +const XMLCh fgValueZero[] =
   {
       chDigit_0, chNull
   };
  @@ -120,7 +125,7 @@
       chDash, chDigit_1, chNull
   };
   
  -const XMLCh fgValueOne[] = 
  +const XMLCh fgValueOne[] =
   {
       chDigit_1, chNull
   };
  @@ -263,21 +268,23 @@
       }
   
   	try {
  -	    /*
  +
           fRegistry->put((void*) SchemaSymbols::fgDT_STRING,
  -                       new StringDatatypeValidator(0,0));
  +                       new StringDatatypeValidator());
  +
  +/*
           fRegistry->put((void*) XMLUni::fgIDString,
  -                       new IDDatatypeValidator(0,0));
  +                       new IDDatatypeValidator());
           fRegistry->put((void*) XMLUni::fgIDRefString,
  -                       new IDREFDatatypeValidator(0,0));
  +                       new IDREFDatatypeValidator());
           fRegistry->put((void*) XMLUni::fgEntityString,
  -                       new ENTITYDatatypeValidator(0,0));
  +                       new ENTITYDatatypeValidator());
           fRegistry->put((void*) XMLUni::fgNotationString,
  -                       new NOTATIONDatatypeValidator(0,0));
  +                       new NOTATIONDatatypeValidator());
   	    */
   
           // Create 'IDREFS' datatype validator
  -	    createDatatypeValidator(XMLUni::fgIDRefsString, 
  +	    createDatatypeValidator(XMLUni::fgIDRefsString,
                       getDatatypeValidator(XMLUni::fgIDRefString), 0, true);
   
           // Create 'ENTITIES' datatype validator
  @@ -288,12 +295,12 @@
   		Janitor<KVStringPairHashTable> janFacets(facets);
   
           facets->put((void*) SchemaSymbols::fgELT_PATTERN ,
  -                    new KVStringPair(0,fgTokPattern));
  +                    new KVStringPair(SchemaSymbols::fgELT_PATTERN,fgTokPattern));
           facets->put((void*) SchemaSymbols::fgELT_WHITESPACE,
  -                    new KVStringPair(0, SchemaSymbols::fgWS_COLLAPSE));
  +                    new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_COLLAPSE));
   
           // Create 'NMTOKEN' datatype validator
  -        if (createDatatypeValidator(XMLUni::fgNmTokenString, 
  +        if (createDatatypeValidator(XMLUni::fgNmTokenString,
                       getDatatypeValidator(SchemaSymbols::fgDT_STRING),
                       facets, false) != 0) {
               janFacets.orphan();
  @@ -319,30 +326,34 @@
       }
   
       // Initialize common Schema/DTD Datatype validator set if not initialized
  -    if (fRegistry->get(XMLUni::fgIDRefString) == 0) {
  +    if (fRegistry->get(SchemaSymbols::fgDT_STRING) == 0) {
           initializeDTDRegistry();
       }
   
   	try {
  -        /* 
  -        fRegistry->put((void*) SchemaSymbols::fgDT_BOOLEAN, 
  -                       new BooleanDatatypeValidator(0,0));
  +        fRegistry->put((void*) SchemaSymbols::fgDT_BOOLEAN,
  +                       new BooleanDatatypeValidator());
  +/*
           fRegistry->put((void*) SchemaSymbols::fgDT_FLOAT,
  -                       new FloatDatatypeValidator(0,0));
  +                       new FloatDatatypeValidator());
           fRegistry->put((void*) SchemaSymbols::fgDT_DOUBLE,
  -                       new DoubleDatatypeValidator(0,0));
  +                       new DoubleDatatypeValidator());
           fRegistry->put((void*) SchemaSymbols::fgDT_DECIMAL,
  -                       new DecimalDatatypeValidator(0,0));
  -        fRegistry->put((void*) SchemaSymbols::fgDT_TIMEDURATION,
  -                       new TimeDurationDatatypeValidator());
  -        fRegistry->put((void*) SchemaSymbols::fgDT_RECURRINGDURATION,
  -                       new RecurringDurationDatatypeValidator(0,0));
  -        fRegistry->put((void*) SchemaSymbols::fgDT_BINARY,
  -                       new BinaryDatatypeValidator(0,0));
  -        fRegistry->put((void*) SchemaSymbols::fgDT_URIREFERENCE,
  -                       new URIReferenceDatatypeValidator(0,0));
  +                       new DecimalDatatypeValidator());
  +        fRegistry->put((void*) SchemaSymbols::fgDT_HEXBINARY,
  +                       new HexBinaryDatatypeValidator());
  +        fRegistry->put((void*) SchemaSymbols::fgDT_BASE64BINARY,
  +                       new Base64BinaryDatatypeValidator());
  +        fRegistry->put((void*) SchemaSymbols::fgDT_ANYURI,
  +                       new AnyURIDatatypeValidator());
           fRegistry->put((void*) SchemaSymbols::fgDT_QNAME,
  -                       new QNameDatatypeValidator(0,0)); 
  +                       new QNameDatatypeValidator());
  +        fRegistry->put((void*) SchemaSymbols::fgDT_DURATION,
  +                       new DurationDatatypeValidator());
  +        fRegistry->put((void*) SchemaSymbols::fgDT_DAY,
  +                       new DayDatatypeValidator());
  +        fRegistry->put((void*) SchemaSymbols::fgDT_TIME,
  +                       new TimeDatatypeValidator());
           */
   
           // REVISIT
  @@ -359,14 +370,14 @@
           // leaks. After each succesful datatype creation, we will orphan the
           // janitor, and then reset it with the new hashtable.
   
  -        // Create 'CDATA' datatype validator
  +        // Create 'normalizedString' datatype validator
           RefHashTableOf<KVStringPair>* facets = new RefHashTableOf<KVStringPair>(3);
   		Janitor<KVStringPairHashTable> janFacets(facets);
   
           facets->put((void*) SchemaSymbols::fgELT_WHITESPACE,
                       new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_REPLACE));
   
  -        if (createDatatypeValidator(XMLUni::fgCDATAString,
  +        if (createDatatypeValidator(SchemaSymbols::fgDT_NORMALIZEDSTRING,
                       getDatatypeValidator(SchemaSymbols::fgDT_STRING),
   				    facets, false) != 0) {
               janFacets.orphan();
  @@ -380,7 +391,7 @@
                       new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_COLLAPSE));
   
           if (createDatatypeValidator(SchemaSymbols::fgDT_TOKEN,
  -                      getDatatypeValidator(XMLUni::fgCDATAString),
  +                      getDatatypeValidator(SchemaSymbols::fgDT_NORMALIZEDSTRING),
                         facets, false) != 0) {
               janFacets.orphan();
           }
  @@ -392,7 +403,7 @@
           facets->put((void*) SchemaSymbols::fgELT_PATTERN,
                       new KVStringPair(SchemaSymbols::fgELT_PATTERN, fgLangPattern));
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_LANGUAGE, 
  +        if (createDatatypeValidator(SchemaSymbols::fgDT_LANGUAGE,
                         getDatatypeValidator(SchemaSymbols::fgDT_TOKEN),
                         facets, false ) != 0) {
               janFacets.orphan();
  @@ -428,8 +439,8 @@
           facets = new RefHashTableOf<KVStringPair>(3);
           janFacets.reset(facets);
   
  -        facets->put((void*) SchemaSymbols::fgELT_SCALE,
  -                    new KVStringPair(SchemaSymbols::fgELT_SCALE, fgValueZero));
  +        facets->put((void*) SchemaSymbols::fgELT_FRACTIONDIGITS,
  +                    new KVStringPair(SchemaSymbols::fgELT_FRACTIONDIGITS, fgValueZero));
   
           if (createDatatypeValidator(SchemaSymbols::fgDT_INTEGER,
                         getDatatypeValidator(SchemaSymbols::fgDT_DECIMAL),
  @@ -444,7 +455,7 @@
           facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE,
                       new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, fgValueZero));
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER, 
  +        if (createDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER,
                         getDatatypeValidator(SchemaSymbols::fgDT_INTEGER),
                         facets, false) != 0) {
               janFacets.orphan();
  @@ -457,7 +468,7 @@
           facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE,
   			        new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE,fgNegOne));
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_NEGATIVEINTEGER, 
  +        if (createDatatypeValidator(SchemaSymbols::fgDT_NEGATIVEINTEGER,
                         getDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER),
                         facets, false) != 0) {
               janFacets.orphan();
  @@ -499,11 +510,11 @@
   
           facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE,
                       new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, fgShortMaxInc));
  -        facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 
  +        facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE,
                       new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, fgShortMinInc));
   
           if (createDatatypeValidator(SchemaSymbols::fgDT_SHORT,
  -                      getDatatypeValidator(SchemaSymbols::fgDT_INT),                                
  +                      getDatatypeValidator(SchemaSymbols::fgDT_INT),
                         facets, false) != 0) {
               janFacets.orphan();
           }
  @@ -569,7 +580,7 @@
           facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE,
                       new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, fgUShortMaxInc));
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_USHORT, 
  +        if (createDatatypeValidator(SchemaSymbols::fgDT_USHORT,
                         getDatatypeValidator(SchemaSymbols::fgDT_UINT),
                         facets, false) != 0) {
               janFacets.orphan();
  @@ -601,102 +612,19 @@
               janFacets.orphan();
           }
   
  -        // Create 'timeInstant' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
  +        // REVISIT - Add the remaining datatype validators
  +        // Create 'dateTime' datatype validator
   
  -        facets->put((void*) SchemaSymbols::fgELT_DURATION,
  -                    new KVStringPair(SchemaSymbols::fgELT_DURATION, fgP0Y));
  -        facets->put((void*) SchemaSymbols::fgELT_PERIOD,
  -                    new KVStringPair(SchemaSymbols::fgELT_PERIOD, fgP0Y));
  -
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_TIMEINSTANT, 
  -                      getDatatypeValidator(SchemaSymbols::fgDT_RECURRINGDURATION),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
  -
  -        // Create 'time' datatype validator
  -
  -        // Create 'timePeriod' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
  -
  -        facets->put((void*) SchemaSymbols::fgELT_PERIOD,
  -                    new KVStringPair(SchemaSymbols::fgELT_PERIOD, fgP0Y));
  -
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_TIMEPERIOD,
  -                      getDatatypeValidator(SchemaSymbols::fgDT_RECURRINGDURATION),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
  -
           // Create 'date' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
   
  -        facets->put((void*) SchemaSymbols::fgELT_DURATION,
  -                    new KVStringPair(SchemaSymbols::fgELT_DURATION, fgPT24H));
  +        // Create 'gMonthDay' datatype validator
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_DATE,
  -                      getDatatypeValidator(SchemaSymbols::fgDT_TIMEPERIOD),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
  -
  -        // Create 'month' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
  -
  -        facets->put((void*) SchemaSymbols::fgELT_DURATION,
  -                    new KVStringPair(SchemaSymbols::fgELT_DURATION, fgP1M));
  -
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_MONTH,
  -                      getDatatypeValidator(SchemaSymbols::fgDT_TIMEPERIOD),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
  -
  -        // Create 'year' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
  -
  -        facets->put((void*) SchemaSymbols::fgELT_DURATION,
  -                    new KVStringPair(SchemaSymbols::fgELT_DURATION, fgP1Y));
  -
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_YEAR,
  -                      getDatatypeValidator(SchemaSymbols::fgDT_TIMEPERIOD),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
  -
  -        // Create 'century' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
  -
  -        facets->put((void*) SchemaSymbols::fgELT_DURATION,
  -                    new KVStringPair(SchemaSymbols::fgELT_DURATION, fgP100Y));
  +        // Create 'gYearMonth' datatype validator
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_CENTURY,
  -                      getDatatypeValidator(SchemaSymbols::fgDT_TIMEPERIOD),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
  -
  -        // Create 'recurringDate' datatype validator
  -        facets = new RefHashTableOf<KVStringPair>(3);
  -        janFacets.reset(facets);
  +        // Create 'gYear' datatype validator
   
  -        facets->put((void*) SchemaSymbols::fgELT_PERIOD,
  -                    new KVStringPair(SchemaSymbols::fgELT_PERIOD, fgP1Y));
  -        facets->put((void*) SchemaSymbols::fgELT_DURATION,
  -                    new KVStringPair(SchemaSymbols::fgELT_DURATION, fgPT24H));
  +        // Create 'gMonth' datatype validator
   
  -        if (createDatatypeValidator(SchemaSymbols::fgDT_RECURRINGDATE, 
  -                      getDatatypeValidator(SchemaSymbols::fgDT_RECURRINGDURATION),
  -                      facets, false) != 0) {
  -            janFacets.orphan();
  -        }
   
           fRegistryExpanded = true;
       }
  @@ -708,8 +636,8 @@
   // ---------------------------------------------------------------------------
   //  DatatypeValidatorFactory: factory methods
   // ---------------------------------------------------------------------------
  -DatatypeValidator* 
  -DatatypeValidatorFactory::createDatatypeValidator(const XMLCh* const typeName, 
  +DatatypeValidator*
  +DatatypeValidatorFactory::createDatatypeValidator(const XMLCh* const typeName,
   		                                          DatatypeValidator* const baseValidator,
                                                     RefHashTableOf<KVStringPair>* const facets,
                                                     const bool derivedByList,
  @@ -726,8 +654,16 @@
   		//datatypeValidator->setDerivedByList(derivedByList);
       }
       else {
  +
  +        if (baseValidator->getType() != DatatypeValidator::String) {
  +
  +            KVStringPair* value = facets->get(SchemaSymbols::fgELT_WHITESPACE);
  +
  +            if (value != 0) {
  +                facets->removeKey(SchemaSymbols::fgELT_WHITESPACE);
  +            }
  +        }
   
  -        baseValidator->processWhiteSpace(facets);
           datatypeValidator = baseValidator->newInstance(baseValidator, facets, finalSet);
       }
   
  @@ -752,7 +688,7 @@
       //datatypeValidator = new UnionDatatypeValidator(validators, finalSet);
   
       if (datatypeValidator != 0) {
  -        fRegistry->put((void*) typeName, datatypeValidator); 
  +        fRegistry->put((void*) typeName, datatypeValidator);
       }
   
       return datatypeValidator;
  
  
  
  1.3       +10 -2     xml-xerces/c/src/validators/datatype/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/Makefile.in,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Makefile.in	2001/03/21 21:39:15	1.2
  +++ Makefile.in	2001/05/09 18:43:41	1.3
  @@ -55,6 +55,9 @@
   #
   #
   # $Log: Makefile.in,v $
  +# Revision 1.3  2001/05/09 18:43:41  tng
  +# Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  +#
   # Revision 1.2  2001/03/21 21:39:15  knoaman
   # Schema symbols and Datatype validator part I
   #
  @@ -87,7 +90,9 @@
   	InvalidDatatypeFacetException.hpp \
   	InvalidDatatypeValueException.hpp \
   	DatatypeValidator.hpp \
  -	DatatypeValidatorFactory.hpp
  +	DatatypeValidatorFactory.hpp \
  +	BooleanDatatypeValidator.hpp \
  +	StringDatatypeValidator.hpp
   
   VALIDATORS_DATATYPE_CPP_PRIVHEADERS =
   
  @@ -95,7 +100,10 @@
   
   VALIDATORS_DATATYPE_CPP_OBJECTS = \
   	DatatypeValidator.$(TO) \
  -	DatatypeValidatorFactory.$(TO)
  +	DatatypeValidatorFactory.$(TO) \
  +	BooleanDatatypeValidator.$(TO) \
  +	StringDatatypeValidator.$(TO)
  +
   
   all::	includes $(VALIDATORS_DATATYPE_CPP_OBJECTS)
   
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/BooleanDatatypeValidator.cpp
  
  Index: BooleanDatatypeValidator.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   * 
   * Copyright (c) 1999-2000 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/>.
   */
  
  /*
   * $Log: BooleanDatatypeValidator.cpp,v $
   * Revision 1.1  2001/05/09 18:43:35  tng
   * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
   *
   */
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <validators/datatype/BooleanDatatypeValidator.hpp>
  #include <validators/schema/SchemaSymbols.hpp>
  #include <validators/datatype/InvalidDatatypeFacetException.hpp>
  #include <validators/datatype/InvalidDatatypeValueException.hpp>
  
  const int   SIZE = 4;
  const XMLCh fgValueSpace[][32] =
  {
      { chLatin_f, chLatin_a, chLatin_l, chLatin_s, chLatin_e, chNull },
      { chLatin_t, chLatin_r, chLatin_u, chLatin_e, chNull },
      { chDigit_0, chNull },
      { chDigit_1, chNull }
  };
  
  // ---------------------------------------------------------------------------
  //  Constructors and Destructor
  // ---------------------------------------------------------------------------
  BooleanDatatypeValidator::BooleanDatatypeValidator(
                            DatatypeValidator*            const baseValidator
                          , RefHashTableOf<KVStringPair>* const facets     
                          , const int                           finalSet)
  :DatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::Boolean)
  {
      // Set Facets if any defined
      if ( facets ) 
      { 
          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_PATTERN)==0) 
              {
                  setPattern(value);
                  setFacetsDefined(DatatypeValidator::FACET_PATTERN);
              } 
              else 
              {
                  ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Tag);
              }
  
          } 
  
      }// End of facet setting
  }
  
  void BooleanDatatypeValidator::checkContent( const XMLCh* const content, bool asBase)
  {
  
      //validate against base validator if any
      BooleanDatatypeValidator *pBaseValidator = (BooleanDatatypeValidator*) this->getBaseValidator();
      if (pBaseValidator !=0) 
          pBaseValidator->checkContent(content, true);
  
      // we check pattern first
      if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) 
      {
          // lazy construction
          if (getRegex() ==0)
              setRegex(new RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption));
  
          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;
  
      int   i = 0;
      for ( ; i < SIZE; i++ ) 
      {
          if ( XMLString::compareString(content, fgValueSpace[i]) ==0 )
              break;
      }
      
      if (i == SIZE)
          ThrowXML(InvalidDatatypeValueException, XMLExcepts::CM_UnaryOpHadBinType);
          //Not valid boolean type
  
  }
  
  int BooleanDatatypeValidator::compare(const XMLCh* const lValue
                                      , const XMLCh* const rValue)
  {
      // need to check by bool semantics
      // 1 == true
      // 0 == false
  
      if (( XMLString::compareString(lValue, fgValueSpace[0]) ==0 ) ||
          ( XMLString::compareString(lValue, fgValueSpace[2]) ==0 ) )
      {
          if (( XMLString::compareString(rValue, fgValueSpace[0]) ==0 ) ||
              ( XMLString::compareString(rValue, fgValueSpace[2]) ==0 ) )        
              return 0;
      }
      else 
      if (( XMLString::compareString(lValue, fgValueSpace[1]) ==0 ) ||
          ( XMLString::compareString(lValue, fgValueSpace[3]) ==0 ) )
      {
          if (( XMLString::compareString(rValue, fgValueSpace[1]) ==0 ) ||
              ( XMLString::compareString(rValue, fgValueSpace[3]) ==0 ) )        
              return 0;
      }
  
      return 1;
  }
  
  /**
    * End of file BooleanDatatypeValidator.cpp
    */
  
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/BooleanDatatypeValidator.hpp
  
  Index: BooleanDatatypeValidator.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   * 
   * Copyright (c) 1999-2000 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: BooleanDatatypeValidator.hpp,v 1.1 2001/05/09 18:43:37 tng Exp $
   */
  
  #if !defined(BOOLEAN_DATATYPEVALIDATOR_HPP)
  #define BOOLEAN_DATATYPEVALIDATOR_HPP
  
  #include <validators/datatype/DatatypeValidator.hpp>
  
  class VALIDATORS_EXPORT BooleanDatatypeValidator : public DatatypeValidator
  {
  public:
  
      // -----------------------------------------------------------------------
      //  Public ctor/dtor
      // -----------------------------------------------------------------------
  	/** @name Constructor. */
      //@{
  
      BooleanDatatypeValidator();
  
      BooleanDatatypeValidator(DatatypeValidator*            const baseValidator
                             , RefHashTableOf<KVStringPair>* const facets     
                             , const int                           finalSet);
  
      virtual ~BooleanDatatypeValidator();
  
  	//@}
  
      // -----------------------------------------------------------------------
      // Getter methods
      // -----------------------------------------------------------------------
      /** @name Getter Functions */
      //@{
  
  
      //@}
  
      // -----------------------------------------------------------------------
      // 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
                                   , const int                           finalSet);
  
  private:
  
      void checkContent(const XMLCh* const content, bool asBase);
  
      // -----------------------------------------------------------------------
      //  Private data members
      //
      // -----------------------------------------------------------------------    
  
  };
  
  // ---------------------------------------------------------------------------
  //  Constructors and Destructor
  // ---------------------------------------------------------------------------
  inline BooleanDatatypeValidator::BooleanDatatypeValidator()
  :DatatypeValidator(0, 0, 0, DatatypeValidator::Boolean)
  {
  }
  
  inline BooleanDatatypeValidator::~BooleanDatatypeValidator()
  {
  }
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  
  
  // -----------------------------------------------------------------------
  // Compare methods
  // -----------------------------------------------------------------------
  
  inline DatatypeValidator* BooleanDatatypeValidator::newInstance(
                                        DatatypeValidator* const            baseValidator
                                      , RefHashTableOf<KVStringPair>* const facets
                                      , const int                           finalSet)
  {
      return (DatatypeValidator*) new BooleanDatatypeValidator(baseValidator, facets, finalSet);
  }
  
  inline void BooleanDatatypeValidator::validate( const XMLCh* const content)
  {
      checkContent(content, false);
  }
  
  /**
    * End of file BooleanDatatypeValidator.hpp
    */
  #endif
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/StringDatatypeValidator.cpp
  
  Index: StringDatatypeValidator.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   * 
   * Copyright (c) 1999-2000 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/>.
   */
  
  /*
   * $Log: StringDatatypeValidator.cpp,v $
   * Revision 1.1  2001/05/09 18:43:42  tng
   * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
   *
   */
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <validators/datatype/StringDatatypeValidator.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
  // ---------------------------------------------------------------------------
  StringDatatypeValidator::StringDatatypeValidator(
                            DatatypeValidator*            const baseValidator
                          , RefHashTableOf<KVStringPair>* const facets     
                          , const int                           finalSet)
  :DatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::String)
  ,fLength(0)
  ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  ,fMinLength(0)
  ,fEnumeration(0)
  ,fWhiteSpace(DatatypeValidator::PRESERVE)
  {
      try
      {
          init(baseValidator, facets);
      }
      catch (XMLException&)
      {
          cleanUp();
      }
  }
  
  void StringDatatypeValidator::init(DatatypeValidator*            const baseValidator
                                   , RefHashTableOf<KVStringPair>* const facets)
  {
      // Set Facets if any defined
      if (facets) 
      { 
          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) 
              {        
                  try
                  {
                      setLength(XMLString::parseInt(value));
                  }
                  catch (NumberFormatException nfe)
                  {
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value);
                  }
  
                  if (getLength() < 0)
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value);
  
                  setFacetsDefined(DatatypeValidator::FACET_LENGTH);
              } 
              else if (XMLString::compareString(key, SchemaSymbols::fgELT_MINLENGTH)==0)
              {
                  try
                  {
                      setMinLength(XMLString::parseInt(value));
                  }
                  catch (NumberFormatException nfe)
                  {
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value);
                  }
  
                  if (getMinLength() < 0)
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value);
  
                  setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
              } 
              else if (XMLString::compareString(key, SchemaSymbols::fgELT_MAXLENGTH)==0)
              {
                  try
                  {
                      setMaxLength(XMLString::parseInt(value));
                  }
                  catch (NumberFormatException nfe)
                  {
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value);
                  }
  
                  if (getMaxLength() < 0)
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value);
  
                  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::fgELT_ENUMERATION)==0)
              {
                  setEnumeration(XMLString::tokenizeString(value));
                  setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
              } 
              else if (XMLString::compareString(key, SchemaSymbols::fgELT_WHITESPACE)==0)
              {
                  // whiteSpace = preserve | replace | collapse
                  if (XMLString::compareString(value, SchemaSymbols::fgWS_PRESERVE) == 0) 
                      setWhiteSpace(DatatypeValidator::PRESERVE);
                  else if (XMLString::compareString(value, SchemaSymbols::fgWS_REPLACE) == 0) 
                      setWhiteSpace(DatatypeValidator::REPLACE);
                  else if (XMLString::compareString(value, SchemaSymbols::fgWS_COLLAPSE) == 0) 
                      setWhiteSpace(DatatypeValidator::COLLAPSE);
                  else 
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_WS, value);
                      //("whiteSpace value '" + ws + "' must be one of 'preserve', 'replace', 'collapse'.");
  
                  setFacetsDefined(DatatypeValidator::FACET_WHITESPACE);
              } 
              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.
              ***/
              StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) 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 (pBaseVlidator->getFixed(DatatypeValidator::FACET_LENGTH) == true)
                  //     if ( getLength() != pBaseValidator->getLength() )
                  //         ThrowXML
                  // else
                  //     if ( getLength() > pBaseValidator->getLength() )
                  //         ThrowXML
                  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 (pBaseVlidator->getFixed(DatatypeValidator::FACET_MINLENGTH) == true)
                  //     if ( getMinLength() != pBaseValidator->getMinLength() )
                  //         ThrowXML
                  // else
                  //     if ( getMinLength() < pBaseValidator->getMinLength() )
                  //         ThrowXML
                  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 (pBaseVlidator->getFixed(DatatypeValidator::FACET_MAXLENGTH) == true)
                  //     if ( getMaxLength() != pBaseValidator->getMaxLength() )
                  //         ThrowXML
                  // else
                  //     if ( getMaxLength() > pBaseValidator->getMaxLength() )
                  //         ThrowXML
                  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));
                  }
              }
  
              // check 4.3.6.c1 error: whitespace
              if (((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0) &&
                  ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0 )) 
              {
                  if ((pBaseValidator->getWSFacet() == DatatypeValidator::COLLAPSE) &&
                      ((getWSFacet() == DatatypeValidator::PRESERVE) ||
                       (getWSFacet() == DatatypeValidator::REPLACE)))
                       ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_collapse);
  
                  if ((pBaseValidator->getWSFacet() == DatatypeValidator::PRESERVE) &&
                      (getWSFacet() == DatatypeValidator::REPLACE))
                       ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_replace);
              }
  
              /***
                  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))
              {
                  // need to adopt the Vector   
                  RefVectorOf<XMLCh>*  fBaseEnumeration = pBaseValidator->getEnumeration();
                  int enumLength = fBaseEnumeration->size();
                  
                  RefVectorOf<XMLCh>* tmpEnumeration = new RefVectorOf<XMLCh>(enumLength, true);
                  for ( int i = 0; i < enumLength; i++) 
                  {
                      int strLen = XMLString::stringLen(fBaseEnumeration->elementAt(i));
                      XMLCh* tmp = new XMLCh[strLen+1];
                      XMLString::moveChars(tmp, fBaseEnumeration->elementAt(i), strLen);
                      tmpEnumeration->insertElementAt(tmp, i);
                  }
  
                  setEnumeration(tmpEnumeration);
                  setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
              }
  
              // we don't inherit pattern
  
              // inherit whitespace
              if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) !=0) &&
                  ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) == 0))
              {
                  setWhiteSpace(pBaseValidator->getWSFacet());
                  setFacetsDefined(DatatypeValidator::FACET_WHITESPACE);
              }
  
          } //if baseValidator
  
      }// End of Facet setting
  
  }
  
  void StringDatatypeValidator::checkContent( const XMLCh* const content, bool asBase)
  {
  
      //validate against base validator if any
      StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) this->getBaseValidator();
      if (pBaseValidator !=0) 
          pBaseValidator->checkContent(content, true);
  
      // we check pattern first
      if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) 
      {
          // lazy construction
          if (getRegex() ==0)
              setRegex(new RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption));
  
          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 strLen = XMLString::stringLen(content);
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
          (strLen > getMaxLength()))
      {
          XMLString::binToText(strLen, 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) &&
          (strLen < getMinLength()))
      {
          XMLString::binToText(strLen, 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) &&
          (strLen != getLength()))
      {
          XMLString::binToText(strLen, 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);
      }
  
  }
  
  /**
    * End of file StringDatatypeValidator.cpp
    */
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/StringDatatypeValidator.hpp
  
  Index: StringDatatypeValidator.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   * 
   * Copyright (c) 1999-2000 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: StringDatatypeValidator.hpp,v 1.1 2001/05/09 18:43:43 tng Exp $
   */
  
  #if !defined(STRING_DATATYPEVALIDATOR_HPP)
  #define STRING_DATATYPEVALIDATOR_HPP
  
  #include <validators/datatype/DatatypeValidator.hpp>
  #include <validators/schema/SchemaSymbols.hpp>
  
  class VALIDATORS_EXPORT StringDatatypeValidator : public DatatypeValidator
  {
  public:
  
      // -----------------------------------------------------------------------
      //  Public ctor/dtor
      // -----------------------------------------------------------------------
  	/** @name Constructor. */
      //@{
  
      StringDatatypeValidator();
  
      StringDatatypeValidator(DatatypeValidator*            const baseValidator
                            , RefHashTableOf<KVStringPair>* const facets     
                            , const int                           finalSet);
  
  
      virtual ~StringDatatypeValidator();
  
  	//@}
  
      // -----------------------------------------------------------------------
      // Getter methods
      // -----------------------------------------------------------------------
      /** @name Getter Functions */
      //@{
  
      short getWSFacet() const;
  
      //@}
  
      // -----------------------------------------------------------------------
      // 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
                                   , const int                           finalSet);
  
  private:
  
      void checkContent(const XMLCh* const content, bool asBase);
  
      void init(DatatypeValidator*            const baseValidator
              , RefHashTableOf<KVStringPair>* const facets);
  
      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>* );
  
      void                 setWhiteSpace(short);
  
      // -----------------------------------------------------------------------
      //  Private data members
      //
      // -----------------------------------------------------------------------    
       unsigned int         fLength;
       unsigned int         fMaxLength;  
       unsigned int         fMinLength;  
       RefVectorOf<XMLCh>*  fEnumeration;
       short                fWhiteSpace;         //DatatypeValidator::PRESERVE
  
  };
  
  // ---------------------------------------------------------------------------
  //  Constructors and Destructor
  // ---------------------------------------------------------------------------
  inline StringDatatypeValidator::StringDatatypeValidator()
  :DatatypeValidator(0, 0, 0, DatatypeValidator::String)
  ,fLength(0)
  ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  ,fMinLength(0)
  ,fEnumeration(0)
  ,fWhiteSpace(DatatypeValidator::PRESERVE)
  {}
  
  inline StringDatatypeValidator::~StringDatatypeValidator()
  {
      cleanUp();
  }
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  inline short StringDatatypeValidator::getWSFacet() const {
  
      return fWhiteSpace;
  }
  
  // -----------------------------------------------------------------------
  // Compare methods
  // -----------------------------------------------------------------------
  inline int StringDatatypeValidator::compare(const XMLCh* const lValue
                                            , const XMLCh* const rValue)
  {
      return XMLString::compareString(lValue, rValue);
  }
  
  inline DatatypeValidator* StringDatatypeValidator::newInstance(
                                        DatatypeValidator* const            baseValidator
                                      , RefHashTableOf<KVStringPair>* const facets
                                      , const int                           finalSet)
  {
      return (DatatypeValidator*) new StringDatatypeValidator(baseValidator, facets, finalSet);
  }
  
  inline void StringDatatypeValidator::validate( const XMLCh* const content)
  {
      checkContent(content, false);
  }
  
  inline void StringDatatypeValidator::cleanUp()
  {
      //~RefVectorOf will delete all adopted elements
      delete fEnumeration;
  }
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  
  inline unsigned int StringDatatypeValidator::getLength() const
  {
      return fLength;
  }
  
  inline unsigned int StringDatatypeValidator::getMaxLength() const
  {
      return fMaxLength;
  }
  
  inline unsigned int StringDatatypeValidator::getMinLength() const
  {
      return fMinLength;
  }
  
  inline RefVectorOf<XMLCh>* StringDatatypeValidator:: getEnumeration() const
  {
      return fEnumeration;
  }
  
  // -----------------------------------------------------------------------
  // Setter methods
  // -----------------------------------------------------------------------
  
  inline void StringDatatypeValidator::setLength(unsigned int newLength)
  {
      fLength = newLength;
  }
  
  inline void StringDatatypeValidator::setMaxLength(unsigned int newMaxLength)
  {
      fMaxLength = newMaxLength;
  }
  
  inline void StringDatatypeValidator::setMinLength(unsigned int newMinLength)
  {
      fMinLength = newMinLength;
  }
  
  inline void StringDatatypeValidator::setEnumeration(RefVectorOf<XMLCh>* newEnum)
  {
      if (fEnumeration)
          delete fEnumeration;
  
      fEnumeration = newEnum;
  }
  
  inline void StringDatatypeValidator::setWhiteSpace(short newValue)
  {
      fWhiteSpace = newValue;
  }
  
  /**
    * End of file StringDatatypeValidator.hpp
    */
  #endif
  
  
  
  1.3       +42 -16    xml-xerces/c/src/validators/schema/SchemaSymbols.cpp
  
  Index: SchemaSymbols.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaSymbols.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SchemaSymbols.cpp	2001/05/03 19:18:03	1.2
  +++ SchemaSymbols.cpp	2001/05/09 18:43:49	1.3
  @@ -1,37 +1,37 @@
   /*
    * The Apache Software License, Version 1.1
  - * 
  + *
    * Copyright (c) 1999-2000 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. 
  - * 
  + *    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:  
  + *    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 
  + *    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
  @@ -45,7 +45,7 @@
    * 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
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: SchemaSymbols.cpp,v $
  + * Revision 1.3  2001/05/09 18:43:49  tng
  + * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  + *
    * Revision 1.2  2001/05/03 19:18:03  knoaman
    * TraverseSchema Part II.
    *
  @@ -307,9 +310,10 @@
       chLatin_i, chLatin_o, chLatin_n,  chNull
   };
   
  -const XMLCh SchemaSymbols::fgELT_SCALE[] =
  +const XMLCh SchemaSymbols::fgELT_FRACTIONDIGITS[] =
   {
  -    chLatin_s, chLatin_c, chLatin_a, chLatin_l, chLatin_e,  chNull
  +    chLatin_f, chLatin_r, chLatin_a, chLatin_c, chLatin_t, chLatin_i, chLatin_o,
  +    chLatin_n, chLatin_D, chLatin_i, chLatin_g, chLatin_i, chLatin_t, chLatin_s, chNull
   };
   
   const XMLCh SchemaSymbols::fgELT_SCHEMA[] =
  @@ -363,7 +367,7 @@
       chLatin_o, chLatin_n, chLatin_t, chLatin_e, chLatin_n, chLatin_t, chNull
   };
   
  -const XMLCh SchemaSymbols::fgELT_RESTRICTION[] = 
  +const XMLCh SchemaSymbols::fgELT_RESTRICTION[] =
   {
       chLatin_r, chLatin_e, chLatin_s, chLatin_t, chLatin_r, chLatin_i,
       chLatin_c, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull
  @@ -580,7 +584,7 @@
       chLatin_a, chLatin_c, chLatin_e, chNull
   };
   
  -const XMLCh SchemaSymbols::fgATTVAL_POUNDALL[] = 
  +const XMLCh SchemaSymbols::fgATTVAL_POUNDALL[] =
   {
       chPound, chLatin_a, chLatin_l, chLatin_l, chNull
   };
  @@ -769,6 +773,12 @@
       chLatin_e, chNull
   };
   
  +const XMLCh SchemaSymbols::fgWS_PRESERVE[] =
  +{
  +    chLatin_p, chLatin_r, chLatin_e, chLatin_s, chLatin_e, chLatin_r,
  +    chLatin_v, chLatin_e, chNull
  +};
  +
   const XMLCh SchemaSymbols::fgWS_COLLAPSE[] =
   {
       chLatin_c, chLatin_o, chLatin_l, chLatin_l, chLatin_a, chLatin_p,
  @@ -969,6 +979,22 @@
   {
       chLatin_Q, chLatin_N, chLatin_a, chLatin_m, chLatin_e, chNull
   };
  +
  +const XMLCh SchemaSymbols::fgDT_NORMALIZEDSTRING[] =
  +{
  +    chLatin_n, chLatin_o, chLatin_r, chLatin_m, chLatin_a, chLatin_l, chLatin_i,
  +    chLatin_z, chLatin_e, chLatin_d, chLatin_S, chLatin_t, chLatin_r, chLatin_i,
  +    chLatin_n, chLatin_g, chNull
  +};
  +
  +const XMLCh SchemaSymbols::fgRegEx_XOption[] =
  +{
  +    chLatin_X, chNull
  +};
  +
  +const int SchemaSymbols::fgINT_MIN_VALUE = 0x80000000;
  +
  +const int SchemaSymbols::fgINT_MAX_VALUE = 0x7fffffff;
   
   /**
     * End of file SchemaSymbols.cpp
  
  
  
  1.4       +8 -3      xml-xerces/c/src/validators/schema/SchemaSymbols.hpp
  
  Index: SchemaSymbols.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaSymbols.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SchemaSymbols.hpp	2001/05/03 20:34:44	1.3
  +++ SchemaSymbols.hpp	2001/05/09 18:43:50	1.4
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: SchemaSymbols.hpp,v 1.3 2001/05/03 20:34:44 tng Exp $
  + * $Id: SchemaSymbols.hpp,v 1.4 2001/05/09 18:43:50 tng Exp $
    */
   
   #if !defined(SCHEMASYMBOLS_HPP)
  @@ -111,7 +111,7 @@
       static const XMLCh fgELT_PATTERN[];
       static const XMLCh fgELT_PERIOD[];
       static const XMLCh fgELT_PRECISION[];
  -    static const XMLCh fgELT_SCALE[];
  +    static const XMLCh fgELT_FRACTIONDIGITS[];
       static const XMLCh fgELT_SCHEMA[];
       static const XMLCh fgELT_SELECTOR[];
       static const XMLCh fgELT_SEQUENCE[];
  @@ -193,6 +193,7 @@
       static const XMLCh fgATTVAL_SUBSTITUTIONGROUP[];
       static const XMLCh fgATTVAL_SUBSTITUTION[];
       static const XMLCh fgATTVAL_ANYTYPE[];
  +    static const XMLCh fgWS_PRESERVE[];
       static const XMLCh fgWS_COLLAPSE[];
       static const XMLCh fgWS_REPLACE[];
       static const XMLCh fgDT_STRING[];
  @@ -229,6 +230,10 @@
       static const XMLCh fgDT_DOUBLE[];
       static const XMLCh fgDT_URIREFERENCE[];
       static const XMLCh fgDT_QNAME[];
  +    static const XMLCh fgDT_NORMALIZEDSTRING[];
  +    static const XMLCh fgRegEx_XOption[];
  +    static const int   fgINT_MIN_VALUE;
  +    static const int   fgINT_MAX_VALUE;
   
       enum {
           EMPTY_SET = 0,
  @@ -251,7 +256,7 @@
           INFINITY = -1,
           NILLABLE = 1,
           ABSTRACT = 2,
  -        FIXED    = 4
  +        FIXED = 4
       };
   
   };
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org