You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2001/09/24 17:31:13 UTC
cvs commit: xml-xerces/c/src/validators/datatype StringDatatypeValidator.hpp StringDatatypeValidator.cpp
peiyongz 01/09/24 08:31:13
Modified: c/src/validators/datatype StringDatatypeValidator.hpp
StringDatatypeValidator.cpp
Log:
DTV Reorganization: inherit from AbstractStringValidator
Revision Changes Path
1.6 +20 -168 xml-xerces/c/src/validators/datatype/StringDatatypeValidator.hpp
Index: StringDatatypeValidator.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/StringDatatypeValidator.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StringDatatypeValidator.hpp 2001/08/24 17:12:01 1.5
+++ StringDatatypeValidator.hpp 2001/09/24 15:31:13 1.6
@@ -55,16 +55,19 @@
*/
/*
- * $Id: StringDatatypeValidator.hpp,v 1.5 2001/08/24 17:12:01 knoaman Exp $
+ * $Id: StringDatatypeValidator.hpp,v 1.6 2001/09/24 15:31:13 peiyongz Exp $
+ * $Log: StringDatatypeValidator.hpp,v $
+ * Revision 1.6 2001/09/24 15:31:13 peiyongz
+ * DTV Reorganization: inherit from AbstractStringValidator
+ *
*/
#if !defined(STRING_DATATYPEVALIDATOR_HPP)
#define STRING_DATATYPEVALIDATOR_HPP
-#include <validators/datatype/DatatypeValidator.hpp>
-#include <validators/schema/SchemaSymbols.hpp>
+#include <validators/datatype/AbstractStringValidator.hpp>
-class VALIDATORS_EXPORT StringDatatypeValidator : public DatatypeValidator
+class VALIDATORS_EXPORT StringDatatypeValidator : public AbstractStringValidator
{
public:
@@ -81,7 +84,6 @@
, RefVectorOf<XMLCh>* const enums
, const int finalSet);
-
virtual ~StringDatatypeValidator();
//@}
@@ -91,43 +93,8 @@
// -----------------------------------------------------------------------
/** @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);
+ virtual short getWSFacet() const;
//@}
@@ -135,153 +102,41 @@
* Returns an instance of the base datatype validator class
* Used by the DatatypeValidatorFactory.
*/
- DatatypeValidator* newInstance(RefHashTableOf<KVStringPair>* const facets
- , RefVectorOf<XMLCh>* const enums
- , const int finalSet);
+ virtual DatatypeValidator* newInstance(RefHashTableOf<KVStringPair>* const facets
+ , RefVectorOf<XMLCh>* const enums
+ , const int finalSet);
-private:
+protected:
- void checkContent(const XMLCh* const content, bool asBase);
+ virtual void assignAdditionalFacet(const XMLCh* const key
+ , const XMLCh* const value);
- void init(DatatypeValidator* const baseValidator
- , RefHashTableOf<KVStringPair>* const facets
- , RefVectorOf<XMLCh>* const enums);
+ virtual void inheritAdditionalFacet();
- void cleanUp();
+ virtual void checkAdditionalFacetConstraints() const;
-// -----------------------------------------------------------------------
-// Getter methods
-// -----------------------------------------------------------------------
+ virtual void checkAdditionalFacet(const XMLCh* const content) const;
- unsigned int getLength() const;
+ inline virtual void checkValueSpace(const XMLCh* const content);
- unsigned int getMaxLength() const;
+ inline virtual int getLength(const XMLCh* const content) const;
- unsigned int getMinLength() const;
-
- RefVectorOf<XMLCh>* getEnumeration() const;
-
-// -----------------------------------------------------------------------
-// Setter methods
-// -----------------------------------------------------------------------
-
- void setLength(unsigned int);
-
- void setMaxLength(unsigned int);
-
- void setMinLength(unsigned int);
-
- void setEnumeration(RefVectorOf<XMLCh>*, bool);
+private:
- void setWhiteSpace(short);
+ inline void setWhiteSpace(short);
// -----------------------------------------------------------------------
// Private data members
//
// -----------------------------------------------------------------------
- unsigned int fLength;
- unsigned int fMaxLength;
- unsigned int fMinLength;
- bool fEnumerationInherited;
short fWhiteSpace; //DatatypeValidator::PRESERVE
- RefVectorOf<XMLCh>* fEnumeration;
-};
-// -----------------------------------------------------------------------
-// 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(
- RefHashTableOf<KVStringPair>* const facets
- , RefVectorOf<XMLCh>* const enums
- , const int finalSet)
-{
- return (DatatypeValidator*) new StringDatatypeValidator(this, facets, enums, finalSet);
-}
-
-inline void StringDatatypeValidator::validate( const XMLCh* const content)
-{
- checkContent(content, false);
-}
-
-inline void StringDatatypeValidator::cleanUp()
-{
- //~RefVectorOf will delete all adopted elements
- if (fEnumeration && !fEnumerationInherited)
- 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>* enums
- , bool inherited)
-{
- if (enums)
- {
- if (fEnumeration && !fEnumerationInherited)
- delete fEnumeration;
-
- fEnumeration = enums;
- fEnumerationInherited = inherited;
- setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
- }
-}
-
-inline void StringDatatypeValidator::setWhiteSpace(short newValue)
+void StringDatatypeValidator::setWhiteSpace(short newValue)
{
fWhiteSpace = newValue;
}
1.14 +83 -517 xml-xerces/c/src/validators/datatype/StringDatatypeValidator.cpp
Index: StringDatatypeValidator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/StringDatatypeValidator.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- StringDatatypeValidator.cpp 2001/09/20 13:11:42 1.13
+++ StringDatatypeValidator.cpp 2001/09/24 15:31:13 1.14
@@ -56,8 +56,8 @@
/*
* $Log: StringDatatypeValidator.cpp,v $
- * Revision 1.13 2001/09/20 13:11:42 knoaman
- * Regx + misc. fixes
+ * Revision 1.14 2001/09/24 15:31:13 peiyongz
+ * DTV Reorganization: inherit from AbstractStringValidator
*
* Revision 1.12 2001/08/21 18:42:53 peiyongz
* Bugzilla# 2816: cleanUp() declared with external linkage and called
@@ -102,9 +102,9 @@
// Includes
// ---------------------------------------------------------------------------
#include <validators/datatype/StringDatatypeValidator.hpp>
+#include <validators/schema/SchemaSymbols.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];
@@ -114,554 +114,113 @@
// Constructors and Destructor
// ---------------------------------------------------------------------------
StringDatatypeValidator::StringDatatypeValidator()
-:DatatypeValidator(0, 0, 0, DatatypeValidator::String)
-,fLength(0)
-,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
-,fMinLength(0)
-,fEnumerationInherited(false)
+:AbstractStringValidator(0, 0, 0, DatatypeValidator::String)
,fWhiteSpace(DatatypeValidator::PRESERVE)
-,fEnumeration(0)
{}
StringDatatypeValidator::~StringDatatypeValidator()
-{
- cleanUp();
-}
+{}
StringDatatypeValidator::StringDatatypeValidator(
DatatypeValidator* const baseValidator
, RefHashTableOf<KVStringPair>* const facets
, RefVectorOf<XMLCh>* const enums
, const int finalSet)
-:DatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::String)
-,fLength(0)
-,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
-,fMinLength(0)
-,fEnumerationInherited(false)
+:AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::String)
,fWhiteSpace(DatatypeValidator::PRESERVE)
-,fEnumeration(0)
{
- try
- {
- init(baseValidator, facets, enums);
- }
- catch (...)
- {
- cleanUp();
- throw;
- }
+ init(baseValidator, facets, enums);
}
-void StringDatatypeValidator::init(DatatypeValidator* const baseValidator
- , RefHashTableOf<KVStringPair>* const facets
- , RefVectorOf<XMLCh>* const enums)
+DatatypeValidator* StringDatatypeValidator::newInstance(
+ RefHashTableOf<KVStringPair>* const facets
+ , RefVectorOf<XMLCh>* const enums
+ , const int finalSet)
{
- // Set Facets if any defined
- if (facets)
- {
- if (enums)
- setEnumeration(enums, false);
-
- XMLCh* key;
- XMLCh* value;
- RefHashTableOfEnumerator<KVStringPair> e(facets);
-
-
- while (e.hasMoreElements())
- {
- KVStringPair pair = e.nextElement();
- key = pair.getKey();
- value = pair.getValue();
-
- if (XMLString::compareString(key, SchemaSymbols::fgELT_LENGTH)==0)
- {
- int val;
- try
- {
- val = XMLString::parseInt(value);
- }
- catch (NumberFormatException nfe)
- {
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value);
- }
-
- if ( val < 0 )
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value);
-
- setLength(val);
- setFacetsDefined(DatatypeValidator::FACET_LENGTH);
- }
- else if (XMLString::compareString(key, SchemaSymbols::fgELT_MINLENGTH)==0)
- {
- int val;
- try
- {
- val = XMLString::parseInt(value);
- }
- catch (NumberFormatException nfe)
- {
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value);
- }
-
- if ( val < 0 )
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value);
-
- setMinLength(val);
- setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
- }
- else if (XMLString::compareString(key, SchemaSymbols::fgELT_MAXLENGTH)==0)
- {
- int val;
- try
- {
- val = XMLString::parseInt(value);
- }
- catch (NumberFormatException nfe)
- {
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value);
- }
-
- if ( val < 0 )
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value);
-
- setMaxLength(val);
- setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
- }
- else if (XMLString::compareString(key, SchemaSymbols::fgELT_PATTERN)==0)
- {
- setPattern(value);
- if (getPattern())
- setFacetsDefined(DatatypeValidator::FACET_PATTERN);
- // do not construct regex until needed
- }
- else if (XMLString::compareString(key, SchemaSymbols::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 if (XMLString::compareString(key, SchemaSymbols::fgATT_FIXED)==0)
- {
- unsigned int val;
- bool retStatus;
- try
- {
- retStatus = XMLString::textToBin(value, val);
- }
- catch (RuntimeException)
- {
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
- }
-
- if (!retStatus)
- {
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
- }
-
- setFixed(val);
- //no setFacetsDefined here
- }
- else
- {
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Tag);
- }
- }//while
-
- /***
- Schema constraint: Part I -- self checking
- ***/
-
- // check 4.3.1.c1 error: length & (maxLength | minLength)
- if ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0)
- {
- if ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0)
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
- else if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0))
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
- }
-
- // check 4.3.2.c1 must: minLength <= maxLength
- if ((getFacetsDefined() & (DatatypeValidator::FACET_MINLENGTH
- |DatatypeValidator::FACET_MAXLENGTH)) != 0)
- {
- if ( getMinLength() > getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_minLen
- , value1
- , value2);
- }
- }
-
- /***
- Schema constraint: Part II base vs derived checking
- ***/
- if (baseValidator != 0)
- {
- /***
- check facets against base.facets
- Note: later we need to check the "fix" option of the base type
- and apply that to every individual facet.
- ***/
- 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 ( getLength() != pBaseValidator->getLength() )
- {
- XMLString::binToText(getLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_Len_baseLen
- , value1
- , value2);
- }
- }
-
- /***
- |--- derived ---|
- base.minLength <= minLength <= maxLength <= base.maxLength
- |------------------- base -------------------|
- ***/
-
- // check 4.3.2.c1 must: minLength <= base.maxLength
- if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH ) != 0) &&
- ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH ) != 0))
- {
- if ( getMinLength() > pBaseValidator->getMaxLength() )
- {
- XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_minLen_baseminLen
- , value1
- , value2);
- }
- }
-
- // check 4.3.2.c2 error: minLength < base.minLength
- if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) &&
- ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0))
- {
- if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MINLENGTH) !=0)
- {
- if ( getMinLength() != pBaseValidator->getMinLength() )
- {
- XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_minLen_base_fixed
- , value1
- , value2);
- }
- }
- else
- {
- if ( getMinLength() < pBaseValidator->getMinLength() )
- {
- XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_minLen_basemaxLen
- , value1
- , value2);
- }
- }
- }
-
- // check 4.3.2.c1 must: base.minLength <= maxLength
- if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) &&
- ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0))
- {
- if ( pBaseValidator->getMinLength() > getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_baseminLen
- , value1
- , value2);
- }
- }
-
- // check 4.3.3.c1 error: maxLength > base.maxLength
- if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
- ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0))
- {
- if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MAXLENGTH) !=0)
- {
- if ( getMaxLength() != pBaseValidator->getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_base_fixed
- , value1
- , value2);
- }
- }
- else
- {
- if ( getMaxLength() > pBaseValidator->getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_basemaxLen
- , value1
- , value2);
- }
- }
- }
-
- // check 4.3.5.c0 must: enumeration values from the value space of base
- if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) &&
- (getEnumeration() !=0))
- {
- int i = 0;
- int enumLength = getEnumeration()->size();
- try
- {
- for ( ; i < enumLength; i++)
- {
- // ask parent do a complete check
- pBaseValidator->checkContent(getEnumeration()->elementAt(i), false);
- // 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::REPLACE) &&
- (getWSFacet() == DatatypeValidator::PRESERVE))
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_replace);
-
- if (((pBaseValidator->getFixed() & DatatypeValidator::FACET_WHITESPACE) !=0) &&
- ( getWSFacet() != pBaseValidator->getWSFacet()))
- {
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_whitespace_base_fixed
- , getWSstring(getWSFacet())
- , getWSstring(pBaseValidator->getWSFacet()));
- }
- }
-
- } //if baseValidator
-
- }// End of Facet setting
-
- /***
- 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.
- ***/
- if ( baseValidator )
- {
- StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) baseValidator;
-
- // inherit length
- if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
- ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) == 0))
- {
- setLength(pBaseValidator->getLength());
- setFacetsDefined(DatatypeValidator::FACET_LENGTH);
- }
-
- // inherit minLength
- if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) &&
- ((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) == 0))
- {
- setMinLength(pBaseValidator->getMinLength());
- setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
- }
-
- // inherit maxLength
- if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
- ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) == 0))
- {
- setMaxLength(pBaseValidator->getMaxLength());
- setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
- }
-
- // inherit enumeration
- if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) !=0) &&
- ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) == 0))
- {
- setEnumeration(pBaseValidator->getEnumeration(), true);
- }
-
- // we don't inherit pattern
-
- // inherit whitespace
- if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) !=0) &&
- ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) == 0))
- {
- setWhiteSpace(pBaseValidator->getWSFacet());
- setFacetsDefined(DatatypeValidator::FACET_WHITESPACE);
- }
-
- // inherit "fixed" option
- setFixed(getFixed() | pBaseValidator->getFixed());
-
- } // end of inheritance
+ return (DatatypeValidator*) new StringDatatypeValidator(this, facets, enums, finalSet);
}
-void StringDatatypeValidator::checkContent( const XMLCh* const content, bool asBase)
+short StringDatatypeValidator::getWSFacet() const
{
-
- //validate against base validator if any
- StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) this->getBaseValidator();
- if (pBaseValidator !=0)
- pBaseValidator->checkContent(content, true);
+ return fWhiteSpace;
+}
- // we check pattern first
- if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 )
+// ---------------------------------------------------------------------------
+// Utilities
+// ---------------------------------------------------------------------------
+void StringDatatypeValidator::assignAdditionalFacet(const XMLCh* const key
+ , const XMLCh* const value)
+{
+ if (XMLString::compareString(key, SchemaSymbols::fgELT_WHITESPACE)==0)
{
- // lazy construction
- if (getRegex() ==0) {
- try {
- setRegex(new RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption));
- }
- catch (XMLException &e)
- {
- ThrowXML1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage());
- }
- }
-
- if (getRegex()->matches(content) ==false)
- {
- ThrowXML2(InvalidDatatypeValueException
- , XMLExcepts::VALUE_NotMatch_Pattern
- , content
- , getPattern());
- }
+ // 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
+ {
+ ThrowXML1(InvalidDatatypeFacetException
+ , XMLExcepts::FACET_Invalid_Tag
+ , key);
}
-
- // 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);
- }
+void StringDatatypeValidator::inheritAdditionalFacet()
+{
+ StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) getBaseValidator();
- if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0) &&
- (strLen < getMinLength()))
+ // inherit whitespace
+ if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) !=0) &&
+ ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) == 0))
{
- XMLString::binToText(strLen, value1, BUF_LEN, 10);
- XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML3(InvalidDatatypeValueException
- , XMLExcepts::VALUE_LT_minLen
- , content
- , value1
- , value2);
+ setWhiteSpace(getBaseValidator()->getWSFacet());
+ setFacetsDefined(DatatypeValidator::FACET_WHITESPACE);
}
+}
- if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
- (strLen != getLength()))
- {
- XMLString::binToText(strLen, value1, BUF_LEN, 10);
- XMLString::binToText(getLength(), value2, BUF_LEN, 10);
+void StringDatatypeValidator::checkAdditionalFacetConstraints() const
+{
- ThrowXML3(InvalidDatatypeValueException
- , XMLExcepts::VALUE_NE_Len
- , content
- , value1
- , value2);
- }
+ StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) getBaseValidator();
+ short thisWSFacet = getWSFacet();
+ short baseWSFacet = pBaseValidator->getWSFacet();
+
+ // check 4.3.6.c1 error: whitespace
+ if (((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0) &&
+ ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0 ))
+ {
+ if ((baseWSFacet == DatatypeValidator::COLLAPSE) &&
+ ((thisWSFacet == DatatypeValidator::PRESERVE) ||
+ (thisWSFacet == DatatypeValidator::REPLACE)))
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_collapse);
+
+ if ((baseWSFacet == DatatypeValidator::REPLACE) &&
+ (thisWSFacet == DatatypeValidator::PRESERVE))
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_replace);
- if ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0 &&
- (getEnumeration() != 0))
- {
- int i=0;
- int enumLength = getEnumeration()->size();
- for ( ; i < enumLength; i++)
+ if (((pBaseValidator->getFixed() & DatatypeValidator::FACET_WHITESPACE) !=0) &&
+ ( thisWSFacet != baseWSFacet))
{
- if (XMLString::compareString(content, getEnumeration()->elementAt(i))==0)
- break;
+ ThrowXML2(InvalidDatatypeFacetException
+ , XMLExcepts::FACET_whitespace_base_fixed
+ , getWSstring(thisWSFacet)
+ , getWSstring(baseWSFacet));
}
-
- if (i == enumLength)
- ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content);
}
+}
+
+void StringDatatypeValidator::checkAdditionalFacet(const XMLCh* const content) const
+{
//
// check WhiteSpace
//
@@ -679,7 +238,14 @@
}
}
+}
+
+void StringDatatypeValidator::checkValueSpace(const XMLCh* const content)
+{}
+int StringDatatypeValidator::getLength(const XMLCh* const content) const
+{
+ return XMLString::stringLen(content);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org