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/05/12 01:23:06 UTC

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

jeffreyr    00/05/11 16:23:05

  Modified:    java/src/org/apache/xerces/validators/datatype Tag:
                        schemawork BooleanValidator.java
                        StringValidator.java
  Log:
  More updates for datatypes
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.6   +99 -36    xml-xerces/java/src/org/apache/xerces/validators/datatype/BooleanValidator.java
  
  Index: BooleanValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/BooleanValidator.java,v
  retrieving revision 1.2.2.5
  retrieving revision 1.2.2.6
  diff -u -r1.2.2.5 -r1.2.2.6
  --- BooleanValidator.java	2000/05/11 02:30:35	1.2.2.5
  +++ BooleanValidator.java	2000/05/11 23:23:04	1.2.2.6
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,65 +59,128 @@
   
   import java.util.Hashtable;
   import java.util.Locale;
  +import java.util.Enumeration;
   import org.apache.xerces.validators.schema.SchemaSymbols;
  +import org.apache.xerces.utils.regex.RegularExpression;
  +import org.apache.xerces.validators.schema.SchemaSymbols;
   /**
    *
    * BooleanValidator validates that content satisfies the W3C XML Datatype for Boolean
    *
    * @author Ted Leung 
  + * @author Jeffrey Rodriguez
    * @version
    */
   
   public class BooleanValidator implements DatatypeValidator {
  -    private Locale fLocale = null;
  -	private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
  -	/**
  +    private Locale fLocale        = null;
  +    private String fBaseValidator = "native";
  +    private String _pattern       = null;
  +    private int    _facetsDefined = 0;
  +    private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
  +    private static  final String _valueSpace[]  = { "false", "true", "0", "1" };
  +
  +    /**
        * validate that a string matches the boolean datatype
  -     *
  -     * validate returns true or false depending on whether the string content is a
  -     * W3C integer type.
  -     * 
        * @param content A string containing the content to be validated
        *
        * @exception throws InvalidDatatypeException if the content is
  -     *  is not a W3C integer type
  +     * is not valid.
        */
  +
  +    public void validate(String content, boolean derivedByList) throws InvalidDatatypeValueException {
  +        if ( _facetsDefined == 0 )// No Facets to validate against
  +            return;
  +
  +        if ( derivedByList == true ) {
  +            ;// What does it mean?
  +        } else {
  +            checkContent( content );
  +        }
  +    }
  +
   
  -	public void validate(String content, boolean list) throws InvalidDatatypeValueException {
  -        if (!content.equals("true") && !content.equals("false"))
  -            throw new InvalidDatatypeValueException(
  -				getErrorString(DatatypeMessageProvider.NotBoolean,
  -							   DatatypeMessageProvider.MSG_NONE,
  -							   new Object[] { content }));
  -	}
  -	
  -	public void validate(int contentIndex) throws InvalidDatatypeValueException {
  -	}
  -	
  -	public void setFacets(Hashtable facets) throws UnknownFacetException, IllegalFacetException, IllegalFacetValueException, ConstrainException {
  -	    throw new IllegalFacetException(); // boolean supports no facets
  -	}
  -	
  -	
  -	public void setBasetype(String base) {
  -	}
  -	
       /**
  +     * Sets the allowable constraining facets
  +     * for the datatype.
  +     * 
  +     * boolean has the following constraining facets:
  +     * pattern
  +     * 
  +     * @param facets Hashtable containing constraining
  +     *               information passed from the
  +     *               DatatypeValidatorRegistry.
  +     * @exception UnknownFacetException
  +     * @exception IllegalFacetException
  +     * @exception IllegalFacetValueException
  +     * @exception ConstrainException
  +     */
  +    public void setFacets(Hashtable facets) throws UnknownFacetException,
  +    IllegalFacetException, IllegalFacetValueException, ConstrainException {
  +
  +        for (Enumeration e = facets.keys(); e.hasMoreElements();) {
  +            String key = (String) e.nextElement();
  +
  +            if (key.equals(SchemaSymbols.ELT_PATTERN)) {
  +                _facetsDefined += DatatypeValidator.FACET_PATTERN;
  +                _pattern = (String)facets.get(key);
  +            } else {
  +                throw new IllegalFacetException();
  +            }
  +        }
  +    }
  +
  +
  +    /**
  +     * Sets the base datatype name.
  +     * 
  +     * @param base
  +     */
  +    public void setBasetype(String base) {
  +        fBaseValidator = base;
  +    }
  +
  +    /**
        * set the locate to be used for error messages
        */
       public void setLocale(Locale locale) {
           fLocale = locale;
       }
   
  -    private String getErrorString(int major, int minor, Object args[]) {
  -         try {
  -             return fMessageProvider.createMessage(fLocale, major, minor, args);
  -         } catch (Exception e) {
  -             return "Illegal Errorcode "+minor;
  -         }
  -    }
       public int compare( DatatypeValidator o1, DatatypeValidator o2){
  -        return 0;
  +      return 0;
       }
   
  +    private String getErrorString(int major, int minor, Object args[]) {
  +        try {
  +            return fMessageProvider.createMessage(fLocale, major, minor, args);
  +        } catch (Exception e) {
  +            return "Illegal Errorcode "+minor;
  +        }
  +    }
  +
  +    /**
  +     * Checks content for validity.
  +     * 
  +     * @param content
  +     * @exception InvalidDatatypeValueException
  +     */
  +    private void checkContent( String content )throws InvalidDatatypeValueException {
  +        boolean  isContentInDomain = false;
  +        for( int i = 0;i<_valueSpace.length;i++ ){
  +            if( content.equals(_valueSpace[i] ) )
  +                isContentInDomain = true;
  +        }
  +        if (isContentInDomain == false)
  +           throw new InvalidDatatypeValueException(
  +                                                  getErrorString(DatatypeMessageProvider.NotBoolean,
  +                                                                 DatatypeMessageProvider.MSG_NONE,
  +                                                                 new Object[] { content}));
  +        if ( (_facetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
  +            RegularExpression regex = new RegularExpression(_pattern, "X" );
  +            if ( regex.matches( content) == false )
  +                throw new InvalidDatatypeValueException("Value'"+content+
  +                                                        "does not match regular expression facet" + _pattern );
  +        }
  +    }
   }
  
  
  
  1.5.2.12  +3 -3      xml-xerces/java/src/org/apache/xerces/validators/datatype/StringValidator.java
  
  Index: StringValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/StringValidator.java,v
  retrieving revision 1.5.2.11
  retrieving revision 1.5.2.12
  diff -u -r1.5.2.11 -r1.5.2.12
  --- StringValidator.java	2000/05/11 17:47:22	1.5.2.11
  +++ StringValidator.java	2000/05/11 23:23:04	1.5.2.12
  @@ -69,11 +69,11 @@
   import org.apache.xerces.utils.regex.RegularExpression;
   
   /**
  - *
    * StringValidator validates that XML content is a W3C string type.
  - *
  + * @author Ted Leung
  + * @author Kito D. Mann, Virtua Communications Corp.
  + * @author Jeffrey Rodriguez
    */
  -
   public class StringValidator implements DatatypeValidator {
       private Locale    fLocale          = null;
       private String    fBaseValidator   = "native";