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/21 23:59:18 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype BooleanDatatypeValidator.java DecimalDatatypeValidator.java DoubleDatatypeValidator.java FloatDatatypeValidator.java URIReferenceDatatypeValidator.java
jeffreyr 00/06/21 14:59:16
Modified: java/src/org/apache/xerces/validators/datatype
BooleanDatatypeValidator.java
DecimalDatatypeValidator.java
DoubleDatatypeValidator.java
FloatDatatypeValidator.java
URIReferenceDatatypeValidator.java
Log:
Performace- moved instantiation of RegularExpression to the facet so we don't create a RegularExpression object every time that we validate if pattern facet is present
Revision Changes Path
1.3 +8 -4 xml-xerces/java/src/org/apache/xerces/validators/datatype/BooleanDatatypeValidator.java
Index: BooleanDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/BooleanDatatypeValidator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BooleanDatatypeValidator.java 2000/06/06 19:54:24 1.2
+++ BooleanDatatypeValidator.java 2000/06/21 21:59:08 1.3
@@ -70,7 +70,7 @@
*
* @author Ted Leung
* @author Jeffrey Rodriguez
- * @version $Id: BooleanDatatypeValidator.java,v 1.2 2000/06/06 19:54:24 jeffreyr Exp $
+ * @version $Id: BooleanDatatypeValidator.java,v 1.3 2000/06/21 21:59:08 jeffreyr Exp $
*/
public class BooleanDatatypeValidator extends AbstractDatatypeValidator {
@@ -81,6 +81,7 @@
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
private static final String fValueSpace[] = { "false", "true", "0", "1"};
private boolean fDerivedByList = false;
+ private RegularExpression fRegex = null;
public BooleanDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
@@ -99,8 +100,12 @@
if (key.equals(SchemaSymbols.ELT_PATTERN)) {
fFacetsDefined += DatatypeValidator.FACET_PATTERN;
fPattern = (String)facets.get(key);
+ if( fPattern != null )
+ fRegex = new RegularExpression(fPattern, "X" );
} else {
- throw new InvalidDatatypeFacetException();
+ throw new
+ InvalidDatatypeFacetException(
+ "Only constraining facet in boolean datatype is PATTERN" );
}
}
} else { // By List
@@ -199,8 +204,7 @@
DatatypeMessageProvider.MSG_NONE,
new Object[] { content}));
if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
- RegularExpression regex = new RegularExpression(fPattern, "X" );
- if ( regex.matches( content) == false )
+ if ( fRegex == null || fRegex.matches( content) == false )
throw new InvalidDatatypeValueException("Value'"+content+
"does not match regular expression facet" + fPattern );
}
1.6 +26 -6 xml-xerces/java/src/org/apache/xerces/validators/datatype/DecimalDatatypeValidator.java
Index: DecimalDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DecimalDatatypeValidator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DecimalDatatypeValidator.java 2000/06/20 21:29:02 1.5
+++ DecimalDatatypeValidator.java 2000/06/21 21:59:09 1.6
@@ -63,7 +63,9 @@
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
+import java.io.IOException;
import org.apache.xerces.validators.schema.SchemaSymbols;
+import org.apache.xerces.utils.regex.RegularExpression;
/**
*
@@ -71,7 +73,7 @@
*
* @author Ted Leung
* @author Jeffrey Rodriguez
- * @version $Id: DecimalDatatypeValidator.java,v 1.5 2000/06/20 21:29:02 jeffreyr Exp $
+ * @version $Id: DecimalDatatypeValidator.java,v 1.6 2000/06/21 21:59:09 jeffreyr Exp $
*/
public class DecimalDatatypeValidator extends AbstractDatatypeValidator {
@@ -87,16 +89,15 @@
private int fFacetsDefined = 0;
private int fScale = 0;
private int fPrecision = 0;
-
private boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
-
- private boolean isScaleDefined = false;
- private boolean isPrecisionDefined = false;
+ private boolean isScaleDefined = false;
+ private boolean isPrecisionDefined = false;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
+ private RegularExpression fRegex = null;
@@ -120,6 +121,8 @@
value = ((String) facets.get(key ));
fFacetsDefined += DatatypeValidator.FACET_PATTERN;
fPattern = value;
+ if( fPattern != null )
+ fRegex = new RegularExpression(fPattern, "X" );
} else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
enumeration = (Vector)facets.get(key);
@@ -219,15 +222,32 @@
public Object validate(String content, Object state) throws InvalidDatatypeValueException {
if ( fDerivationByList == false ) { //derived by restriction
+
+ if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
+ if ( fRegex == null || fRegex.matches( content) == false )
+ throw new InvalidDatatypeValueException("Value'"+content+
+ "does not match regular expression facet" + fPattern );
+ }
+
BigDecimal d = null; // Is content a Decimal
try {
d = new BigDecimal(content);
- } catch (Exception nfe) {
+ }
+ catch (Exception nfe) {
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotDecimal,
DatatypeMessageProvider.MSG_NONE,
new Object[] { "'" + content +"'"}));
}
+ //}
+ //catch (IOException ex ) {
+ // throw new InvalidDatatypeValueException(
+ // getErrorString(DatatypeMessageProvider.NotDecimal,
+ // DatatypeMessageProvider.MSG_NONE,
+ // new Object[] { "'" + content +"'"}));
+ //}
+
+
if( isScaleDefined == true ) {
if (d.scale() > fScale)
throw new InvalidDatatypeValueException(
1.4 +118 -106 xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java
Index: DoubleDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DoubleDatatypeValidator.java 2000/06/06 19:54:25 1.3
+++ DoubleDatatypeValidator.java 2000/06/21 21:59:11 1.4
@@ -62,12 +62,13 @@
import java.util.Locale;
import java.util.Vector;
import org.apache.xerces.validators.schema.SchemaSymbols;
+import org.apache.xerces.utils.regex.RegularExpression;
/**
*
* @author Ted Leung
* @author Jeffrey Rodriguez
- * @version $Id: DoubleDatatypeValidator.java,v 1.3 2000/06/06 19:54:25 jeffreyr Exp $
+ * @version $Id: DoubleDatatypeValidator.java,v 1.4 2000/06/21 21:59:11 jeffreyr Exp $
*/
public class DoubleDatatypeValidator extends AbstractDatatypeValidator {
@@ -86,123 +87,127 @@
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
+ private RegularExpression fRegex = null;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
public DoubleDatatypeValidator () throws InvalidDatatypeFacetException {
- this( null, null, false ); // Native, No Facets defined, Restriction
+ this( null, null, false ); // Native, No Facets defined, Restriction
}
public DoubleDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
- if( base != null )
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
+ if ( base != null )
setBasetype( base ); // Set base type
- if( facets != null ) { // Set Facet
- if( derivedByList == false ) {
- for (Enumeration e = facets.keys(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- if (key.equals(SchemaSymbols.ELT_PATTERN)) {
- fFacetsDefined += DatatypeValidator.FACET_PATTERN;
- fPattern = (String)facets.get(key);
- } else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
- fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
- continue; //Treat the enumaration after this for loop
- } else if (key.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
- fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
- String value = null;
- try {
- value = ((String)facets.get(key));
- fMaxInclusive = Double.valueOf(value).doubleValue();
- } catch (NumberFormatException ex ) {
- throw new InvalidDatatypeFacetException( getErrorString(
- DatatypeMessageProvider.IllegalFacetValue,
- DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
- }
- } else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
- fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
- String value = null;
- try {
- value = ((String)facets.get(key));
- fMaxExclusive = Double.valueOf(value).doubleValue();
- } catch (NumberFormatException ex ) {
- throw new InvalidDatatypeFacetException( getErrorString(
- DatatypeMessageProvider.IllegalFacetValue,
- DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
- }
- } else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
- fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
- String value = null;
- try {
- value = ((String)facets.get(key));
- fMinInclusive = Double.valueOf(value).doubleValue();
- } catch (NumberFormatException ex ) {
- throw new InvalidDatatypeFacetException( getErrorString(
- DatatypeMessageProvider.IllegalFacetValue,
- DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
- }
- } else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
- fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
- String value = null;
- try {
- value = ((String)facets.get(key));
- fMinExclusive = Double.valueOf(value).doubleValue();
- } catch (NumberFormatException ex ) {
- throw new InvalidDatatypeFacetException( getErrorString(
- DatatypeMessageProvider.IllegalFacetValue,
- DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
- }
- } else {
+ if ( facets != null ) { // Set Facet
+ if ( derivedByList == false ) {
+ for (Enumeration e = facets.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ if (key.equals(SchemaSymbols.ELT_PATTERN)) {
+ fFacetsDefined += DatatypeValidator.FACET_PATTERN;
+ fPattern = (String)facets.get(key);
+ if ( fPattern != null )
+ fRegex = new RegularExpression(fPattern, "X" );
+
+ } else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
+ fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
+ continue; //Treat the enumaration after this for loop
+ } else if (key.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
+ String value = null;
+ try {
+ value = ((String)facets.get(key));
+ fMaxInclusive = Double.valueOf(value).doubleValue();
+ } catch (NumberFormatException ex ) {
+ throw new InvalidDatatypeFacetException( getErrorString(
+ DatatypeMessageProvider.IllegalFacetValue,
+ DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
+ }
+ } else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
+ String value = null;
+ try {
+ value = ((String)facets.get(key));
+ fMaxExclusive = Double.valueOf(value).doubleValue();
+ } catch (NumberFormatException ex ) {
+ throw new InvalidDatatypeFacetException( getErrorString(
+ DatatypeMessageProvider.IllegalFacetValue,
+ DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
+ }
+ } else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
+ String value = null;
+ try {
+ value = ((String)facets.get(key));
+ fMinInclusive = Double.valueOf(value).doubleValue();
+ } catch (NumberFormatException ex ) {
+ throw new InvalidDatatypeFacetException( getErrorString(
+ DatatypeMessageProvider.IllegalFacetValue,
+ DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
+ }
+ } else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
+ fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
+ String value = null;
+ try {
+ value = ((String)facets.get(key));
+ fMinExclusive = Double.valueOf(value).doubleValue();
+ } catch (NumberFormatException ex ) {
+ 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,
- null));
- }
- }
- isMaxExclusiveDefined = ((fFacetsDefined &
- DatatypeValidator.FACET_MAXEXCLUSIVE ) != 0 )?true:false;
- isMaxInclusiveDefined = ((fFacetsDefined &
- DatatypeValidator.FACET_MAXINCLUSIVE ) != 0 )?true:false;
- isMinExclusiveDefined = ((fFacetsDefined &
- DatatypeValidator.FACET_MINEXCLUSIVE ) != 0 )?true:false;
- isMinInclusiveDefined = ((fFacetsDefined &
- DatatypeValidator.FACET_MININCLUSIVE ) != 0 )?true:false;
-
-
- if ( isMaxExclusiveDefined && isMaxInclusiveDefined ) {
- throw new InvalidDatatypeFacetException(
- "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." );
- }
- if ( isMinExclusiveDefined && isMinInclusiveDefined ) {
- throw new InvalidDatatypeFacetException(
- "It is an error for both minInclusive and minExclusive to be specified for the same datatype." );
- }
+ DatatypeMessageProvider.MSG_NONE,
+ null));
+ }
+ }
+ isMaxExclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MAXEXCLUSIVE ) != 0 )?true:false;
+ isMaxInclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MAXINCLUSIVE ) != 0 )?true:false;
+ isMinExclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MINEXCLUSIVE ) != 0 )?true:false;
+ isMinInclusiveDefined = ((fFacetsDefined &
+ DatatypeValidator.FACET_MININCLUSIVE ) != 0 )?true:false;
+
+
+ if ( isMaxExclusiveDefined && isMaxInclusiveDefined ) {
+ throw new InvalidDatatypeFacetException(
+ "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." );
+ }
+ if ( isMinExclusiveDefined && isMinInclusiveDefined ) {
+ throw new InvalidDatatypeFacetException(
+ "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) {
- fEnumDoubles = new double[v.size()];
- for (int i = 0; i < v.size(); i++)
- try {
- fEnumDoubles[i] = Double.valueOf((String) v.elementAt(i)).doubleValue();
- boundsCheck(fEnumDoubles[i]); // Check against max,min Inclusive, Exclusives
- } catch (InvalidDatatypeValueException idve) {
- throw new InvalidDatatypeFacetException(
- getErrorString(DatatypeMessageProvider.InvalidEnumValue,
- DatatypeMessageProvider.MSG_NONE,
- new Object [] { v.elementAt(i)}));
- } catch (NumberFormatException nfe) {
- System.out.println("Internal Error parsing enumerated values for real type");
- }
- }
- }
- } else {
- fDerivationByList = true;
- //WORK TO DO - Add derivation by list Double type
- }
+ if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) {
+ Vector v = (Vector) facets.get(SchemaSymbols.ELT_ENUMERATION);
+ if (v != null) {
+ fEnumDoubles = new double[v.size()];
+ for (int i = 0; i < v.size(); i++)
+ try {
+ fEnumDoubles[i] = Double.valueOf((String) v.elementAt(i)).doubleValue();
+ boundsCheck(fEnumDoubles[i]); // Check against max,min Inclusive, Exclusives
+ } catch (InvalidDatatypeValueException idve) {
+ throw new InvalidDatatypeFacetException(
+ getErrorString(DatatypeMessageProvider.InvalidEnumValue,
+ DatatypeMessageProvider.MSG_NONE,
+ new Object [] { v.elementAt(i)}));
+ } catch (NumberFormatException nfe) {
+ System.out.println("Internal Error parsing enumerated values for real type");
+ }
+ }
+ }
+ } else {
+ fDerivationByList = true;
+ //WORK TO DO - Add derivation by list Double type
+ }
}// End of facet setting
}
@@ -219,6 +224,13 @@
public Object validate(String content, Object state)
throws InvalidDatatypeValueException {
if ( fDerivationByList == false ) { //derived by restriction
+ if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
+ if ( fRegex == null || fRegex.matches( content) == false )
+ throw new InvalidDatatypeValueException("Value'"+content+
+ "does not match regular expression facet" + fPattern );
+ }
+
+
double d = 0.0;
try {
d = Double.valueOf(content).doubleValue();
@@ -299,9 +311,9 @@
public Hashtable getFacets(){
return null;
}
- /**
- * Returns a copy of this object.
- */
+ /**
+ * Returns a copy of this object.
+ */
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
}
1.4 +35 -20 xml-xerces/java/src/org/apache/xerces/validators/datatype/FloatDatatypeValidator.java
Index: FloatDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/FloatDatatypeValidator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FloatDatatypeValidator.java 2000/06/06 19:54:25 1.3
+++ FloatDatatypeValidator.java 2000/06/21 21:59:11 1.4
@@ -62,39 +62,42 @@
import java.util.Locale;
import java.util.Vector;
import org.apache.xerces.validators.schema.SchemaSymbols;
+import org.apache.xerces.utils.regex.RegularExpression;
/**
*
* @author Ted Leung
* @author Jeffrey Rodriguez
- * @version $Id: FloatDatatypeValidator.java,v 1.3 2000/06/06 19:54:25 jeffreyr Exp $
+ * @version $Id: FloatDatatypeValidator.java,v 1.4 2000/06/21 21:59:11 jeffreyr Exp $
*/
public class FloatDatatypeValidator extends AbstractDatatypeValidator {
- private Locale fLocale = null;
+ private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null; // null means a native datatype
- private float[] fEnumFloats = null;
- private String fPattern = null;
- private boolean fDerivationByList = false; // Default is restriction
- private float fMaxInclusive = Float.MAX_VALUE;
- private float fMaxExclusive = Float.MAX_VALUE;
- private float fMinInclusive = Float.MIN_VALUE;
- private float fMinExclusive = Float.MIN_VALUE;
- private int fFacetsDefined = 0;
+ private float[] fEnumFloats = null;
+ private String fPattern = null;
+ private boolean fDerivationByList = false; // Default is restriction
+ private float fMaxInclusive = Float.MAX_VALUE;
+ private float fMaxExclusive = Float.MAX_VALUE;
+ private float fMinInclusive = Float.MIN_VALUE;
+ private float fMinExclusive = Float.MIN_VALUE;
+ private int fFacetsDefined = 0;
private boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
+ private RegularExpression fRegex = null;
+
public FloatDatatypeValidator () throws InvalidDatatypeFacetException{
this( null, null, false ); // Native, No Facets defined, Restriction
}
public FloatDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
if ( base != null )
setBasetype( base ); // Set base type
@@ -108,6 +111,10 @@
if (key.equals(SchemaSymbols.ELT_PATTERN)) {
fFacetsDefined += DatatypeValidator.FACET_PATTERN;
fPattern = (String)facets.get(key);
+ if ( fPattern != null )
+ fRegex = new RegularExpression(fPattern, "X" );
+
+
} else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
continue; //Treat the enumaration after this for loop
@@ -119,8 +126,8 @@
fMaxInclusive = Float.valueOf(value).floatValue();
} catch (NumberFormatException ex ) {
throw new InvalidDatatypeFacetException( getErrorString(
- DatatypeMessageProvider.IllegalFacetValue,
- DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
+ DatatypeMessageProvider.IllegalFacetValue,
+ DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
}
} else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
@@ -157,8 +164,8 @@
}
} else {
throw new InvalidDatatypeFacetException( getErrorString( DatatypeMessageProvider.MSG_FORMAT_FAILURE,
- DatatypeMessageProvider.MSG_NONE,
- null));
+ DatatypeMessageProvider.MSG_NONE,
+ null));
}
}
isMaxExclusiveDefined = ((fFacetsDefined &
@@ -173,11 +180,11 @@
if ( isMaxExclusiveDefined && isMaxInclusiveDefined ) {
throw new InvalidDatatypeFacetException(
- "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." );
+ "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." );
}
if ( isMinExclusiveDefined && isMinInclusiveDefined ) {
throw new InvalidDatatypeFacetException(
- "It is an error for both minInclusive and minExclusive to be specified for the same datatype." );
+ "It is an error for both minInclusive and minExclusive to be specified for the same datatype." );
}
@@ -217,6 +224,14 @@
public Object validate(String content, Object state)
throws InvalidDatatypeValueException {
if ( fDerivationByList == false ) {
+ if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
+ if ( fRegex == null || fRegex.matches( content) == false )
+ throw new InvalidDatatypeValueException("Value'"+content+
+ "does not match regular expression facet" + fPattern );
+ }
+
+
+
float f = 0;
try {
f = Float.valueOf(content).floatValue();
@@ -288,9 +303,9 @@
public Hashtable getFacets(){
return null;
}
- /**
- * Returns a copy of this object.
- */
+ /**
+ * Returns a copy of this object.
+ */
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
}
1.6 +41 -16 xml-xerces/java/src/org/apache/xerces/validators/datatype/URIReferenceDatatypeValidator.java
Index: URIReferenceDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/URIReferenceDatatypeValidator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- URIReferenceDatatypeValidator.java 2000/06/20 20:42:11 1.5
+++ URIReferenceDatatypeValidator.java 2000/06/21 21:59:12 1.6
@@ -63,6 +63,7 @@
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
+import org.apache.xerces.utils.URI;
import org.apache.xerces.validators.schema.SchemaSymbols;
@@ -74,7 +75,7 @@
* @author Jeffrey Rodriguez
* @see RFC 2396
* @see Tim Berners-Lee, et. al. RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax.. 1998 Available at: http://www.ietf.org/rfc/rfc2396.txt
- * @version $Id: URIReferenceDatatypeValidator.java,v 1.5 2000/06/20 20:42:11 ericye Exp $
+ * @version $Id: URIReferenceDatatypeValidator.java,v 1.6 2000/06/21 21:59:12 jeffreyr Exp $
*/
public class URIReferenceDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
@@ -86,16 +87,18 @@
private String fPattern = null;
private Vector fEnumeration = null;
private int fFacetsDefined = 0;
+ private RegularExpression fRegex = null;
-
+
+
public URIReferenceDatatypeValidator () throws InvalidDatatypeFacetException{
- this ( null, null, false ); // Native, No Facets defined, Restriction
+ this ( null, null, false ); // Native, No Facets defined, Restriction
}
public URIReferenceDatatypeValidator ( DatatypeValidator base, Hashtable facets,
- boolean derivedByList ) throws InvalidDatatypeFacetException {
+ boolean derivedByList ) throws InvalidDatatypeFacetException {
- setBasetype( base ); // Set base type
+ setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ){
@@ -133,6 +136,9 @@
} else if (key.equals(SchemaSymbols.ELT_PATTERN)) {
fFacetsDefined += DatatypeValidator.FACET_PATTERN;
fPattern = (String)facets.get(key);
+ if ( fPattern != null )
+ fRegex = new RegularExpression(fPattern, "X" );
+
} else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
fEnumeration = (Vector)facets.get(key);
@@ -144,10 +150,10 @@
if (((fFacetsDefined & DatatypeValidator.FACET_LENGTH ) != 0 ) ) {
if (((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
- "It is an error for both length and maxLength to be members of facets." );
+ "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." );
}
}
@@ -155,7 +161,7 @@
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength > fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of maxLength = " + fMaxLength +
- "must be greater that the value of minLength" + fMinLength );
+ "must be greater that the value of minLength" + fMinLength );
}
}
} else { //derived by list
@@ -199,10 +205,10 @@
if (((fFacetsDefined & DatatypeValidator.FACET_LENGTH ) != 0 ) ) {
if (((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
- "It is an error for both length and maxLength to be members of facets." );
+ "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." );
}
}
@@ -210,15 +216,15 @@
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength > fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of maxLength = " + fMinLength +
- "must be greater that the value of minLength" + fMaxLength );
+ "must be greater that the value of minLength" + fMaxLength );
}
}
}
}// End of Facets Setting
}
+
-
/**
* Validates content to conform to a URIReference
@@ -231,11 +237,14 @@
* @exception InvalidDatatypeValueException
*/
public Object validate(String content, Object state)
- throws InvalidDatatypeValueException
+ throws InvalidDatatypeValueException
{
StringTokenizer parsedList = null;
+ URI uriContent = null
if ( fDerivedByList == true ) { //derived by list
+
+
parsedList = new StringTokenizer( content );
try {
while ( parsedList.hasMoreTokens() ) {
@@ -246,7 +255,23 @@
}
} else { //derived by constraint
//
+ if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
+ if ( fRegex == null || fRegex.matches( content) == false )
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' does not match regular expression facet" + fPattern );
+ }
+
+ try {
+ uriContent = new URI( content );
+
+ } catch ( URI.MalformedURIException ex ) {
+ throw new InvalidDatatypeValueException("Value '"+content+
+ "' is a Malformed URI ");
+
+ }
+
+
// checkContent( content ); TODO
}
return null;
@@ -274,9 +299,9 @@
return null;
}
- /**
- * Returns a copy of this object.
- */
+ /**
+ * Returns a copy of this object.
+ */
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
}