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/31 23:14:28 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype DecimalDatatypeValidator.java
jeffreyr 00/07/31 14:14:27
Modified: java/src/org/apache/xerces/validators/datatype
DecimalDatatypeValidator.java
Log:
fixed BigDecimal '+' bug, this shows in versions earlier than 1.2 causing a numErrorException to be thrown if value is like '+2.33'
Revision Changes Path
1.10 +31 -7 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DecimalDatatypeValidator.java 2000/07/31 17:56:52 1.9
+++ DecimalDatatypeValidator.java 2000/07/31 21:14:24 1.10
@@ -73,7 +73,7 @@
*
* @author Ted Leung
* @author Jeffrey Rodriguez
- * @version $Id: DecimalDatatypeValidator.java,v 1.9 2000/07/31 17:56:52 jeffreyr Exp $
+ * @version $Id: DecimalDatatypeValidator.java,v 1.10 2000/07/31 21:14:24 jeffreyr Exp $
*/
public class DecimalDatatypeValidator extends AbstractDatatypeValidator {
@@ -131,19 +131,19 @@
} else if (key.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
value = ((String) facets.get(key ));
fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
- fMaxInclusive = new BigDecimal(value);
+ fMaxInclusive = new BigDecimal(stripPlusIfPresent(value));
} else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
value = ((String) facets.get(key ));
fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
- fMaxExclusive = new BigDecimal(value);
+ fMaxExclusive = new BigDecimal(stripPlusIfPresent( value));
} else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
value = ((String) facets.get(key ));
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
- fMinInclusive = new BigDecimal(value);
+ fMinInclusive = new BigDecimal(stripPlusIfPresent(value));
} else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
value = ((String) facets.get(key ));
fFacetsDefined += DatatypeValidator.FACET_MINEXCLUSIVE;
- fMinExclusive = new BigDecimal(value);
+ fMinExclusive = new BigDecimal(stripPlusIfPresent(value));
} else if (key.equals(SchemaSymbols.ELT_PRECISION)) {
value = ((String) facets.get(key ));
fFacetsDefined += DatatypeValidator.FACET_PRECISSION;
@@ -229,7 +229,8 @@
try {
for ( ; i < enumeration.size(); i++) {
fEnumDecimal[i] =
- new BigDecimal( ((String) enumeration.elementAt(i)));
+ new BigDecimal( stripPlusIfPresent(((String) enumeration.elementAt(i))));
+
boundsCheck(fEnumDecimal[i]); // Check against max,min Inclusive, Exclusives
}
} catch ( Exception idve ){
@@ -275,7 +276,7 @@
BigDecimal d = null; // Is content a Decimal
try {
- d = new BigDecimal(content);
+ d = new BigDecimal( stripPlusIfPresent( content));
} catch (Exception nfe) {
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotDecimal,
@@ -419,6 +420,29 @@
fBaseValidator = base;
}
+ /**
+ * This class deals with a bug in BigDecimal class
+ * present up to version 1.1.2. 1.1.3 knows how
+ * to deal with the + sign.
+ *
+ * This method strips the first '+' if it found
+ * alone such as.
+ * +33434.344
+ *
+ * If we find +- then nothing happens we just
+ * return the string passed
+ *
+ * @param value
+ * @return
+ */
+ static private String stripPlusIfPresent( String value ){
+ String strippedPlus = value;
+
+ if( value.length() >= 2 && value.charAt(0) == '+' && value.charAt(1) != '-' ) {
+ strippedPlus = value.substring(1);
+ }
+ return strippedPlus;
+ }
}