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/08/10 05:46:07 UTC

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

jeffreyr    00/08/09 20:46:06

  Modified:    java/src/org/apache/xerces/validators/datatype
                        IDDatatypeValidator.java
                        IDREFDatatypeValidator.java
  Log:
  WIP- Migrating ATTValidators from XMLValidator to Schema to unify all validator.
  
  Revision  Changes    Path
  1.6       +1 -2      xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java
  
  Index: IDDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- IDDatatypeValidator.java	2000/08/10 02:58:19	1.5
  +++ IDDatatypeValidator.java	2000/08/10 03:46:05	1.6
  @@ -59,7 +59,6 @@
   
   import java.util.Hashtable;
   import java.util.Locale;
  -import java.util.Hashtable;
   import org.apache.xerces.utils.XMLCharacterProperties;
   import org.apache.xerces.utils.XMLMessages;
   
  @@ -68,7 +67,7 @@
    * These validators can be supplied by the application writer and may be useful as
    * standalone code as well as plugins to the validator architecture.
    * @author Jeffrey Rodriguez
  - * @version $Id: IDDatatypeValidator.java,v 1.5 2000/08/10 02:58:19 jeffreyr Exp $
  + * @version $Id: IDDatatypeValidator.java,v 1.6 2000/08/10 03:46:05 jeffreyr Exp $
    */
   public class IDDatatypeValidator extends AbstractDatatypeValidator {
       private DatatypeValidator         fBaseValidator = null;
  
  
  
  1.5       +64 -3     xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java
  
  Index: IDREFDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IDREFDatatypeValidator.java	2000/06/23 01:26:29	1.4
  +++ IDREFDatatypeValidator.java	2000/08/10 03:46:05	1.5
  @@ -59,20 +59,33 @@
   
   import java.util.Hashtable;
   import java.util.Locale;
  +import org.apache.xerces.utils.XMLCharacterProperties;
  +import org.apache.xerces.utils.XMLMessages;
   
  +
  +
   /**
    * IDREFValidator defines the interface that data type validators must obey.
    * These validators can be supplied by the application writer and may be useful as
    * standalone code as well as plugins to the validator architecture.
    * 
    * @author Jeffrey Rodriguez-
  - * @version $Id: IDREFDatatypeValidator.java,v 1.4 2000/06/23 01:26:29 jeffreyr Exp $
  + * @version $Id: IDREFDatatypeValidator.java,v 1.5 2000/08/10 03:46:05 jeffreyr Exp $
    */
   public class IDREFDatatypeValidator extends AbstractDatatypeValidator {
  -    private DatatypeValidator fBaseValidator  = null;
  -    private boolean           fDerivedByList  = false;
  +    private DatatypeValidator fBaseValidator    = null;
  +    private boolean           fDerivedByList    = false;
  +    private Hashtable              fTableOfId   = null; //This is pass to us through the state object
  +    private Hashtable              fTableIDRefs = null;
  +    private Object                   fNullValue = null;
  +    private Locale            fLocale           = null;
  +    private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
  +
  +
  +
   
   
  +
       public IDREFDatatypeValidator () throws InvalidDatatypeFacetException {
           this( null, null, false ); // Native, No Facets defined, Restriction
       }
  @@ -101,6 +114,14 @@
        * @see         org.apache.xerces.validators.datatype.InvalidDatatypeValueException
        */
       public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
  +            //Pass content as a String
  +
  +        this.fTableOfId = (Hashtable) state;
  +
  +        if (!XMLCharacterProperties.validName(content)) {//Check if is valid key
  +            throw new InvalidDatatypeValueException( "ID is not valid" );//Need Message
  +        }
  +        addIdRef( content, state);
           return null;
       }
   
  @@ -137,6 +158,46 @@
        */
       private void setBasetype(DatatypeValidator base){
           fBaseValidator = base;
  +    }
  +
  +    /** addId. */
  +    private void addIdRef(String content, Object state) {
  +
  +        if ( state == null ) {
  +            if(content != null &&  this.fTableOfId.containsKey( content ) ){
  +                return;
  +            }
  +            if( this.fTableIDRefs == null ){
  +                this.fTableIDRefs = new Hashtable();
  +            } else if( fTableIDRefs.containsKey( content ) ){
  +                return;
  +            }
  +
  +            if ( this.fNullValue == null ){
  +                fNullValue = new Object();
  +            }
  +            this.fTableIDRefs.put( content, fNullValue ); 
  +        } else {
  +            ;
  +        }
  +    } // addId(int):boolean
  +
  +
  +
  +     /**
  +     * 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;
  +        }
       }