You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by je...@locus.apache.org on 2000/12/06 00:36:32 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype ListDatatypeValidator.java

jeffreyr    00/12/05 15:36:32

  Modified:    java/src/org/apache/xerces/validators/datatype
                        ListDatatypeValidator.java
  Log:
  Added list bug fix patch submitted by Elena Litani
  
  Revision  Changes    Path
  1.3       +18 -6     xml-xerces/java/src/org/apache/xerces/validators/datatype/ListDatatypeValidator.java
  
  Index: ListDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/ListDatatypeValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ListDatatypeValidator.java	2000/10/17 21:40:11	1.2
  +++ ListDatatypeValidator.java	2000/12/05 23:36:31	1.3
  @@ -72,7 +72,7 @@
    * StringValidator validates that XML content is a W3C string type.
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version $Id: ListDatatypeValidator.java,v 1.2 2000/10/17 21:40:11 jeffreyr Exp $
  + * @version $Id: ListDatatypeValidator.java,v 1.3 2000/12/05 23:36:31 jeffreyr Exp $
    */
   public class ListDatatypeValidator extends AbstractDatatypeValidator{
       private Locale     fLocale          = null;
  @@ -237,6 +237,7 @@
       private void checkContent( String content,  Object state )throws InvalidDatatypeValueException
       {
           StringTokenizer parsedList = new StringTokenizer( content );
  +        boolean enumOn = false; //if enumeration facet present
           try {
               int numberOfTokens =  parsedList.countTokens();
               if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
  @@ -265,15 +266,26 @@
               if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
                   // Enumerations are defined in the value space so the contains method
                   // of vector doesn't really do the right thing, we really should check using compare
  -                if ( fEnumeration.contains( content ) == false )
  -                    throw new InvalidDatatypeValueException("Value '"+
  -                                                            content+"' must be one of "+fEnumeration);
  +                enumOn = true;
               }
               
  -            if (this.fDerivedByList) {
  +            if (this.fDerivedByList || enumOn) {
  +                if( numberOfTokens == 0 ){
  +                       InvalidDatatypeValueException error = new InvalidDatatypeValueException( content );
  +                       throw error;
  +                   }
  +
  +                String token = null;
                   while ( parsedList.hasMoreTokens() ) {       //Check each token in list against base type
  +                    token = parsedList.nextToken();
  +                    if (enumOn) {
  +                        if ( fEnumeration.contains( token ) == false )
  +                            throw new InvalidDatatypeValueException("Value '"+
  +                                                                    token +"' must be one of "+fEnumeration);
  +                    }
  +                    
                       if ( this.fBaseValidator != null ) {//validate against parent type if any
  -                        this.fBaseValidator.validate( parsedList.nextToken(), state );
  +                        this.fBaseValidator.validate( token, state );
                       }
                   }
               }