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/06/19 22:44:27 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype DatatypeValidatorFactory.java DatatypeValidatorFactoryImpl.java RecurringDurationDatatypeValidator.java StringDatatypeValidator.java

jeffreyr    00/06/19 13:44:27

  Modified:    java/src/org/apache/xerces/validators/datatype
                        DatatypeValidatorFactory.java
                        DatatypeValidatorFactoryImpl.java
                        RecurringDurationDatatypeValidator.java
                        StringDatatypeValidator.java
  Log:
  Fixed problems with String Datatype Validator minLenth, maxLength, Length.
  
  Revision  Changes    Path
  1.3       +2 -2      xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactory.java
  
  Index: DatatypeValidatorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatatypeValidatorFactory.java	2000/06/02 05:36:25	1.2
  +++ DatatypeValidatorFactory.java	2000/06/19 20:44:26	1.3
  @@ -62,11 +62,11 @@
   
   
   /**
  - * @version $Id: DatatypeValidatorFactory.java,v 1.2 2000/06/02 05:36:25 jeffreyr Exp $
  + * @version $Id: DatatypeValidatorFactory.java,v 1.3 2000/06/19 20:44:26 jeffreyr Exp $
    * @author  Jeffrey Rodriguez
    */
   public interface DatatypeValidatorFactory {
       public DatatypeValidator createDatatypeValidator(String typeName, 
  -                            DatatypeValidator base, Hashtable facets, boolean list );
  +                    DatatypeValidator base, Hashtable facets, boolean list ) throws  InvalidDatatypeFacetException;
   }
   
  
  
  
  1.6       +12 -5     xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java
  
  Index: DatatypeValidatorFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DatatypeValidatorFactoryImpl.java	2000/06/07 21:41:53	1.5
  +++ DatatypeValidatorFactoryImpl.java	2000/06/19 20:44:26	1.6
  @@ -61,12 +61,13 @@
   import org.apache.xerces.validators.datatype.*;
   import org.apache.xerces.validators.schema.SchemaSymbols;
   import org.apache.xerces.validators.datatype.DatatypeValidatorFactory;
  +import org.apache.xerces.validators.datatype.InvalidDatatypeFacetException;
   
   
   
   
   /**
  - * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.5 2000/06/07 21:41:53 ericye Exp $
  + * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.6 2000/06/19 20:44:26 jeffreyr Exp $
    * @author  Jeffrey Rodriguez
    */
   
  @@ -210,7 +211,7 @@
   
               facets = new Hashtable();
               facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
  -            facets.put(SchemaSymbols.ELT_PERIOD,   "PY24H" );
  +//            facets.put(SchemaSymbols.ELT_PERIOD,   "PY24H" ); Bug -- WORK TODO
               createDatatypeValidator("time", 
                                                    getDatatypeValidator( "recurringDuration"), facets, false );
   
  @@ -252,10 +253,14 @@
       }
   
       public DatatypeValidator createDatatypeValidator(String typeName, 
  -                                                     DatatypeValidator base, Hashtable facets, boolean list ){
  +            DatatypeValidator base, Hashtable facets, boolean list ) throws InvalidDatatypeFacetException {
   
           DatatypeValidator simpleType = null;
   
  +        if (this.fDebug == true) {
  +            System.out.println("type name = " + typeName );
  +        }
  +
           if ( base != null ) {
               try {
                   Class validatorDef = base.getClass();
  @@ -297,7 +302,7 @@
   
   
       private static Object createDatatypeValidator(Constructor validatorConstructor, 
  -                                                  Object[] arguments) {
  +                   Object[] arguments)  throws  InvalidDatatypeFacetException {
           Object validator = null;
           try {
               validator = validatorConstructor.newInstance(arguments);
  @@ -325,7 +330,9 @@
                   System.out.println("!! The original error message is: " + e.getTargetException().getMessage() );
                   e.getTargetException().printStackTrace();
               } else {
  -                return null;
  +                 throw new InvalidDatatypeFacetException( e.getTargetException().getMessage() );
  +                //System.out.println("Exception: " + e.getTargetException
  +                //validator = null;
               }
           }
           return validator;
  
  
  
  1.4       +87 -18    xml-xerces/java/src/org/apache/xerces/validators/datatype/RecurringDurationDatatypeValidator.java
  
  Index: RecurringDurationDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/RecurringDurationDatatypeValidator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RecurringDurationDatatypeValidator.java	2000/06/06 19:54:25	1.3
  +++ RecurringDurationDatatypeValidator.java	2000/06/19 20:44:26	1.4
  @@ -72,11 +72,12 @@
    *
    *
    * @author Ted Leung, George Joseph, Jeffrey Rodriguez,  
  - * @version $Id: RecurringDurationDatatypeValidator.java,v 1.3 2000/06/06 19:54:25 jeffreyr Exp $
  + * @version $Id: RecurringDurationDatatypeValidator.java,v 1.4 2000/06/19 20:44:26 jeffreyr Exp $
    */
   
   public class RecurringDurationDatatypeValidator extends AbstractDatatypeValidator {
   
  +    private static final boolean           fDbug             = false;
       private Locale            fLocale           = null;
       private DatatypeValidator fBaseValidator    = null; // A Native datatype is null
       private String            fPattern          = null;
  @@ -119,12 +120,6 @@
           if ( facets != null  )  {
               if ( derivedByList == false ) { // Restriction
   
  -                //if (fBaseValidator != null)
  -                //  if (!fBaseValidator.ensureFacetsAreConsistent(facets))
  -                //    throw new InvalidDatatypeFacetException(
  -                //                                         getErrorString( DatatypeMessageProvider.FacetsInconsistent,
  -                //                                                       DatatypeMessageProvider.MSG_NONE, null));
  -
                   for (Enumeration e = facets.keys(); e.hasMoreElements();) {
   
                       String key = (String) e.nextElement();
  @@ -140,6 +135,8 @@
                           String value = null;
                           try {
                               value         = ((String)facets.get(key));
  +
  +
                               fMaxInclusive = normalizeDuration( value.toCharArray(), 0) ;
                           } catch ( InvalidDatatypeValueException nfe ){
                               throw new InvalidDatatypeFacetException( getErrorString(
  @@ -185,8 +182,37 @@
                           }
                       } else if (key.equals(SchemaSymbols.ELT_PERIOD  )) {
                           fFacetsDefined += DatatypeValidator.FACET_PERIOD;
  +                        String value = null;
  +                        try {
  +                           value         = ((String)facets.get(key));
  +                           fPeriod   = normalizeDuration( value.toCharArray(), 0 ); 
  +                           if( this.fDbug == true ){
  +                               System.out.println( "value = " + value );
  +                               System.out.println("fPeriod = " + fPeriod );
  +                           }
  +                       } catch ( InvalidDatatypeValueException nfe ) {
  +                           throw new InvalidDatatypeFacetException( getErrorString(
  +                                     DatatypeMessageProvider.IllegalFacetValue,
  +                                     DatatypeMessageProvider.MSG_NONE,
  +                                     new Object [] { value, key}));
  +                       }
                       } else if (key.equals(SchemaSymbols.ELT_DURATION )) {
                           fFacetsDefined += DatatypeValidator.FACET_DURATION;
  +                        String value = null;
  +                        try {
  +                           value         = ((String)facets.get(key));
  +                           fDuration     = normalizeDuration( value.toCharArray(), 0 ); 
  +                           if( this.fDbug == true ){
  +                               System.out.println("fDuration = " + fDuration );
  +                           }
  +                       } catch ( InvalidDatatypeValueException nfe ) {
  +                           throw new InvalidDatatypeFacetException( getErrorString(
  +                                     DatatypeMessageProvider.IllegalFacetValue,
  +                                     DatatypeMessageProvider.MSG_NONE,
  +                                     new Object [] { value, key}));
  +                       }
  +
  +
                       } else {
                           throw new InvalidDatatypeFacetException( getErrorString(  DatatypeMessageProvider.MSG_FORMAT_FAILURE,
                                                                                     DatatypeMessageProvider.MSG_NONE,
  @@ -213,7 +239,6 @@
                                                              "It is an error for both minInclusive and minExclusive to be specified for the same datatype." ); 
                   }
   
  -
                   if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) {
                       Vector v = (Vector) facets.get(SchemaSymbols.ELT_ENUMERATION);    
                       if (v != null) {
  @@ -227,6 +252,13 @@
                                                normalizeDuration( value.toCharArray(), 0 );
                                   boundsCheck( fEnumrecurringduration[i] ); // Check against max,min Inclusive, Exclusives
                               }
  +                           if( this.fDbug == true ){
  +                               System.out.println( "The enumeration vectory is " + value );
  +                               for( int enumCounter = 0;
  +                                  enumCounter < this.fEnumrecurringduration.length; enumCounter++ ) {
  +                                   System.out.println( "fEnumrecurringduration[" + enumCounter + "]" );
  +                               }
  +                           }
                           } catch (InvalidDatatypeValueException idve) {
                               throw new InvalidDatatypeFacetException(
                                   getErrorString(DatatypeMessageProvider.InvalidEnumValue,
  @@ -265,15 +297,16 @@
                                                               "does not match regular expression facet" + fPattern );
               }
   
  -            normalizedValue = normalizeDuration(content.toCharArray(), 0 ); 
  -            try {
  -            boundsCheck( normalizedValue );
  -            } catch( InvalidDatatypeFacetException ex ){
  -                throw new InvalidDatatypeValueException( "Boundary error:" );
  -            }
  +            Calendar cal = normalizeInstant(content.toCharArray(), 0, content.length() ); 
  +            //System.out.println( "cal = " + cal.toString() );
  +            //try {
  +            //boundsCheck( normalizedValue );
  +           // } catch( InvalidDatatypeFacetException ex ){
  +             //   throw new InvalidDatatypeValueException( "Boundary error:" );
  +            //}
   
  -            if ( fEnumrecurringduration != null )
  -                enumCheck( normalizedValue );
  +            //if ( fEnumrecurringduration != null )
  +              //  enumCheck( normalizedValue );
   
           } else { //derived by list 
           }
  @@ -337,6 +370,16 @@
           GregorianCalendar cend   = null;
   
           //Start phase 1: capture start and/or end instant.
  +
  +        if( fDbug == true ) {
  +             System.out.println( "normalizedDuration" );
  +             for( int p = 0; p < value.length; p++ ){
  +                 System.out.print( value[p] );
  +             }
  +             System.out.println("");
  +        }
  +
  +
           try
           {
               if (value[index]=='-')
  @@ -348,6 +391,7 @@
   
               if (ix > -1 && ix < endindex)
               {
  +                //System.out.println( "Inside ix section " );
                   if (value[ix+1]=='-')
                   {
                       p2negative=true;
  @@ -381,9 +425,16 @@
               //Only one term specified.
               else
               {
  +                //System.out.println(" inside only one term section" );
                   index=(p1negative?(start+1):(start));
               }
               //If both terms are instants, return the millisecond difference
  +
  +            if( fDbug == true ) {
  +                 System.out.println( "cstart = " +  cstart );
  +                 System.out.println( "cend   = " +  cend   );
  +            }
  +
               if (cstart != null && cend != null)
               {
                   return((cend.getTime().getTime() - cstart.getTime().getTime()));
  @@ -411,6 +462,9 @@
               lindex=index+1;
               for (i=index+1;i<=pendindex;i++)
               {
  +                if( fDbug == true ){
  +                    System.out.println( "Second Phaser value = " + value );
  +                }
                   //Accumulate digits.
                   if (Character.isDigit(value[i]) || value[i]=='.')
                   {
  @@ -425,10 +479,16 @@
                       continue;
                   }
                   //If you get a separator, it must be appropriate for the section.
  +
  +                if( fDbug ){
  +                System.out.println("tseps = >" + tseps +"<" );
  +                }
                   sepindex = indexOf((intime?tseps:dseps), sepindex, value[i]);
  -                if (sepindex == -1)
  +
  +                if (sepindex == -1 && intime == true )
                       throw new ParseException("Illegal or misplaced separator.", i);
                   sepindex++;
  +
                   //Fractional digits are allowed only for seconds.
                   if (fixed && value[i]!='S')
                       throw new ParseException("Fractional digits allowed only for 'seconds'.", i);
  @@ -437,30 +497,39 @@
                   switch (value[i])
                   {
                   case('Y'):
  -                    {
  +                    {   if(fDbug )
  +                           System.out.println("Inside the Y" );
                           if (intime)throw new ParseException("Year must be specified before 'T' separator.", i);
                           buckets[Calendar.YEAR]= parseInt(value, lindex, i-lindex);
                           break;
                       }
                   case('D'):
                       {
  +                        if( fDbug )
  +                           System.out.println("Inside the D" );
                           if (intime)throw new ParseException("Days must be specified before 'T' separator.", i);
                           buckets[Calendar.DAY_OF_MONTH]= parseInt(value, lindex, i-lindex);
                           break;
                       }
                   case('H'):
                       {
  +                        if( fDbug ) 
  +                           System.out.println( "Inside the H" );
                           if (!intime)throw new ParseException("Hours must be specified after 'T' separator.", i);
                           buckets[Calendar.HOUR_OF_DAY]= parseInt(value, lindex, i-lindex);
                           break;
                       }
                   case('M'):
                       {
  +                        if( fDbug )
  +                           System.out.println( "Inside the M" );
                           buckets[(intime?Calendar.MINUTE:Calendar.MONTH)]= parseInt(value, lindex, i-lindex);
                           break;
                       }
                   case('S'):
                       {
  +                        if( fDbug )
  +                           System.out.println( "Inside S" );
                           if (!intime)throw new ParseException("Seconds must be specified after 'T' separator.", i);
                           if (!fixed)buckets[Calendar.SECOND]= parseInt(value, lindex, i-lindex);
                           else
  
  
  
  1.5       +24 -7     xml-xerces/java/src/org/apache/xerces/validators/datatype/StringDatatypeValidator.java
  
  Index: StringDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/StringDatatypeValidator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StringDatatypeValidator.java	2000/06/07 21:41:53	1.4
  +++ StringDatatypeValidator.java	2000/06/19 20:44:26	1.5
  @@ -73,7 +73,7 @@
    * @author Ted Leung
    * @author Kito D. Mann, Virtua Communications Corp.
    * @author Jeffrey Rodriguez
  - * @version $Id: StringDatatypeValidator.java,v 1.4 2000/06/07 21:41:53 ericye Exp $
  + * @version $Id: StringDatatypeValidator.java,v 1.5 2000/06/19 20:44:26 jeffreyr Exp $
    */
   public class StringDatatypeValidator extends AbstractDatatypeValidator{
       private Locale     fLocale          = null;
  @@ -100,7 +100,6 @@
   
   
       public  StringDatatypeValidator () throws InvalidDatatypeFacetException{
  -        //System.out.println( "Inside constructor" );
           this( null, null, false ); // Native, No Facets defined, Restriction
   
       }
  @@ -112,6 +111,7 @@
   
           // Set Facets if any defined
   
  +        //fFacetsDefined = 0;
           if ( facets != null  ){
               if ( derivedByList == false) {
                   for (Enumeration e = facets.keys(); e.hasMoreElements();) {
  @@ -173,15 +173,15 @@
                                                                  "It is an error for both length and maxLength to be members of facets." );  
                       } else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
                           throw new InvalidDatatypeFacetException(
  -                                                               "It is an error for both length and minLength to be members of facets." );
  +                                "It is an error for both length and minLength to be members of facets." );
                       }
                   }
   
                   if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
                                              DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
                       if ( fMinLength > fMaxLength ) {
  -                        throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
  -                                                                 "must be less than the value of maxLength = " + fMaxLength );
  +                        throw new InvalidDatatypeFacetException( "Value of minLength = '" + fMinLength +
  +                            "'must be less than the value of maxLength = '" + fMaxLength + "'.");
                       }
                   }
   
  @@ -317,12 +317,28 @@
               if ( content.length() > fMaxLength ) {
                   throw new InvalidDatatypeValueException("Value '"+content+
                                                           "' with length '"+content.length()+
  -                                                        "' exceeds maximum length of "+fMaxLength+".");
  +                                          "' exceeds maximum length facet of '"+fMaxLength+"'.");
               }
           }
  -        if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
  +        if ( (fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
  +            if ( content.length() < fMinLength ) {
  +                throw new InvalidDatatypeValueException("Value '"+content+
  +                                                    "' with length '"+content.length()+
  +                                    "' is less than minimum length facet of '"+fMinLength+"'." );
  +            }
  +        }
   
  +        if ( (fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0 ) {
  +                    if ( content.length() != fLength ) {
  +                        throw new InvalidDatatypeValueException("Value '"+content+
  +                                                         "' with length '"+content.length()+
  +                                               "' is not equal to length facet '"+fLength+"'.");
  +                    }
  +                }
  +
   
  +
  +        if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
               if ( fEnumeration.contains( content ) == false )
                   throw new InvalidDatatypeValueException("Value '"+content+"' must be one of "+fEnumeration);
           }
  @@ -359,6 +375,7 @@
                   throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
                                                            "lexicographically greater or equal than" + fMinInclusive );
           }
  +
   
           if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
               RegularExpression regex = new RegularExpression(fPattern, "X" );