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/07/29 04:26:00 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype StringDatatypeValidator.java
jeffreyr 00/07/28 19:26:00
Modified: java/src/org/apache/xerces/validators/datatype
StringDatatypeValidator.java
Log:
Finish Enumeration by list for String and also added fBase type check
Revision Changes Path
1.14 +63 -32 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- StringDatatypeValidator.java 2000/06/23 01:26:30 1.13
+++ StringDatatypeValidator.java 2000/07/29 02:26:00 1.14
@@ -73,7 +73,7 @@
* @author Ted Leung
* @author Kito D. Mann, Virtua Communications Corp.
* @author Jeffrey Rodriguez
- * @version $Id: StringDatatypeValidator.java,v 1.13 2000/06/23 01:26:30 jeffreyr Exp $
+ * @version $Id: StringDatatypeValidator.java,v 1.14 2000/07/29 02:26:00 jeffreyr Exp $
*/
public class StringDatatypeValidator extends AbstractDatatypeValidator{
private Locale fLocale = null;
@@ -107,7 +107,7 @@
public StringDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
-
+
setBasetype( base ); // Set base type
fDerivedByList = derivedByList;
@@ -177,7 +177,7 @@
"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." );
}
}
@@ -185,7 +185,7 @@
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength > fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = '" + fMinLength +
- "'must be less than the value of maxLength = '" + fMaxLength + "'.");
+ "'must be less than the value of maxLength = '" + fMaxLength + "'.");
}
}
@@ -278,20 +278,11 @@
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException
{
- if ( fFacetsDefined == 0 )// No Facets to validate
- return null;
-
if ( fDerivedByList == false ) {
- checkContent( content );
+ if (fFacetsDefined != 0 )//Any facets to validate
+ checkContent( content );
} else { //derived by list
- StringTokenizer parsedList = new StringTokenizer( content );
- try {
- while ( parsedList.hasMoreTokens() ) {
- checkContentList( parsedList.nextToken() );
- }
- } catch ( NoSuchElementException e ) {
- e.printStackTrace();
- }
+ checkContentList( content, state );
}
return null;
}
@@ -320,24 +311,24 @@
if ( content.length() > fMaxLength ) {
throw new InvalidDatatypeValueException("Value '"+content+
"' with length '"+content.length()+
- "' exceeds maximum length facet of '"+fMaxLength+"'.");
+ "' exceeds maximum length facet of '"+fMaxLength+"'.");
}
}
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+"'." );
+ "' 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 ( content.length() != fLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length '"+content.length()+
+ "' is not equal to length facet '"+fLength+"'.");
+ }
+ }
@@ -351,7 +342,7 @@
comparisonResult = compare( content, fMaxExclusive );
if ( comparisonResult >= 0 ) {
throw new InvalidDatatypeValueException( "MaxExclusive:Value '"+content+ "' must be " +
- "lexicographically less than" + fMaxExclusive );
+ "lexicographically less than" + fMaxExclusive );
}
@@ -361,7 +352,7 @@
comparisonResult = compare( content, fMaxInclusive );
if ( comparisonResult > 0 )
throw new InvalidDatatypeValueException( "MaxInclusive:Value '"+content+ "' must be " +
- "lexicographically less or equal than" + fMaxInclusive );
+ "lexicographically less or equal than" + fMaxInclusive );
}
if ( isMinExclusiveDefined == true ) {
@@ -372,7 +363,7 @@
if ( comparisonResult <= 0 )
throw new InvalidDatatypeValueException( "MinExclusive:Value '"+content+ "' must be " +
- "lexicographically greater than" + fMinExclusive );
+ "lexicographically greater than" + fMinExclusive );
}
if ( isMinInclusiveDefined == true ) {
int comparisonResult;
@@ -380,7 +371,7 @@
//System.out.println( "inclusive = " + comparisonResult );
if ( comparisonResult < 0 )
throw new InvalidDatatypeValueException( "MinInclusive:Value '"+content+ "' must be " +
- "lexicographically greater or equal than '" + fMinInclusive + "'." );
+ "lexicographically greater or equal than '" + fMinInclusive + "'." );
}
@@ -388,7 +379,7 @@
//RegularExpression regex = new RegularExpression(fPattern );
if ( fRegex == null || fRegex.matches( content) == false )
throw new InvalidDatatypeValueException("Value '"+content+
- "' does not match regular expression facet '" + fPattern + "'." );
+ "' does not match regular expression facet '" + fPattern + "'." );
}
}
@@ -430,9 +421,49 @@
}
// Private methods
- private void checkContentList( String content )throws InvalidDatatypeValueException
+ private void checkContentList( String content, Object state )throws InvalidDatatypeValueException
{
- //Revisit
+ StringTokenizer parsedList = new StringTokenizer( content );
+ try {
+ int numberOfTokens = parsedList.countTokens();
+ while ( parsedList.hasMoreTokens() ) { //Check actual list content
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
+ if ( numberOfTokens > fMaxLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length ='"+ numberOfTokens + "'tokens"+
+ "' exceeds maximum length facet with '"+fMaxLength+"' tokens.");
+ }
+ }
+ if ( (fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
+ if ( numberOfTokens < fMinLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length ='"+ numberOfTokens+ "'tokens" +
+ "' is less than minimum length facet with '"+fMinLength+"' tokens." );
+ }
+ }
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0 ) {
+ if ( numberOfTokens != fLength ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' with length ='"+ numberOfTokens+ "'tokens" +
+ "' is not equal to length facet with '"+fLength+"'. tokens");
+ }
+ }
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
+ if ( fEnumeration.contains( content ) == false )
+ throw new InvalidDatatypeValueException("Value '"+
+ content+"' must be one of "+fEnumeration);
+ }
+
+ if ( this.fBaseValidator != null ) {//validate against parent type if any
+ this.fBaseValidator.validate( content, state );
+ }
+ }
+ } catch ( NoSuchElementException e ) {
+ e.printStackTrace();
+ }
}
private void setBasetype( DatatypeValidator base) {