I'd really like to get the "obsolete" syntax back, so don't kick yourself
quite yet.  For some background you might want to read

http://lists.w3.org/Archives/Public/www-xml-schema-comments/1999OctDec/0022.
html
http://lists.w3.org/Archives/Public/www-xml-schema-comments/1999OctDec/0023.
html

That tried to address internationalized enumerations and how to support all
those existing schemas that use "0" and "1" instead of "true" and "false"






-----Original Message-----
From: George T. Joseph [mailto:[EMAIL PROTECTED]
Sent: Friday, January 07, 2000 1:33 AM
To: xerces-dev
Subject: New functionality for StringValidator.java


I added functionality to
org/apache/xerces/validators/datatype/StringValidator.java to let Schemas
validate enumeration/literals and
maxLength in datatypes based on 'string'.

Example:

<datatype name='newtype'>
<basetype name='string'>
<enumeration>
<literal>AAA</literal>
<literal>BBB</literal>
</enumeration>
</datatype>

I realize that this is already obsolete syntax based on the 12/17 Schema
draft but I needed it and thought others may.  The diff is
below.

George
************************************************************


*** StringValidatorOrig.java    Wed Jan 05 15:12:26 2000
--- StringValidator.java        Fri Jan 07 00:30:44 2000
***************
*** 58,63 ****
--- 58,65 ----
  package org.apache.xerces.validators.datatype;

  import java.util.Hashtable;
+ import java.util.Vector;
+ import java.util.Enumeration;
  import java.util.Locale;

  /**
***************
*** 71,77 ****
  public class StringValidator implements InternalDatatypeValidator {

        Locale fLocale = null;
!
        /**
       * validate that a string is a W3C string type
       *
--- 73,82 ----
  public class StringValidator implements InternalDatatypeValidator {

        Locale fLocale = null;
!       Hashtable facetData = null;
!       StringValidator fBaseValidator = null;
!       int fMaxLength = 0;
!       boolean fIsMaxLength = false;
        /**
       * validate that a string is a W3C string type
       *
***************
*** 84,103 ****
       *  not a W3C string type
       */

!       public void validate(String content) throws
InvalidDatatypeValueException {
!         // just say yes
        }

        public void validate(int contentIndex) throws
InvalidDatatypeValueException {
        }

        public void setFacets(Hashtable facets) throws
UnknownFacetException, IllegalFacetException, IllegalFacetValueException {
        }

        public void setFacets(int facets[]) throws UnknownFacetException,
IllegalFacetException, IllegalFacetValueException {
        }

        public void setBasetype(DatatypeValidator base) {
        }

      /**
--- 89,151 ----
       *  not a W3C string type
       */

!       public void validate(String content) throws
InvalidDatatypeValueException
!       {
!
!               if (facetData == null)return;
!
!               Enumeration eee = facetData.keys();
!               while(eee.hasMoreElements())
!               {
!                       String key = (String)eee.nextElement();
!                       if (key.equals(DatatypeValidator.ENUMERATION))
!                       {
!                               Vector value = (Vector)facetData.get(key);
!                               String vvv = value.toString();
!                               if (!value.contains(content)) throw new
InvalidDatatypeValueException("Value '"+content+"' must be one of "+vvv);
!                       }
!                       else if (key.equals(DatatypeValidator.MAXLENGTH))
!                       {
!                               if (content.length() > fMaxLength &&
fIsMaxLength)
!                                       throw new
InvalidDatatypeValueException("Value '"+content+"' with length
'"+content.length()+"' exceeds maximum length of
"+fMaxLength+".");
!                       }
!               }
        }

        public void validate(int contentIndex) throws
InvalidDatatypeValueException {
        }

        public void setFacets(Hashtable facets) throws
UnknownFacetException, IllegalFacetException, IllegalFacetValueException {
+               facetData=facets;
+
+               Enumeration eee = facetData.keys();
+               while(eee.hasMoreElements())
+               {
+                       String key = (String)eee.nextElement();
+                       if (key.equals(DatatypeValidator.MAXLENGTH))
+                       {
+                               int vvv;
+                               String value = (String)facetData.get(key);
+                               try
+                               {
+                                       vvv = Integer.parseInt(value);
+                               }
+                               catch(NumberFormatException nfe)
+                               {
+                                       throw new
IllegalFacetValueException("maxLength value '"+value+"' is invalid.");
+                               }
+                               fMaxLength = vvv;
+                               fIsMaxLength = true;
+                       }
+               }
        }

        public void setFacets(int facets[]) throws UnknownFacetException,
IllegalFacetException, IllegalFacetValueException {
        }

        public void setBasetype(DatatypeValidator base) {
+           fBaseValidator = (StringValidator) base;
+
        }

      /**

Reply via email to