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/02 07:36:28 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype AbstractDatatypeValidator.java BinaryDatatypeValidator.java BooleanDatatypeValidator.java DatatypeValidatorFactoryImpl.java DecimalDatatypeValidator.java DoubleDatatypeValidator.java ENTITYDatatypeValidator.java FloatDatatypeValidator.java IDDatatypeValidator.java IDREFDatatypeValidator.java InvalidDatatypeFacetException.java NOTATIONDatatypeValidator.java QNameDatatypeValidator.java RecurringDurationDatatypeValidator.java StringDatatypeValidator.java TimeDurationDatatypeValidator.java URIReferenceDatatypeValidator.java XMLException.java Makefile DatatypeMessageProvider.java DatatypeValidator.java DatatypeValidatorFactory.java InvalidDatatypeValueException.java
jeffreyr 00/06/01 22:36:27
Modified: java/src/org/apache/xerces/validators/datatype Makefile
DatatypeMessageProvider.java DatatypeValidator.java
DatatypeValidatorFactory.java
InvalidDatatypeValueException.java
Added: java/src/org/apache/xerces/validators/datatype
AbstractDatatypeValidator.java
BinaryDatatypeValidator.java
BooleanDatatypeValidator.java
DatatypeValidatorFactoryImpl.java
DecimalDatatypeValidator.java
DoubleDatatypeValidator.java
ENTITYDatatypeValidator.java
FloatDatatypeValidator.java
IDDatatypeValidator.java
IDREFDatatypeValidator.java
InvalidDatatypeFacetException.java
NOTATIONDatatypeValidator.java
QNameDatatypeValidator.java
RecurringDurationDatatypeValidator.java
StringDatatypeValidator.java
TimeDurationDatatypeValidator.java
URIReferenceDatatypeValidator.java
XMLException.java
Log:
Changes for new datatype factory architecture
Revision Changes Path
1.6 +19 -21 xml-xerces/java/src/org/apache/xerces/validators/datatype/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Makefile 2000/05/17 18:33:14 1.5
+++ Makefile 2000/06/02 05:36:25 1.6
@@ -1,30 +1,28 @@
# Makefile for directory ./org/apache/xerces/validators/datatype
TARGETS=\
- BinaryValidator.class\
- BooleanValidator.class\
+ AbstractDatatypeValidator.class\
+ BinaryDatatypeValidator.class\
+ BooleanDatatypeValidator.class\
DatatypeMessageProvider.class\
DatatypeValidator.class\
- DatatypeValidatorRegistry.class\
- DecimalValidator.class\
- DoubleValidator.class\
- FloatValidator.class\
- ConstrainException.class\
- IllegalFacetException.class\
- IllegalFacetValueException.class\
+ DatatypeValidatorFactory.class\
+ DecimalDatatypeValidator.class\
+ DoubleDatatypeValidator.class\
+ ENTITYDatatypeValidator.class \
+ FloatDatatypeValidator.class\
+ IDDatatypeValidator.class \
+ IDREFDatatypeValidator.class \
+ InvalidDatatypeFacetException.class\
InvalidDatatypeValueException.class\
- RecurringDurationValidator.class\
- StringValidator.class\
- TimeDurationValidator.class\
- UnknownFacetException.class\
- URIReferenceValidator.class \
- IDValidator.class \
- IDREFValidator.class \
- ENTITYValidator.class \
- NOTATIONValidator.class \
- QNameValidator.class\
- URIReferenceValidator.class \
- DatatypeValidatorRegistry.class
+ NOTATIONDatatypeValidator.class \
+ QNameDatatypeValidator.class\
+ StringDatatypeValidator.class\
+ URIReferenceDatatypeValidator.class \
+ RecurringDurationDatatypeValidator.class\
+ TimeDurationDatatypeValidator.class\
+ DatatypeValidatorFactoryImpl.class\
+ XMLException.class
DIRS =
1.4 +5 -0 xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeMessageProvider.java
Index: DatatypeMessageProvider.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeMessageProvider.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DatatypeMessageProvider.java 2000/05/17 18:33:12 1.3
+++ DatatypeMessageProvider.java 2000/06/02 05:36:25 1.4
@@ -62,6 +62,11 @@
import java.util.ResourceBundle;
import org.apache.xerces.utils.XMLMessageProvider;
+/**
+ * @version $i$
+ */
+
+
public class DatatypeMessageProvider implements XMLMessageProvider {
/**
* The domain of messages concerning the XML Schema: Datatypes specification.
1.5 +13 -42 xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidator.java
Index: DatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DatatypeValidator.java 2000/05/17 18:33:12 1.4
+++ DatatypeValidator.java 2000/06/02 05:36:25 1.5
@@ -68,6 +68,7 @@
* W3C to remove facets from the data type spec.
*
* @author Jeffrey Rodriguez-
+ * @version $i$
*/
public interface DatatypeValidator {
public static final int FACET_LENGTH = 1;
@@ -84,8 +85,6 @@
public static final int FACET_ENCODING = 1<<11;
public static final int FACET_DURATION = 1<<12;
public static final int FACET_PERIOD = 1<<13;
- public static final int DERIVED_BY_RESTRICTION = 1;
- public static final int DERIVED_BY_LIST = 1<<1;
@@ -105,56 +104,28 @@
* @exception InvalidDatatypeValueException
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
- public void validate(String content ) throws InvalidDatatypeValueException;
+ public Object validate(String content, Object state ) throws InvalidDatatypeValueException;
- /**
- * set the facets for this datatype
- *
- * setFacets is responsible for ensuring that the supplied facets do not contradict each
- * other.
- *
- * @param facets A hashtable where facet name Symbols are keys and facet values are stored
- * in the hashtable. Usually facet values are strings, except for the
- * enumeration facet. The value for this facet is a Vector of strings, one
- * per enumeration value
- * @exception throws UnknownFacetException
- * @exception throws IllegalFacetException
- * @exception throws IllegalFacetValueException
- * @exception UnknownFacetException
- * @exception IllegalFacetException
- * @exception IllegalFacetValueException
- * @exception ConstrainException
- * @see org.apache.xerces.validators.schema.SchemaSymbols
- * @see org.apache.xerces.validators.datatype.IllegalFacetException
- * @see org.apache.xerces.validators.datatype.IllegalFacetValueException
- * @see org.apache.xerces.validators.datatype.ConstrainException
- */
- public void setFacets(Hashtable facets,String derivationType ) throws UnknownFacetException,
- IllegalFacetException, IllegalFacetValueException, ConstrainException;
/**
- * Name of base type as a string.
- * A Native datatype has the string "native" as its
- * base type.
+ * returns the datatype facet if any is set as a
+ * Hashtable
*
- * @param base the validator for this type's base type
+ * @return
*/
- public void setBasetype(String base);
-
+ public Hashtable getFacets();
- /**
- * set the locate to be used for error messages
- */
- public void setLocale(Locale locale);
/**
- * REVISIT
- * Compares two Datatype for order
+ * Compares content in the Domain value vs. lexical
+ * value.
+ * e.g. If type is a float then 1.0 may be equivalent
+ * to 1 even tough both are lexically different.
*
- * @param o1
- * @param o2
+ * @param value1
+ * @param valu2
* @return
*/
- public int compare( DatatypeValidator o1, DatatypeValidator o2);
+ public int compare( String value1, String value2);
}
1.2 +3 -261 xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactory.java
Index: DatatypeValidatorFactory.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DatatypeValidatorFactory.java 2000/05/18 16:50:31 1.1
+++ DatatypeValidatorFactory.java 2000/06/02 05:36:25 1.2
@@ -61,270 +61,12 @@
import org.apache.xerces.validators.schema.SchemaSymbols;
-
-
/**
- * @version $Id: DatatypeValidatorFactory.java,v 1.1 2000/05/18 16:50:31 jeffreyr Exp $
+ * @version $Id: DatatypeValidatorFactory.java,v 1.2 2000/06/02 05:36:25 jeffreyr Exp $
* @author Jeffrey Rodriguez
*/
-public class DatatypeValidatorFactory {
- private static DatatypeValidatorRegistry _instance = new DatatypeValidatorRegistry();
- private Hashtable fRegistry = new Hashtable();
-
- private DatatypeValidatorFactory() {
- initializeRegistry();
- }
-
- /**
- * Initializes registry with primitive and derived
- * Simple types.
- */
- void initializeRegistry() {
- DatatypeValidator v = null;
-
- //Register Primitive Datatypes
-
- fRegistry.put("string", new StringValidator() );
- fRegistry.put("boolean", new BooleanValidator() );
- fRegistry.put("float", new FloatValidator());
- fRegistry.put("double", new DoubleValidator());
- fRegistry.put("decimal", new DecimalValidator());
- fRegistry.put("timeDuration", new TimeDurationValidator());
- fRegistry.put("recurringDuration", new RecurringDurationValidator());
- fRegistry.put("binary", new BinaryValidator());
- fRegistry.put("uriReference", new URIReferenceValidator());
- fRegistry.put("ID", new IDValidator());
- fRegistry.put("IDREF", new IDREFValidator());
- fRegistry.put("ENTITY", new ENTITYValidator());
- fRegistry.put("NOTATION", new NOTATIONValidator());
- fRegistry.put("QName", new QNameValidator());
-
-
-
-
- Hashtable facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PATTERN , "([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*" );
- addValidator("language",
- createDatatypeValidator("language", new StringValidator() , facets,
- false ));
-
- addValidator("IDREFS",
- createDatatypeValidator( "IDREFS", new IDREFValidator(), null , true ));
-
- addValidator("ENTITIES",
- createDatatypeValidator( "ENTITIES", new ENTITYValidator(), null, true ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PATTERN , "\\c+" );
- addValidator("NMTOKEN",
- createDatatypeValidator("NMTOKEN", new StringValidator(), facets, false ));
-
- addValidator("NMTOKENS",
- createDatatypeValidator("NMTOKENS", new
- getDatatypeValidator( "NMTOKEN" ), facets, true );
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PATTERN , "\\i\\c*" );
- addValidator("Name",
- createDatatypeValidator("Name", new StringValidator(), facets, false );
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
- addValidator("NCName",
- createDatatypeValidator("NCName", new StringValidator(), facets, false ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_SCALE, "0");
- addValidator("integer",
- createDatatypeValidator("integer", new DecimalValidator(), facets, false));
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "0" );
- addValidator("nonPositiveInteger",
- createDatatypeValidator("nonPositiveInteger",
- getDatatypeValidator("integer"), facets, false );
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "-1" );
- addValidator("negativeInteger",
- createDatatypeValidator("negativeInteger",
- getDatatypeValidator( "nonPositiveInteger", facets, false );
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "9223372036854775807");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-9223372036854775808");
- addValidator("long",
- createDatatypeValidator("integer", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "2147483647");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-2147483648");
- addValidator("int",
- createDatatypeValidator("long", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "32767");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-32768");
- addValidator("short",
- createDatatypeValidator("int", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "127");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-128");
- addValidator("byte",
- createDatatypeValidator("short", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "0" );
- addValidator("nonNegativeInteger",
- createDatatypeValidator("integer", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "18446744073709551615" );
- addValidator("unsignedLong",
- createDatatypeValidator("nonNegativeInteger", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "4294967295" );
- addValidator("unsignedInt",
- createDatatypeValidator("unsignedLong", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "65535" );
- addValidator("unsignedShort",
- createDatatypeValidator("unsignedInt", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "255" );
- addValidator("unsignedByte",
- createDatatypeValidator("unsignedShort", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
- facets.put(SchemaSymbols.ELT_PERIOD, "P0Y" );
- addValidator("timeInstant",
- createDatatypeValidator("recurringDuration", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
- facets.put(SchemaSymbols.ELT_PERIOD, "PY24H" );
- addValidator("time",
- createDatatypeValidator("recurringDuration", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PERIOD, "P0Y" );
- addValidator("timePeriod",
- createDatatypeValidator("recurringDuration", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_DURATION, "PT24H" );
- addValidator("date",
- createDatatypeValidator("timePeriod", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_DURATION, "P1M" );
- addValidator("month",
- createDatatypeValidator("timePeriod", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_DURATION, "P1Y" );
- addValidator("year",
- createDatatypeValidator("timePeriod", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_DURATION, "P100Y" );
- addValidator("century",
- createDatatypeValidator("timePeriod", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
-
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PERIOD, "P1Y" );
- facets.put(SchemaSymbols.ELT_DURATION, "PT24H" );
- addValidator("recurringDate",
- createDatatypeValidator("recurringDuration", facets,
- SchemaSymbols.ATTVAL_RESTRICTION ));
- }
-
+public interface DatatypeValidatorFactory {
public DatatypeValidator createDatatypeValidator(String typeName,
- DatatypeValidator base, Hashtable facets, boolean list ){
- DatatypeValidator baseDatatype = base;
- try {
- if( baseDatatype != null ) {
- if( facets != null )
- baseDatatype.setFacets(facets, list );
- }
- } catch (IllegalFacetException ex) {
- ex.printStackTrace();
- } catch (IllegalFacetValueException ex) {
- ex.printStackTrace();
- } catch (UnknownFacetException ex) {
- ex.printStackTrace();
- } catch (ConstrainException ex ) {
- ex.printStackTrace();
- }
- return baseDatatype;
- }
-
- private DatatypeValidator getDatatypeValidator(String type) {
- DatatypeValidator simpleType = null;
- if( fRegistry.containsKey( type ) == true ){
- simpleType = (DatatypeValidator) fRegistry.get(type);
- if( simpleType != null ) {
- try {
- simpleType = (DatatypeValidator) simpleType.getClass().newInstance();
- } catch( InstantiationException e ) {
- e.printStackTrace();
- } catch( IllegalAccessException e ) {
- e.printStackTrace();
- }
- }
- }
- return simpleType;
- }
-
- private public void addValidator(String name, DatatypeValidator v) {
- fRegistry.put(name,v);
- }
-
- static private DatatypeValidatorRegistry getDatatypeRegistry() {
- return _instance;
- }
-
- static public void main( String argv[] ){
- DatatypeValidatorRegistry tstRegistry = DatatypeValidatorRegistry.getDatatypeRegistry();
-
- DatatypeValidator tstData1 = tstRegistry.getDatatypeValidator( "NTOKEN" );
- DatatypeValidator tstData2 = tstRegistry.getDatatypeValidator( "NTOKENS" );
-
- System.out.println( "NMTOKEN = " + tstData1 );
- System.out.println( "NMTOKENS = " + tstData2 );
-
- }
-
-
-
+ DatatypeValidator base, Hashtable facets, boolean list );
}
1.2 +8 -2 xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeValueException.java
Index: InvalidDatatypeValueException.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeValueException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvalidDatatypeValueException.java 1999/11/09 01:12:06 1.1
+++ InvalidDatatypeValueException.java 2000/06/02 05:36:26 1.2
@@ -61,10 +61,16 @@
* InvalidDatatypeValueException is thrown when data value doesn't match it's datatype
*
*/
-public class InvalidDatatypeValueException
- extends Exception {
+public class InvalidDatatypeValueException extends XMLException {
public InvalidDatatypeValueException() { super(); }
public InvalidDatatypeValueException(String msg) { super(msg); }
+ public InvalidDatatypeValueException ( Exception exception ) {
+ super( exception );
+ }
+ public InvalidDatatypeValueException ( String message, Exception exception ) {
+ super( message, exception );
+ }
+
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/AbstractDatatypeValidator.java
Index: AbstractDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* @version $Id: AbstractDatatypeValidator.java,v 1.1 2000/06/02 05:36:25 jeffreyr Exp $
* @author Jeffrey Rodriguez
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import org.apache.xerces.validators.datatype.DatatypeValidator;
class AbstractDatatypeValidator implements DatatypeValidator {
private Hashtable fFacets; // Hashtable of Facets Strings.
public AbstractDatatypeValidator(){
}
public AbstractDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean list ){
}
/**
* Checks that "content" string is valid
* datatype.
* If invalid a Datatype validation exception is thrown.
*
* @param content A string containing the content to be validated
* @param derivedBylist
* Flag which is true when type
* is derived by list otherwise it
* it is derived by extension.
*
* @exception throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @exception InvalidDatatypeValueException
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException{
return null;
}
/**
* returns the datatype facet if any is set as a
* Hashtable
*
* @return
*/
public Hashtable getFacets() {
return null;
}
/**
* Compares content in the Domain value vs. lexical
* value.
* e.g. If type is a float then 1.0 may be equivalent
* to 1 even tough both are lexically different.
*
* @param value1
* @param valu2
* @return
*/
public int compare(String value1, String valu2) {
return 0;
}
/**
* sets the datatype facet if any is set as a
* Hashtable
*
* @return
*/
public void setFacets(Hashtable facets, boolean list) {
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/BinaryDatatypeValidator.java
Index: BinaryDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.utils.regex.RegularExpression;
import org.apache.xerces.utils.Base64;
import org.apache.xerces.utils.HexBin;
/**
*
* binaryValidator validates that XML content is a W3C binary type.
*
* @author Ted Leung
* @author Jeffrey Rodriguez
* @version $Id: BinaryDatatypeValidator.java,v 1.1 2000/06/02 05:36:25 jeffreyr Exp $
*/
public class BinaryDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null; //Basetype null means this is a native type
private int fLength = 0;
private int fMaxLength = 0;
private int fMinLength = 0;
private String fPattern = null;
private Vector fEnumeration = null;
private int fFacetsDefined = 0;
private String fEncoding = SchemaSymbols.ATTVAL_BASE64;//default Base64 encoding
private boolean fDerivedByList = false; // Default is restriction
public BinaryDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public BinaryDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
if( base != null )
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ) {
if ( derivedByList == false ) {
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH ) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+
lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+
lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else 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;
fEnumeration = (Vector)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_ENCODING )) {
fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
fEncoding = (String)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
} else { //Derivation by List
fDerivedByList = true;
}
}// End of Facet setting
}
/**
* validate that a string is a W3C binary type
*
* validate returns true or false depending on whether the string content is an
* instance of the W3C binary datatype
*
* @param content A string containing the content to be validated
*
* @exception throws InvalidDatatypeException if the content is
* not a W3C binary type
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException {
if ( fDerivedByList == false) { //derived by restriction
if (((fFacetsDefined & DatatypeValidator.FACET_ENCODING) != 0 ) ){ //Encode defined then validate
if ( fEncoding.equals( SchemaSymbols.ATTVAL_BASE64)){ //Base64
if ( Base64.isBase64( content ) == false ) {
throw new InvalidDatatypeValueException( "Value '"+
content+ "' must be" + "is not encoded in Base64" );
}
} else { //HexBin
if ( HexBin.isHex( content ) == false ){
throw new InvalidDatatypeValueException( "Value '"+
content+ "' must be" + "is not encoded in Hex" );
}
}
}
} else{ //derived by list
}
return null;
}
/**
* Compare two Binary Datatype Lexical values.
*
* @param content1
* @param content2
* @return
*/
public int compare( String content1, String content2){
return 0;
}
/**
* Returns a Hastable that represent the facets
* state of the datatype.
*
* @return
*/
public Hashtable getFacets(){
return null;
}
//Private methods
/**
* Set base type
*
* @param base
*/
private void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/BooleanDatatypeValidator.java
Index: BooleanDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Enumeration;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.utils.regex.RegularExpression;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.validators.datatype.InvalidDatatypeFacetException;
/**
*
* BooleanValidator validates that content satisfies the W3C XML Datatype for Boolean
*
* @author Ted Leung
* @author Jeffrey Rodriguez
* @version $Id: BooleanDatatypeValidator.java,v 1.1 2000/06/02 05:36:25 jeffreyr Exp $
*/
public class BooleanDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null; //Basetype null means we are a native type
private String fPattern = null;
private int fFacetsDefined = 0;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
private static final String fValueSpace[] = { "false", "true", "0", "1"};
private boolean fDerivedByList = false;
public BooleanDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public BooleanDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ) {
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 {
throw new InvalidDatatypeFacetException();
}
}
} else { // By List
fDerivedByList = true;
}
}// End of facet setting
}
/**
* validate that a string matches the boolean datatype
* @param content A string containing the content to be validated
*
* @exception throws InvalidDatatypeException if the content is
* is not valid.
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException {
if ( fDerivedByList == true ) {
;// What does it mean?
} else {
checkContent( content );
}
return null;
}
/**
* Compare two boolean data types
*
* @param content1
* @param content2
* @return
*/
public int compare( String content1, String content2){
return 0;
}
/**
* Return a Hashtable that contains facet information
*
* @return Hashtable
*/
public Hashtable getFacets(){
return null;
}
//Begin private method definitions
/**
* Sets the base datatype name.
*
* @param base
*/
private void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
private String getErrorString(int major, int minor, Object args[]) {
try {
return fMessageProvider.createMessage(fLocale, major, minor, args);
} catch (Exception e) {
return "Illegal Errorcode "+minor;
}
}
/**
* Checks content for validity.
*
* @param content
* @exception InvalidDatatypeValueException
*/
private void checkContent( String content )throws InvalidDatatypeValueException {
boolean isContentInDomain = false;
for ( int i = 0;i<fValueSpace.length;i++ ) {
if ( content.equals(fValueSpace[i] ) )
isContentInDomain = true;
}
if (isContentInDomain == false)
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotBoolean,
DatatypeMessageProvider.MSG_NONE,
new Object[] { content}));
if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
RegularExpression regex = new RegularExpression(fPattern, "X" );
if ( regex.matches( content) == false )
throw new InvalidDatatypeValueException("Value'"+content+
"does not match regular expression facet" + fPattern );
}
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java
Index: DatatypeValidatorFactoryImpl.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.lang.reflect.*;
import org.apache.xerces.validators.datatype.*;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.validators.datatype.DatatypeValidatorFactory;
/**
* @version $Id: DatatypeValidatorFactoryImpl.java,v 1.1 2000/06/02 05:36:25 jeffreyr Exp $
* @author Jeffrey Rodriguez
*/
public class DatatypeValidatorFactoryImpl implements DatatypeValidatorFactory {
private static DatatypeValidatorFactoryImpl _instance = new DatatypeValidatorFactoryImpl();
private Hashtable fRegistry = new Hashtable();
private DatatypeValidatorFactoryImpl() {
initializeRegistry();
}
/**
* Initializes registry with primitive and derived
* Simple types.
*/
void initializeRegistry() {
DatatypeValidator v = null;
//Register Primitive Datatypes
try {
fRegistry.put("string", new StringDatatypeValidator() );
fRegistry.put("boolean", new BooleanDatatypeValidator() );
fRegistry.put("float", new FloatDatatypeValidator());
fRegistry.put("double", new DoubleDatatypeValidator());
fRegistry.put("decimal", new DecimalDatatypeValidator());
fRegistry.put("timeDuration", new TimeDurationDatatypeValidator());
fRegistry.put("recurringDuration", new RecurringDurationDatatypeValidator());
fRegistry.put("binary", new BinaryDatatypeValidator());
fRegistry.put("uriReference", new URIReferenceDatatypeValidator());
fRegistry.put("ID", new IDDatatypeValidator());
fRegistry.put("IDREF", new IDREFDatatypeValidator());
fRegistry.put("ENTITY", new ENTITYDatatypeValidator());
fRegistry.put("NOTATION", new NOTATIONDatatypeValidator());
fRegistry.put("QName", new QNameDatatypeValidator());
Hashtable facets = new Hashtable();
facets.put(SchemaSymbols.ELT_PATTERN , "([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*" );
addValidator("language",
createDatatypeValidator("language", new StringDatatypeValidator() , facets,
false ));
addValidator("IDREFS",
createDatatypeValidator( "IDREFS", new IDREFDatatypeValidator(), null , true ));
addValidator("ENTITIES",
createDatatypeValidator( "ENTITIES", new ENTITYDatatypeValidator(), null, true ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_PATTERN , "\\c+" );
addValidator("NMTOKEN",
createDatatypeValidator("NMTOKEN", new StringDatatypeValidator(), facets, false ));
addValidator("NMTOKENS",
createDatatypeValidator("NMTOKENS",
getDatatypeValidator( "NMTOKEN" ), null, true ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_PATTERN , "\\i\\c*" );
addValidator("Name",
createDatatypeValidator("Name", new StringDatatypeValidator(), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
addValidator("NCName",
createDatatypeValidator("NCName", new StringDatatypeValidator(), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_SCALE, "0");
addValidator("integer",
createDatatypeValidator("integer", new DecimalDatatypeValidator(), facets, false));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "0" );
addValidator("nonPositiveInteger",
createDatatypeValidator("nonPositiveInteger",
getDatatypeValidator("integer"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "-1" );
addValidator("negativeInteger",
createDatatypeValidator("negativeInteger",
getDatatypeValidator( "nonPositiveInteger"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "9223372036854775807");
facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-9223372036854775808");
addValidator("long",
createDatatypeValidator("long",
getDatatypeValidator( "integer"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "2147483647");
facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-2147483648");
addValidator("int",
createDatatypeValidator("int",
getDatatypeValidator( "long"), facets,false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "32767");
facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-32768");
addValidator("short",
createDatatypeValidator("short",
getDatatypeValidator( "int"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE , "127");
facets.put(SchemaSymbols.ELT_MININCLUSIVE, "-128");
addValidator("byte",
createDatatypeValidator("byte",
getDatatypeValidator( "short"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MININCLUSIVE, "0" );
addValidator("nonNegativeInteger",
createDatatypeValidator("nonNegativeInteger",
getDatatypeValidator( "integer"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "18446744073709551615" );
addValidator("unsignedLong",
createDatatypeValidator("unsignedLong",
getDatatypeValidator( "nonNegativeInteger"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "4294967295" );
addValidator("unsignedInt",
createDatatypeValidator("unsignedInt",
getDatatypeValidator( "unsignedLong"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "65535" );
addValidator("unsignedShort",
createDatatypeValidator("unsignedShort",
getDatatypeValidator( "unsignedInt"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "255" );
addValidator("unsignedByte",
createDatatypeValidator("unsignedByte",
getDatatypeValidator( "unsignedShort"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_MAXINCLUSIVE, "255" );
addValidator("positiveInteger",
createDatatypeValidator("positiveInteger",
getDatatypeValidator( "nonNegativeInteger"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
facets.put(SchemaSymbols.ELT_PERIOD, "P0Y" );
addValidator("timeInstant",
createDatatypeValidator("timeInstant",
getDatatypeValidator( "recurringDuration"),facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_DURATION, "P0Y" );
facets.put(SchemaSymbols.ELT_PERIOD, "PY24H" );
addValidator("time",
createDatatypeValidator("time",
getDatatypeValidator( "recurringDuration"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_PERIOD, "P0Y" );
addValidator("timePeriod",
createDatatypeValidator("timePeriod",
getDatatypeValidator( "recurringDuration"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_DURATION, "PT24H" );
addValidator("date",
createDatatypeValidator("date",
getDatatypeValidator( "timePeriod"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_DURATION, "P1M" );
addValidator("month",
createDatatypeValidator("month",
getDatatypeValidator( "timePeriod"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_DURATION, "P1Y" );
addValidator("year",
createDatatypeValidator("year",
getDatatypeValidator( "timePeriod"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_DURATION, "P100Y" );
addValidator("century",
createDatatypeValidator("century",
getDatatypeValidator( "timePeriod"), facets, false ));
facets = new Hashtable();
facets.put(SchemaSymbols.ELT_PERIOD, "P1Y" );
facets.put(SchemaSymbols.ELT_DURATION, "PT24H" );
addValidator("recurringDate",
createDatatypeValidator("recurringDate",
getDatatypeValidator( "recurringDuration"),facets, false ));
} catch ( InvalidDatatypeFacetException ex ){
ex.printStackTrace();
}
}
public DatatypeValidator createDatatypeValidator(String typeName,
DatatypeValidator base, Hashtable facets, boolean list ){
DatatypeValidator simpleType = null;
if ( base != null ) {
try {
Class [] validatorArgsClass = new Class[] {
org.apache.xerces.validators.datatype.DatatypeValidator.class,
java.util.Hashtable.class,
boolean.class};
Object [] validatorArgs = new Object[] {
base, facets, new Boolean( list )};
Class validatorDef =
Class.forName(
"org.apache.xerces.validators.datatype.AbstractDatatypeValidator" );
Constructor validatorConstructor =
validatorDef.getConstructor( validatorArgsClass );
simpleType =
( DatatypeValidator ) createDatatypeValidator (
validatorConstructor, validatorArgs );
addValidator( typeName, simpleType );//register validator
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
return simpleType;// return it
}
private static Object createDatatypeValidator(Constructor validatorConstructor,
Object[] arguments) {
Object validator = null;
try {
validator = validatorConstructor.newInstance(arguments);
return validator;
} catch (InstantiationException e) {
System.out.println(e);
} catch (IllegalAccessException e) {
System.out.println(e);
} catch (IllegalArgumentException e) {
System.out.println(e);
} catch (InvocationTargetException e) {
System.out.println(e);
}
return validator;
}
public DatatypeValidator getDatatypeValidator(String type) {
DatatypeValidator simpleType = null;
if ( fRegistry.containsKey( type ) == true ) {
simpleType = (DatatypeValidator) fRegistry.get(type);
if ( simpleType != null ) {
try {
simpleType = (DatatypeValidator) simpleType.getClass().newInstance();
} catch ( InstantiationException e ) {
e.printStackTrace();
} catch ( IllegalAccessException e ) {
e.printStackTrace();
}
}
}
return simpleType;
}
private void addValidator(String name, DatatypeValidator v) {
fRegistry.put(name,v);
}
static public DatatypeValidatorFactoryImpl getDatatypeRegistry() {
return _instance;
}
static public void main( String argv[] ){
DatatypeValidatorFactoryImpl tstRegistry = DatatypeValidatorFactoryImpl.getDatatypeRegistry();
DatatypeValidator tstData1 = tstRegistry.getDatatypeValidator( "NTOKEN" );
DatatypeValidator tstData2 = tstRegistry.getDatatypeValidator( "NTOKENS" );
System.out.println( "NMTOKEN = " + tstData1 );
System.out.println( "NMTOKENS = " + tstData2 );
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/DecimalDatatypeValidator.java
Index: DecimalDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import org.apache.xerces.validators.schema.SchemaSymbols;
/**
*
* DecimalValidator validates that content satisfies the W3C XML Datatype for decimal
*
* @author Ted Leung
* @author Jeffrey Rodriguez
* @version
*/
public class DecimalDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null; // Null means a native datatype
private boolean fDerivationByList = false; //Derived by restriction is defaul
private BigDecimal[] fEnumDecimal = null;
private String fPattern = null;
private BigDecimal fMaxInclusive = null;
private BigDecimal fMaxExclusive = null;
private BigDecimal fMinInclusive = null;
private BigDecimal fMinExclusive = null;
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 DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
public DecimalDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public DecimalDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
if ( facets != null ) { // Set Facet
if ( derivedByList == false ) { // Derivation by Constraint
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
String value = ((String) facets.get(key ));
try {
if (key.equals(SchemaSymbols.ELT_PATTERN)) {
fFacetsDefined += DatatypeValidator.FACET_PATTERN;
fPattern = value;
} 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;
fMaxInclusive = new BigDecimal(value);
} else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
fMaxExclusive = new BigDecimal(value);
} else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
fMinInclusive = new BigDecimal(value);
} else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
fMinExclusive = new BigDecimal(value);
} else if (key.equals(SchemaSymbols.ELT_PRECISION)) {
fFacetsDefined += DatatypeValidator.FACET_PRECISSION;
isPrecisionDefined = true;
fPrecision = Integer.parseInt(value );
} else if (key.equals(SchemaSymbols.ELT_SCALE)) {
fFacetsDefined += DatatypeValidator.FACET_SCALE;
isScaleDefined = true;
fScale = Integer.parseInt( value );
} else {
throw new InvalidDatatypeFacetException(
getErrorString( DatatypeMessageProvider.MSG_FORMAT_FAILURE,
DatatypeMessageProvider.MSG_NONE, null));
}
} catch ( NumberFormatException ex ){
throw new InvalidDatatypeFacetException( getErrorString(
DatatypeMessageProvider.IllegalFacetValue,
DatatypeMessageProvider.MSG_NONE, new Object [] { value, key}));
}
}
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) {
fEnumDecimal = new BigDecimal[v.size()];
for (int i = 0; i < v.size(); i++)
try {
fEnumDecimal[i] = new BigDecimal( ((String) v.elementAt(i)));
boundsCheck(fEnumDecimal[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) {
throw new InvalidDatatypeFacetException(
"Internal Error parsing enumerated values for Decimal type");
}
}
}
} else { // Derivation by List
}
}//End of Facet setup
}
/**
* validate that a string matches the decimal datatype
*
* validate returns true or false depending on whether the string content is a
* W3C decimal type.
*
* @param content A string containing the content to be validated
*
* @exception throws InvalidDatatypeException if the content is
* is not a W3C decimal type
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException {
if ( fDerivationByList == false ) { //derived by restriction
BigDecimal d = null; // Is content a Decimal
try {
d = new BigDecimal(content);
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotDecimal,
DatatypeMessageProvider.MSG_NONE,
new Object[] { content}));
}
if( isScaleDefined == true ) {
if (d.scale() > fScale)
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.ScaleExceeded,
DatatypeMessageProvider.MSG_NONE,
new Object[] { content}));
}
if( isPrecisionDefined == true ) {
int precision = d.movePointRight(d.scale()).toString().length() -
((d.signum() < 0) ? 1 : 0); // account for minus sign
if (precision > fPrecision)
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.PrecisionExceeded,
DatatypeMessageProvider.MSG_NONE,
new Object[] {content} ));
}
boundsCheck(d);
if ( fEnumDecimal != null )
enumCheck(d);
} else { //derivation by list
}
return null;
}
/*
* check that a facet is in range, assumes that facets are compatible -- compatibility ensured by setFacets
*/
private void boundsCheck(BigDecimal d) throws InvalidDatatypeValueException {
boolean minOk = false;
boolean maxOk = false;
if ( isMaxInclusiveDefined)
maxOk = (d.compareTo(fMaxInclusive) <= 0);
else if ( isMaxExclusiveDefined)
maxOk = (d.compareTo(fMaxExclusive) < 0);
else
maxOk = (!isMaxInclusiveDefined && ! isMaxExclusiveDefined);
if ( isMinInclusiveDefined)
minOk = (d.compareTo(fMinInclusive) >= 0);
else if ( isMinExclusiveDefined)
minOk = (d.compareTo(fMinInclusive) > 0);
else
minOk = (!isMinInclusiveDefined && !isMinExclusiveDefined);
if (!(minOk && maxOk))
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.OutOfBounds,
DatatypeMessageProvider.MSG_NONE,
new Object [] { d}));
}
private void enumCheck(BigDecimal v) throws InvalidDatatypeValueException {
for (int i = 0; i < fEnumDecimal.length; i++) {
if (v == fEnumDecimal[i]) return;
}
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotAnEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { v}));
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
fLocale = locale;
}
public Hashtable getFacets(){
return null;
}
private String getErrorString(int major, int minor, Object args[]) {
try {
return fMessageProvider.createMessage(fLocale, major, minor, args);
} catch (Exception e) {
return "Illegal Errorcode "+minor;
}
}
/*
public static void main(String args[]) {
// simple unit test
try {
DatatypeValidator v = new DecimalValidator();
Hashtable facets = new Hashtable();
facets.put("minInclusive","0");
DatatypeValidator nonneg = new DecimalValidator();
nonneg.setBasetype(v);
nonneg.setFacets(facets);
facets = new Hashtable();
facets.put("minInclusive","-1");
DatatypeValidator bad = new DecimalValidator();
bad.setBasetype(nonneg);
bad.setFacets(facets);
} catch (Exception e) {
e.printStackTrace();
}
}
*/
public int compare( String content1, String content2){
return 0;
}
private void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java
Index: DoubleDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import org.apache.xerces.validators.schema.SchemaSymbols;
/**
*
* @author Ted Leung
* @author Jeffrey Rodriguez
* @version
*/
public class DoubleDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null; // Null means a native datatype
private boolean fDerivationByList = false; //Derived by restriction is defaul
private double[] fEnumDoubles = null;
private String fPattern = null;
private double fMaxInclusive = Double.MAX_VALUE;
private double fMaxExclusive = Double.MAX_VALUE;
private double fMinInclusive = Double.MIN_VALUE;
private double fMinExclusive = Double.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();
public DoubleDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public DoubleDatatypeValidator ( DatatypeValidator base, Hashtable facets,
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 {
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." );
}
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
}
/**
* validate that a string matches the real datatype
* @param content A string containing the content to be validated
* @exception throws InvalidDatatypeException if the content is
* is not a W3C real type
*/
public Object validate(String content, Object state)
throws InvalidDatatypeValueException {
if ( fDerivationByList == false ) { //derived by restriction
double d = 0.0;
try {
d = Double.valueOf(content).doubleValue();
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotReal,
DatatypeMessageProvider.MSG_NONE,
new Object [] { content}));
}
boundsCheck(d);
if (((fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) )
enumCheck(d);
} else {
;// TODO Derived by list validation
}
return null;
}
// Private Methods start here
/*
* check that a facet is in range, assumes that facets are compatible -- compatibility ensured by setFacets
*/
private void boundsCheck(double d) throws InvalidDatatypeValueException {
boolean inUpperBound = false;
boolean inLowerBound = false;
if ( isMaxInclusiveDefined ) {
inUpperBound = ( d <= fMaxInclusive );
} else if ( isMaxExclusiveDefined ) {
inUpperBound = ( d < fMaxExclusive );
}
if ( isMinInclusiveDefined ) {
inLowerBound = ( d >= fMinInclusive );
} else if ( isMinExclusiveDefined ) {
inLowerBound = ( d > fMinExclusive );
}
if ( inUpperBound == false || inLowerBound == false ) { // within bounds ?
getErrorString(DatatypeMessageProvider.OutOfBounds,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Double(d)});
}
}
private void enumCheck(double v) throws InvalidDatatypeValueException {
for (int i = 0; i < fEnumDoubles.length; i++) {
if (v == fEnumDoubles[i]) return;
}
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotAnEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Double(v)}));
}
/**
* Compare two Double datatype. Comparison is
* in Space value.
*
* @param content1
* @param content2
* @return
*/
public int compare( String content1, String content2){
return 0;
}
/**
* Returns a Hashtable containing facet information.
*
* @return
*/
public Hashtable getFacets(){
return null;
}
private String getErrorString(int major, int minor, Object args[]) {
try {
return fMessageProvider.createMessage(fLocale, major, minor, args);
} catch (Exception e) {
return "Illegal Errorcode "+minor;
}
}
private void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/ENTITYDatatypeValidator.java
Index: ENTITYDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Locale;
/**
* ENTITYDatatypeValidator 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: ENTITYDatatypeValidator.java,v 1.1 2000/06/02 05:36:25 jeffreyr Exp $
*/
public class ENTITYDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
private boolean fDerivedByList = false;
public ENTITYDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public ENTITYDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
;
}
/**
* Checks that "content" string is valid
* datatype.
* If invalid a Datatype validation exception is thrown.
*
* @param content A string containing the content to be validated
* @param derivedBylist
* Flag which is true when type
* is derived by list otherwise it
* it is derived by extension.
*
* @exception throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @exception InvalidDatatypeValueException
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
return null;
}
/**
* REVISIT
* Compares two Datatype for order
*
* @return
*/
public int compare( String content1, String content2){
return -1;
}
public Hashtable getFacets(){
return null;
}
// Private methods start here
/**
*
* @param base the validator for this type's base type
*/
private void setBasetype(DatatypeValidator base){
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/FloatDatatypeValidator.java
Index: FloatDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import org.apache.xerces.validators.schema.SchemaSymbols;
/**
*
* @author Ted Leung
* @author Jeffrey Rodriguez
* @version $Id: FloatDatatypeValidator.java,v 1.1 2000/06/02 05:36:25 jeffreyr Exp $
*/
public class FloatDatatypeValidator extends AbstractDatatypeValidator {
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 boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
public FloatDatatypeValidator () throws InvalidDatatypeFacetException{
this( null, null, false ); // Native, No Facets defined, Restriction
}
public FloatDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
if ( base != null )
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ) {
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 = Float.valueOf(value).floatValue();
} 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 = Float.valueOf(value).floatValue();
} 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 = Float.valueOf(value).floatValue();
} 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 = Float.valueOf(value).floatValue();
} 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." );
}
if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) {
Vector v = (Vector) facets.get(SchemaSymbols.ELT_ENUMERATION);
if (v != null) {
fEnumFloats = new float[v.size()];
for (int i = 0; i < v.size(); i++)
try {
fEnumFloats[i] = Float.valueOf((String) v.elementAt(i)).floatValue();
boundsCheck(fEnumFloats[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 { //derivation by list - WORK TO DO
fDerivationByList = true;
}
}// End facet setup
}
/**
* validate that a string matches the real datatype
* @param content A string containing the content to be validated
* @exception throws InvalidDatatypeException if the content is
* is not a W3C real type
*/
public Object validate(String content, Object state)
throws InvalidDatatypeValueException {
if ( fDerivationByList == false ) {
float f = 0;
try {
f = Float.valueOf(content).floatValue();
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotReal,
DatatypeMessageProvider.MSG_NONE,
new Object [] { content}));
}
boundsCheck(f);
if (((fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) )
enumCheck(f);
} else {
;// TODO Derived by list
}
return null;
}
/*
* check that a facet is in range, assumes that facets are compatible -- compatibility ensured by setFacets
*/
private void boundsCheck(float f) throws InvalidDatatypeValueException {
boolean inUpperBound = false;
boolean inLowerBound = false;
if ( isMaxInclusiveDefined ) {
inUpperBound = ( f <= fMaxInclusive );
} else if ( isMaxExclusiveDefined ) {
inUpperBound = ( f < fMaxExclusive );
}
if ( isMinInclusiveDefined ) {
inLowerBound = ( f >= fMinInclusive );
} else if ( isMinExclusiveDefined ) {
inLowerBound = ( f > fMinExclusive );
}
if ( inUpperBound == false || inLowerBound == false ) { // within bounds ?
getErrorString(DatatypeMessageProvider.OutOfBounds,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Float(f)});
}
}
private void enumCheck(float v) throws InvalidDatatypeValueException {
for (int i = 0; i < fEnumFloats.length; i++) {
if (v == fEnumFloats[i]) return;
}
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotAnEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Float(v)}));
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
fLocale = locale;
}
public int compare( String content1, String content2){
return 0;
}
public Hashtable getFacets(){
return null;
}
private String getErrorString(int major, int minor, Object args[]) {
try {
return fMessageProvider.createMessage(fLocale, major, minor, args);
} catch (Exception e) {
return "Illegal Errorcode "+minor;
}
}
private void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java
Index: IDDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Locale;
/**
* DataTypeValidator 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:
*/
public class IDDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
private boolean fDerivedByList = false;
public IDDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public IDDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
}
/**
* Checks that "content" string is valid
* datatype.
* If invalid a Datatype validation exception is thrown.
*
* @param content A string containing the content to be validated
* @param derivedBylist
* Flag which is true when type
* is derived by list otherwise it
* it is derived by extension.
*
* @exception throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @exception InvalidDatatypeValueException
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
return null;
}
/**
* REVISIT
* Compares two Datatype for order
*
* @param o1
* @param o2
* @return
*/
public int compare( String content1, String content2){
return -1;
}
public Hashtable getFacets(){
return null;
}
/**
* Name of base type as a string.
* A Native datatype has the string "native" as its
* base type.
*
* @param base the validator for this type's base type
*/
private void setBasetype(DatatypeValidator base){
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java
Index: IDREFDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Locale;
/**
* 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-
*/
public class IDREFDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
private boolean fDerivedByList = false;
public IDREFDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public IDREFDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
}
/**
* Checks that "content" string is valid
* datatype.
* If invalid a Datatype validation exception is thrown.
*
* @param content A string containing the content to be validated
* @param derivedBylist
* Flag which is true when type
* is derived by list otherwise it
* it is derived by extension.
*
* @exception throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @exception InvalidDatatypeValueException
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
return null;
}
/**
* REVISIT
* Compares two Datatype for order
*
* @param o1
* @param o2
* @return
*/
public int compare( String content1, String content2){
return -1;
}
public Hashtable getFacets(){
return null;
}
/**
* Name of base type as a string.
* A Native datatype has the string "native" as its
* base type.
*
* @param base the validator for this type's base type
*/
private void setBasetype(DatatypeValidator base){
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/InvalidDatatypeFacetException.java
Index: InvalidDatatypeFacetException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
public class InvalidDatatypeFacetException extends XMLException {
public InvalidDatatypeFacetException ( ){
super();
}
public InvalidDatatypeFacetException ( String message ) {
super( message );
}
public InvalidDatatypeFacetException ( Exception exception ) {
super( exception );
}
public InvalidDatatypeFacetException ( String message, Exception exception ) {
super( message, exception );
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/NOTATIONDatatypeValidator.java
Index: NOTATIONDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Locale;
/**
* NOTATIONValidator 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: NOTATIONDatatypeValidator.java,v 1.1 2000/06/02 05:36:26 jeffreyr Exp $
*/
public class NOTATIONDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
public NOTATIONDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public NOTATIONDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
}
/**
* Checks that "content" string is valid
* datatype.
* If invalid a Datatype validation exception is thrown.
*
* @param content A string containing the content to be validated
* @param derivedBylist
* Flag which is true when type
* is derived by list otherwise it
* it is derived by extension.
*
* @exception throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @exception InvalidDatatypeValueException
* @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
*/
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
return null;
}
public Hashtable getFacets(){
return null;
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale){
}
/**
* REVISIT
* Compares two Datatype for order
*
* @param o1
* @param o2
* @return
*/
public int compare( String content1, String content2){
return -1;
}
/**
* Name of base type as a string.
* A Native datatype has the string "native" as its
* base type.
*
* @param base the validator for this type's base type
*/
private void setBasetype(DatatypeValidator base){
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/QNameDatatypeValidator.java
Index: QNameDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
import java.text.ParseException;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.utils.regex.RegularExpression;
/**
* QName Validator validates a QName type.
* QName represents XML qualified names. The value
* space of QName is the set of tuples
* {namespace name, local part}, where namespace
* name is a uriReference and local part is an NCName.
* The lexical space of QName is the set of strings
* that match the QName production of [Namespaces in
* XML].
*
* @author Jeffrey Rodriguez
* @version $Id: QNameDatatypeValidator.java,v 1.1 2000/06/02 05:36:26 jeffreyr Exp $
*/
public class QNameDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null;
private boolean fDerivedByList = false;
private int fLength = 0;
private int fMaxLength = 0;
private int fMinLength = 0;
private String fPattern = null;
private Vector fEnumeration = null;
private String fMaxInclusive = null;
private String fMaxExclusive = null;
private String fMinInclusive = null;
private String fMinExclusive = null;
private int fFacetsDefined = 0;
private boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
public QNameDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public QNameDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ){
if ( derivedByList == false) {
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else 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;
fEnumeration = (Vector)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
fMaxInclusive = (String)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
fMaxExclusive = (String)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
fMinInclusive = (String)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
fMinExclusive = (String)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
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." );
}
} else { //derived by list
fDerivedByList = true;
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
fEnumeration = (Vector)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
}
}// End of Facets Setting
}
/**
* validate that a string is a W3C string type
*
* @param content A string containing the content to be validated
* @param list
* @exception throws InvalidDatatypeException if the content is
* not a W3C string type
* @exception InvalidDatatypeValueException
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException
{
StringTokenizer parsedList = null;
if ( fDerivedByList == true ) { //derived by list
parsedList = new StringTokenizer( content );
try {
while ( parsedList.hasMoreTokens() ) {
checkContentList( parsedList.nextToken() );
}
} catch ( NoSuchElementException e ) {
e.printStackTrace();
}
} else { //derived by list
checkContent( content );
}
return null;
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
fLocale = locale;
}
private void checkContent( String content )throws InvalidDatatypeValueException
{
if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
if ( content.length() > fMaxLength ) {
throw new InvalidDatatypeValueException("Value '"+content+
"' with length '"+content.length()+
"' exceeds maximum length of "+fMaxLength+".");
}
}
if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
if ( fEnumeration.contains( content ) == false )
throw new InvalidDatatypeValueException("Value '"+content+"' must be one of "+fEnumeration);
}
if ( isMaxExclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMaxExclusive );
if ( comparisonResult > 0 ) {
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically less than" + fMaxExclusive );
}
}
if ( isMaxInclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMaxInclusive );
if ( comparisonResult >= 0 )
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically less or equal than" + fMaxInclusive );
}
if ( isMinExclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMinExclusive );
if ( comparisonResult < 0 )
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically greater than" + fMinExclusive );
}
if ( isMinInclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMinInclusive );
if ( comparisonResult <= 0 )
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically greater or equal than" + fMinInclusive );
}
if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
RegularExpression regex = new RegularExpression(fPattern, "X" );
if ( regex.matches( content) == false )
throw new InvalidDatatypeValueException("Value'"+content+
"does not match regular expression facet" + fPattern );
}
}
public Hashtable getFacets(){
return null;
}
public int compare( String content1, String content2 ){
return -1;
}
private void checkContentList( String content )throws InvalidDatatypeValueException
{
//Revisit
}
private void setBasetype( DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/RecurringDurationDatatypeValidator.java
Index: RecurringDurationDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.text.ParseException;
import org.apache.xerces.utils.regex.RegularExpression;
import org.apache.xerces.validators.schema.SchemaSymbols;
/**
*
*
*
* @author Ted Leung, George Joseph, Jeffrey Rodriguez,
* @version
*/
public class RecurringDurationDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null; // A Native datatype is null
private String fPattern = null;
private long fMaxInclusive = 0L;
private long fMaxExclusive = 0L;
private long fMinInclusive = 0L;
private long fMinExclusive = 0L;
private long fDuration = 0L;
private long fPeriod = 0L;
private long[] fEnumrecurringduration = null; // Time duration is represented internally as longs
private boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
private int fFacetsDefined = 0;
private boolean fDerivedByList = false;
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
public RecurringDurationDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public RecurringDurationDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
if ( base != null )
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ) {
if ( derivedByList == false ) { // Restriction
//if (fBaseValidator != null)
// if (!fBaseValidator.ensureFacetsAreConsistent(facets))
// throw new InvalidDatatypeFacetException(
// getErrorString( DatatypeMessageProvider.FacetsInconsistent,
// DatatypeMessageProvider.MSG_NONE, null));
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 enumeration 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 = normalizeDuration( value.toCharArray(), 0) ;
} catch ( InvalidDatatypeValueException nfe ){
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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ){
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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ){
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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ) {
throw new InvalidDatatypeFacetException( getErrorString(
DatatypeMessageProvider.IllegalFacetValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { value, key}));
}
} else if (key.equals(SchemaSymbols.ELT_PERIOD )) {
fFacetsDefined += DatatypeValidator.FACET_PERIOD;
} else if (key.equals(SchemaSymbols.ELT_DURATION )) {
fFacetsDefined += DatatypeValidator.FACET_DURATION;
} 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." );
}
if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) {
Vector v = (Vector) facets.get(SchemaSymbols.ELT_ENUMERATION);
if (v != null) {
fEnumrecurringduration = new long[v.size()];
int i = 0;
String value = null;
try {
for (; i < v.size(); i++){
value = (String)v.elementAt(i);
fEnumrecurringduration[i] =
normalizeDuration( value.toCharArray(), 0 );
boundsCheck( fEnumrecurringduration[i] ); // Check against max,min Inclusive, Exclusives
}
} catch (InvalidDatatypeValueException idve) {
throw new InvalidDatatypeFacetException(
getErrorString(DatatypeMessageProvider.InvalidEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { v.elementAt(i)}));
}
}
}
} else { //Derived by List TODO
fDerivedByList = true;
}
}// End Facet definition
}
/**
* validates a String to be a Lexical representation
* of a recurringduration Datatype.
*
* @param content A string containing the content to be validated
* @param state
* @return
* @exception InvalidDatatypeValueException
* If String is does not represent a
* valid recurringduration datatype.
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException{
long normalizedValue;
if ( fDerivedByList == false ) { //derived by constraint
if ( fPattern != null ) {
RegularExpression regex = new RegularExpression(fPattern, "X" );
if ( regex.matches( content) == false )
throw new InvalidDatatypeValueException("Value'"+content+
"does not match regular expression facet" + fPattern );
}
normalizedValue = normalizeDuration(content.toCharArray(), 0 );
try {
boundsCheck( normalizedValue );
} catch( InvalidDatatypeFacetException ex ){
throw new InvalidDatatypeValueException( "Boundary error:" );
}
if ( fEnumrecurringduration != null )
enumCheck( normalizedValue );
} else { //derived by list
}
return null;
}
/**
* set the base type for this datatype
*
* @param base the validator for this type's base type
*
*/
public void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
}
public int compare( String content1, String content2) {
return -1;
}
public Hashtable getFacets(){
return null;
}
// Here start private methods
private static long normalizeDuration(char[] value, int start )
throws InvalidDatatypeValueException
{
int i=0, j=0, k=0, l=0, m=0;
int sepindex = 0;
int index = start;
int lindex = 0;
int endindex = (start+ value.length)-1;
int pendindex = endindex;
final char[] dseps = {'Y','M','D'};
final char[] tseps = {'H','M','S'};
final char[] msc = {'0','0','0'};
final int[] buckets = new int[Calendar.FIELD_COUNT];
for (i=0;i<buckets.length;i++)
buckets[i]=0;
boolean intime = false;
boolean fixed = false;
boolean p1negative = false;
boolean p2negative = false;
boolean p1specified = false;
boolean p2specified = false;
GregorianCalendar cstart = null;
GregorianCalendar cend = null;
//Start phase 1: capture start and/or end instant.
try
{
if (value[index]=='-')
{
p1negative=true;
}
//Look for the forward slash.
int ix = indexOf(value, start, '/');
if (ix > -1 && ix < endindex)
{
if (value[ix+1]=='-')
{
p2negative=true;
}
//If the first term starts with a 'P', pin it for later parsing
if (value[(p1negative?index+1:index)]=='P')
{
if (p1negative)
index++;
p1specified = true;
pendindex = ix-1;
}
//Otherwise parse it for a timeInstant
else
{
cstart = (GregorianCalendar) normalizeInstant(value, index, ix-index);
}
//If the second term starts with a 'P', pin it for later parsing
if (value[(p2negative?(ix+2):(ix+1))]=='P')
{
p2specified=true;
index=(p2negative?(ix+2):(ix+1));
}
//Otherwise parse it for a timeInstant
else
{
ix++;
cend = (GregorianCalendar) normalizeInstant(value,ix,(endindex-ix)+1);
}
}
//Only one term specified.
else
{
index=(p1negative?(start+1):(start));
}
//If both terms are instants, return the millisecond difference
if (cstart != null && cend != null)
{
return((cend.getTime().getTime() - cstart.getTime().getTime()));
}
//If both terms are 'P', error.
if (p1specified && p2specified)
throw new ParseException("Period cannot be expressed as 2 durations.", 0);
if (p1specified && value[index] != 'P')
{
throw new ParseException("Invalid start character for recurringduration:"+value[index], index);
}
if (p2specified && value[index] != 'P')
{
throw new ParseException("Invalid start character for recurringduration:"+value[index], index);
}
} catch (Exception e)
{
throw new InvalidDatatypeValueException(e.toString());
}
//Second phase....parse 'P' term
try
{
lindex=index+1;
for (i=index+1;i<=pendindex;i++)
{
//Accumulate digits.
if (Character.isDigit(value[i]) || value[i]=='.')
{
if (value[i]=='.')fixed=true;
continue;
}
if (value[i]=='T')
{
intime=true;
sepindex=0;
lindex=i+1;
continue;
}
//If you get a separator, it must be appropriate for the section.
sepindex = indexOf((intime?tseps:dseps), sepindex, value[i]);
if (sepindex == -1)
throw new ParseException("Illegal or misplaced separator.", i);
sepindex++;
//Fractional digits are allowed only for seconds.
if (fixed && value[i]!='S')
throw new ParseException("Fractional digits allowed only for 'seconds'.", i);
j=0;
switch (value[i])
{
case('Y'):
{
if (intime)throw new ParseException("Year must be specified before 'T' separator.", i);
buckets[Calendar.YEAR]= parseInt(value, lindex, i-lindex);
break;
}
case('D'):
{
if (intime)throw new ParseException("Days must be specified before 'T' separator.", i);
buckets[Calendar.DAY_OF_MONTH]= parseInt(value, lindex, i-lindex);
break;
}
case('H'):
{
if (!intime)throw new ParseException("Hours must be specified after 'T' separator.", i);
buckets[Calendar.HOUR_OF_DAY]= parseInt(value, lindex, i-lindex);
break;
}
case('M'):
{
buckets[(intime?Calendar.MINUTE:Calendar.MONTH)]= parseInt(value, lindex, i-lindex);
break;
}
case('S'):
{
if (!intime)throw new ParseException("Seconds must be specified after 'T' separator.", i);
if (!fixed)buckets[Calendar.SECOND]= parseInt(value, lindex, i-lindex);
else
{
int ps = indexOf(value, lindex, '.');
buckets[Calendar.SECOND]= parseInt(value, lindex, ps-lindex);
ps++;k=0;
while ((ps <= pendindex) && (k<3) && Character.isDigit(value[ps]))
msc[k++]=value[ps++];
buckets[Calendar.MILLISECOND]= parseInt(msc, 0, 3);
fixed=false;
}
break;
}
default:
{
throw new ParseException("Illegal 'picture' character: "+value[i], i);
}
}
lindex=i+1;
}
} catch (Exception e)
{
throw new InvalidDatatypeValueException(e.toString());
}
//Third phase, make the calculations.
try
{
//Roll the start calendar forward and return difference.
if (cstart !=null)
{
long st = cstart.getTime().getTime();
for (k=0;k<buckets.length;k++)
if (buckets[k]!=0)cstart.add(k, (p2negative?-buckets[k]:buckets[k]));
long ms = cstart.getTime().getTime();
return((ms-st));
}
//Roll the end calendar backward and return difference.
if (cend !=null)
{
long st = cend.getTime().getTime();
for (k=0;k<buckets.length;k++)
if (buckets[k]>0) cend.add(k, (p1negative?buckets[k]:-buckets[k]));
long ms = cend.getTime().getTime();
return((ms-st));
}
//Otherwise roll the relative specification forward and reverse the sing as appropriate.
long r=(((long)(( (buckets[Calendar.YEAR]*31104000L)+
(buckets[Calendar.MONTH]*2592000L)+
(buckets[Calendar.DAY_OF_MONTH]*86400L)+
(buckets[Calendar.HOUR_OF_DAY]*3600L)+
(buckets[Calendar.MINUTE]*60L)+
(buckets[Calendar.SECOND]))*1000L)+
(buckets[Calendar.MILLISECOND])));
return((p1negative?-r:r));
} catch (Exception e)
{
throw new InvalidDatatypeValueException(e.toString());
}
}
public static Calendar normalizeInstant(char[] value, int start,
int length) throws InvalidDatatypeValueException
{
boolean negative=false;
boolean tznegative=false;
int tzoffset=0;
int tzhh=0,tzmm=0;
int i=start,j=0,k=0,l=0,m=0;
final char[]ms={'0','0','0'};
final Calendar cal = new GregorianCalendar();
final int endindex = (start+length)-1;
try
{
if (length < 16) throw new ParseException("Value is too short.",0);
cal.clear();
cal.setLenient(false);
// If there's a leading sign, set the appropriate Era.
if (value[i]=='-'||value[i]=='+')
{
cal.set(Calendar.ERA, (value[i]=='-'?GregorianCalendar.BC:GregorianCalendar.AD));
i++;
}
// Grab the year (might be > 9999), month, day, hour and minute fields
j=indexOf(value,i,'-',i+5);
if (j==-1 || j>endindex)throw new ParseException("Year separator is missing or misplaced.", i);
cal.set(Calendar.YEAR, parseInt(value,i,j-i));
i=j+1;
cal.set(Calendar.MONTH, parseInt(value,i,2)-1);
i+=2;
if (value[i]!='-')throw new ParseException("Month separator is missing or misplaced.",i);
cal.set(Calendar.DAY_OF_MONTH, parseInt(value,i+1,2));
i+=3;
if (value[i]!='T')throw new ParseException("Time separator is missing or misplaced.",i);
cal.set(Calendar.HOUR_OF_DAY, parseInt(value,i+1,2));
i+=3;
if (value[i]!=':')throw new ParseException("Hour separator is missing or misplaced.",i);
cal.set(Calendar.MINUTE, parseInt(value,i+1,2));
i+=3;
// Seconds are optional
if ((endindex-i)>1 && (value[i]==':'))
{
cal.set(Calendar.SECOND, parseInt(value,i+1,2));
i+=3;
// Grab optional fractional seconds to 3 decimal places.
if (i<endindex && value[i]=='.')
{
i++;k=0;
while ((i <= endindex) && (k<3) && Character.isDigit(value[i]))
ms[k++]=value[i++];
cal.set(Calendar.MILLISECOND, parseInt(ms,0,3));
}
// Eat any remaining digits.
while (i<=endindex && Character.isDigit(value[i])) i++;
}
// Check for timezone.
if (i<=endindex)
{
if (value[i]=='Z')
{
cal.set(Calendar.ZONE_OFFSET, 0);
}
// else if ((endindex-i)==2 || (endindex-i)==5)
else if (value[i]=='-' || value[i]=='+')
{
tznegative = (value[i]=='-');
tzhh=parseInt(value,i+1,2);
if ((endindex-i)==5)
{
if (value[i+3] != ':')throw new ParseException("time zone must be 'hh:mm'.",i);
tzmm=parseInt(value,i+4,2);
}
tzoffset=((tzhh*3600000)+(tzmm*60000));
cal.set(Calendar.ZONE_OFFSET, (tznegative?-tzoffset:tzoffset));
} else throw new ParseException("Unrecognized time zone.",i);
}
return(cal);
} catch (Exception e)
{
e.printStackTrace();
throw new InvalidDatatypeValueException("Unable to parse timeInstant "+e.toString());
}
}
/*
* check that a facet is in range, assumes that facets are compatible -- compatibility ensured by setFacets
*/
private void boundsCheck(long f) throws InvalidDatatypeFacetException {
boolean inUpperBound = false;
boolean inLowerBound = false;
if ( isMaxInclusiveDefined ) {
inUpperBound = ( f <= fMaxInclusive );
} else if ( isMaxExclusiveDefined ) {
inUpperBound = ( f < fMaxExclusive );
}
if ( isMinInclusiveDefined ) {
inLowerBound = ( f >= fMinInclusive );
} else if ( isMinExclusiveDefined ) {
inLowerBound = ( f > fMinExclusive );
}
if ( inUpperBound == false || inLowerBound == false ) { // within bounds ?
throw new InvalidDatatypeFacetException(
getErrorString(DatatypeMessageProvider.OutOfBounds,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Long(f) }));
}
}
private void enumCheck(long d) throws InvalidDatatypeValueException {
for (int i = 0; i < this.fEnumrecurringduration.length; i++) {
if (d == fEnumrecurringduration[i]) return;
}
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotAnEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Long(d )}));
}
private String getErrorString(int major, int minor, Object args[]) {
try {
return fMessageProvider.createMessage(fLocale, major, minor, args);
} catch (Exception e) {
return "Illegal Errorcode "+minor;
}
}
private static final int indexOf(char[] value, int start, char s)
{
return(indexOf(value,start,s,value.length-1));
}
private static final int indexOf(char[] value, int start, char s, int max)
{
for (int i=start;i<=max;i++)if (value[i]==s) return(i);
return(-1);
}
private static final int indexOneOf(char[] value, int start, String s)
{
return(indexOneOf(value,start,s,value.length-1));
}
private static final int indexOneOf(char[] value, int start, String s, int max)
{
for (int i=start;i<max;i++)
for (int j=0;j<s.length();j++) if (value[i] == s.charAt(j))return(i);
return(-1);
}
// parseInt is a copy of the Integer.parseInt method, modified to accept
// a character array.
private static final int parseInt(char[] s, int start, int length) throws NumberFormatException
{
if (s == null) throw new NumberFormatException("null");
int radix=10;
int result = 0;
boolean negative = false;
int i= start;
int limit;
int multmin;
int digit=0;
if (length <= 0) throw new NumberFormatException(new String(s,start,length));
if (s[i] == '-')
{
negative = true;
limit = Integer.MIN_VALUE;
i++;
} else if (s[i]=='+')
{
negative = false;
limit = -Integer.MAX_VALUE;
i++;
} else
{
limit = -Integer.MAX_VALUE;
}
multmin = limit / radix;
if (i < (start+length))
{
digit = Character.digit(s[i++],radix);
if (digit < 0) throw new NumberFormatException(new String(s,start,length));
else result = -digit;
}
while (i < (start+length))
{
digit = Character.digit(s[i++],radix);
if (digit < 0) throw new NumberFormatException(new String(s,start,length));
if (result < multmin) throw new NumberFormatException(new String(s,start,length));
result *= radix;
if (result < limit + digit) throw new NumberFormatException(new String(s,start,length));
result -= digit;
}
if (negative)
{
if (i > 1) return result;
else throw new NumberFormatException(new String(s,start,length));
}
return -result;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/StringDatatypeValidator.java
Index: StringDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
import java.text.Collator;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import org.apache.xerces.validators.schema.SchemaSymbols;
import org.apache.xerces.utils.regex.RegularExpression;
/**
* StringValidator validates that XML content is a W3C string type.
* @author Ted Leung
* @author Kito D. Mann, Virtua Communications Corp.
* @author Jeffrey Rodriguez
*/
public class StringDatatypeValidator extends AbstractDatatypeValidator{
private Locale fLocale = null;
DatatypeValidator fBaseValidator = null; // Native datatypes have null
private int fLength = 0;
private int fMaxLength = 0;
private int fMinLength = 0;
private String fPattern = null;
private Vector fEnumeration = null;
private String fMaxInclusive = null;
private String fMaxExclusive = null;
private String fMinInclusive = null;
private String fMinExclusive = null;
private int fFacetsDefined = 0;
private boolean fDerivedByList = false;//default
private boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
public StringDatatypeValidator () throws InvalidDatatypeFacetException{
this( null, null, false ); // Native, No Facets defined, Restriction
}
public StringDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ){
if ( derivedByList == false) {
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else 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;
fEnumeration = (Vector)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MAXINCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
fMaxInclusive = (String)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MAXEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MAXEXCLUSIVE;
fMaxExclusive = (String)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MININCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
fMinInclusive = (String)facets.get(key);
} else if (key.equals(SchemaSymbols.ELT_MINEXCLUSIVE)) {
fFacetsDefined += DatatypeValidator.FACET_MININCLUSIVE;
fMinExclusive = (String)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
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." );
}
} else { //derived by list
fDerivedByList = true;
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
fEnumeration = (Vector)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
}
}// End of Facets Setting
}
/**
* validate that a string is a W3C string type
*
* @param content A string containing the content to be validated
* @param list
* @exception throws InvalidDatatypeException if the content is
* not a W3C string type
* @exception InvalidDatatypeValueException
*/
public Object validate(String content, Object state) throws InvalidDatatypeValueException
{
if ( fFacetsDefined == 0 )// No Facets to validate
return null;
if ( fDerivedByList == false ) {
checkContent( content );
} else { //derived by list
StringTokenizer parsedList = new StringTokenizer( content );
try {
while ( parsedList.hasMoreTokens() ) {
checkContentList( parsedList.nextToken() );
}
} catch ( NoSuchElementException e ) {
e.printStackTrace();
}
}
return null;
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
fLocale = locale;
}
/**
*
* @return A Hashtable containing the facets
* for this datatype.
*/
public Hashtable getFacets(){
return null;
}
private void checkContent( String content )throws InvalidDatatypeValueException
{
if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
if ( content.length() > fMaxLength ) {
throw new InvalidDatatypeValueException("Value '"+content+
"' with length '"+content.length()+
"' exceeds maximum length of "+fMaxLength+".");
}
}
if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
if ( fEnumeration.contains( content ) == false )
throw new InvalidDatatypeValueException("Value '"+content+"' must be one of "+fEnumeration);
}
if ( isMaxExclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMaxExclusive );
if ( comparisonResult > 0 ) {
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically less than" + fMaxExclusive );
}
}
if ( isMaxInclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMaxInclusive );
if ( comparisonResult >= 0 )
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically less or equal than" + fMaxInclusive );
}
if ( isMinExclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMinExclusive );
if ( comparisonResult < 0 )
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically greater than" + fMinExclusive );
}
if ( isMinInclusiveDefined == true ) {
int comparisonResult;
comparisonResult = compare( content, fMinInclusive );
if ( comparisonResult <= 0 )
throw new InvalidDatatypeValueException( "Value '"+content+ "' must be" +
"lexicographically greater or equal than" + fMinInclusive );
}
if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
RegularExpression regex = new RegularExpression(fPattern, "X" );
if ( regex.matches( content) == false )
throw new InvalidDatatypeValueException("Value'"+content+
"does not match regular expression facet" + fPattern );
}
}
public int compare( String content, String facetValue ){
Locale loc = Locale.getDefault();
Collator collator = Collator.getInstance( loc );
return collator.compare( content, facetValue );
}
// Private methods
private void checkContentList( String content )throws InvalidDatatypeValueException
{
//Revisit
}
private void setBasetype( DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/TimeDurationDatatypeValidator.java
Index: TimeDurationDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.text.ParseException;
import org.apache.xerces.utils.regex.RegularExpression;
import org.apache.xerces.validators.schema.SchemaSymbols;
/**
*
* TimeDurationValidator validates that XML content is a W3C timeDuration.
*
* @author Ted Leung, George Joseph
* @version
*/
public class TimeDurationDatatypeValidator extends AbstractDatatypeValidator {
private Locale fLocale = null;
private DatatypeValidator fBaseValidator = null; // A Native datatype is null
private String fPattern = null;
private long fMaxInclusive = 0L;
private long fMaxExclusive = 0L;
private long fMinInclusive = 0L;
private long fMinExclusive = 0L;
private long fDuration = 0L;
private long fPeriod = 0L;
private boolean isMaxExclusiveDefined = false;
private boolean isMaxInclusiveDefined = false;
private boolean isMinExclusiveDefined = false;
private boolean isMinInclusiveDefined = false;
private int fFacetsDefined = 0;
private boolean fDerivedByList = false;
private long[] fEnumTimeDuration = null; // Time duration is represented internally as longs
private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
public TimeDurationDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
public TimeDurationDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
if ( base != null )
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ) {
if ( derivedByList == false ) { // Restriction
if (fBaseValidator != null)
//if (!fBaseValidator.ensureFacetsAreConsistent(facets))
// throw new InvalidDatatypeFacetException(
// getErrorString( DatatypeMessageProvider.FacetsInconsistent,
// DatatypeMessageProvider.MSG_NONE, null));
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 enumeration 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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ){
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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ){
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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ){
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 = normalizeDuration( value.toCharArray(), 0 );
} catch ( InvalidDatatypeValueException nfe ) {
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." );
}
if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) {
Vector v = (Vector) facets.get(SchemaSymbols.ELT_ENUMERATION);
if (v != null) {
fEnumTimeDuration = new long[v.size()];
int i = 0;
String value = null;
try {
for (; i < v.size(); i++){
value = (String)v.elementAt(i);
fEnumTimeDuration[i] =
normalizeDuration( value.toCharArray(),0 );
boundsCheck(fEnumTimeDuration[i]); // Check against max,min Inclusive, Exclusives
}
} catch (InvalidDatatypeValueException idve) {
throw new InvalidDatatypeFacetException(
getErrorString(DatatypeMessageProvider.InvalidEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { v.elementAt(i)}));
}
}
}
} else { //Derived by List TODO
}
}// End Facet definition
}
/**
* validates a String to be a Lexical representation
* of a TimeDuration Datatype.
*
* @param content A string containing the content to be validated
* @param state
* @return
* @exception InvalidDatatypeValueException
* If String is does not represent a
* valid TimeDuration datatype.
*/
public Object validate(String content, Object state)
throws InvalidDatatypeValueException{
long normalizedValue;
if ( fDerivedByList == false ) { //derived by constraint
if ( fPattern != null ) {
RegularExpression regex = new RegularExpression(fPattern, "X" );
if ( regex.matches( content) == false )
throw new InvalidDatatypeValueException("Value'"+content+
"does not match regular expression facet" + fPattern );
}
normalizedValue = normalizeDuration(content.toCharArray(), 0 );
try {
boundsCheck( normalizedValue );
} catch( InvalidDatatypeFacetException ex ){
throw new InvalidDatatypeValueException( "Boundary Exception" );
}
if( fEnumTimeDuration != null )
enumCheck( normalizedValue );
} else { //derived by list
}
return null;
}
/**
* set the base type for this datatype
*
* @param base the validator for this type's base type
*
*/
public void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
/**
* set the locate to be used for error messages
*/
public void setLocale(Locale locale) {
}
public int compare( String content1, String content2) {
return -1;
}
public Hashtable getFacets(){
return null;
}
public static long normalizeDuration(char[] value, int start )
throws InvalidDatatypeValueException
{
int i=0, j=0, k=0, l=0, m=0;
int sepindex = 0;
int index = start;
int lindex = 0;
int endindex = (start+ value.length)-1;
int pendindex = endindex;
final char[] dseps = {'Y','M','D'};
final char[] tseps = {'H','M','S'};
final char[] msc = {'0','0','0'};
final int[] buckets = new int[Calendar.FIELD_COUNT];
for (i=0;i<buckets.length;i++)
buckets[i]=0;
boolean intime = false;
boolean fixed = false;
boolean p1negative = false;
boolean p2negative = false;
boolean p1specified = false;
boolean p2specified = false;
GregorianCalendar cstart = null;
GregorianCalendar cend = null;
//Start phase 1: capture start and/or end instant.
try
{
if (value[index]=='-')
{
p1negative=true;
}
//Look for the forward slash.
int ix = indexOf(value, start, '/');
if (ix > -1 && ix < endindex)
{
if (value[ix+1]=='-')
{
p2negative=true;
}
//If the first term starts with a 'P', pin it for later parsing
if (value[(p1negative?index+1:index)]=='P')
{
if (p1negative)
index++;
p1specified = true;
pendindex = ix-1;
}
//Otherwise parse it for a timeInstant
else
{
cstart = (GregorianCalendar) normalizeInstant(value, index, ix-index);
}
//If the second term starts with a 'P', pin it for later parsing
if (value[(p2negative?(ix+2):(ix+1))]=='P')
{
p2specified=true;
index=(p2negative?(ix+2):(ix+1));
}
//Otherwise parse it for a timeInstant
else
{
ix++;
cend = (GregorianCalendar) normalizeInstant(value,ix,(endindex-ix)+1);
}
}
//Only one term specified.
else
{
index=(p1negative?(start+1):(start));
}
//If both terms are instants, return the millisecond difference
if (cstart != null && cend != null)
{
return((cend.getTime().getTime() - cstart.getTime().getTime()));
}
//If both terms are 'P', error.
if (p1specified && p2specified)
throw new ParseException("Period cannot be expressed as 2 durations.", 0);
if (p1specified && value[index] != 'P')
{
throw new ParseException("Invalid start character for timeDuration:"+value[index], index);
}
if (p2specified && value[index] != 'P')
{
throw new ParseException("Invalid start character for timeDuration:"+value[index], index);
}
} catch (Exception e)
{
throw new InvalidDatatypeValueException(e.toString());
}
//Second phase....parse 'P' term
try
{
lindex=index+1;
for (i=index+1;i<=pendindex;i++)
{
//Accumulate digits.
if (Character.isDigit(value[i]) || value[i]=='.')
{
if (value[i]=='.')fixed=true;
continue;
}
if (value[i]=='T')
{
intime=true;
sepindex=0;
lindex=i+1;
continue;
}
//If you get a separator, it must be appropriate for the section.
sepindex = indexOf((intime?tseps:dseps), sepindex, value[i]);
if (sepindex == -1)
throw new ParseException("Illegal or misplaced separator.", i);
sepindex++;
//Fractional digits are allowed only for seconds.
if (fixed && value[i]!='S')
throw new ParseException("Fractional digits allowed only for 'seconds'.", i);
j=0;
switch (value[i])
{
case('Y'):
{
if (intime)throw new ParseException("Year must be specified before 'T' separator.", i);
buckets[Calendar.YEAR]= parseInt(value, lindex, i-lindex);
break;
}
case('D'):
{
if (intime)throw new ParseException("Days must be specified before 'T' separator.", i);
buckets[Calendar.DAY_OF_MONTH]= parseInt(value, lindex, i-lindex);
break;
}
case('H'):
{
if (!intime)throw new ParseException("Hours must be specified after 'T' separator.", i);
buckets[Calendar.HOUR_OF_DAY]= parseInt(value, lindex, i-lindex);
break;
}
case('M'):
{
buckets[(intime?Calendar.MINUTE:Calendar.MONTH)]= parseInt(value, lindex, i-lindex);
break;
}
case('S'):
{
if (!intime)throw new ParseException("Seconds must be specified after 'T' separator.", i);
if (!fixed)buckets[Calendar.SECOND]= parseInt(value, lindex, i-lindex);
else
{
int ps = indexOf(value, lindex, '.');
buckets[Calendar.SECOND]= parseInt(value, lindex, ps-lindex);
ps++;k=0;
while ((ps <= pendindex) && (k<3) && Character.isDigit(value[ps]))
msc[k++]=value[ps++];
buckets[Calendar.MILLISECOND]= parseInt(msc, 0, 3);
fixed=false;
}
break;
}
default:
{
throw new ParseException("Illegal 'picture' character: "+value[i], i);
}
}
lindex=i+1;
}
} catch (Exception e)
{
throw new InvalidDatatypeValueException(e.toString());
}
//Third phase, make the calculations.
try
{
//Roll the start calendar forward and return difference.
if (cstart !=null)
{
long st = cstart.getTime().getTime();
for (k=0;k<buckets.length;k++)
if (buckets[k]!=0)cstart.add(k, (p2negative?-buckets[k]:buckets[k]));
long ms = cstart.getTime().getTime();
return((ms-st));
}
//Roll the end calendar backward and return difference.
if (cend !=null)
{
long st = cend.getTime().getTime();
for (k=0;k<buckets.length;k++)
if (buckets[k]>0) cend.add(k, (p1negative?buckets[k]:-buckets[k]));
long ms = cend.getTime().getTime();
return((ms-st));
}
//Otherwise roll the relative specification forward and reverse the sing as appropriate.
long r=(((long)(( (buckets[Calendar.YEAR]*31104000L)+
(buckets[Calendar.MONTH]*2592000L)+
(buckets[Calendar.DAY_OF_MONTH]*86400L)+
(buckets[Calendar.HOUR_OF_DAY]*3600L)+
(buckets[Calendar.MINUTE]*60L)+
(buckets[Calendar.SECOND]))*1000L)+
(buckets[Calendar.MILLISECOND])));
return((p1negative?-r:r));
} catch (Exception e)
{
throw new InvalidDatatypeValueException(e.toString());
}
}
public static Calendar normalizeInstant(char[] value, int start,
int length) throws InvalidDatatypeValueException
{
boolean negative=false;
boolean tznegative=false;
int tzoffset=0;
int tzhh=0,tzmm=0;
int i=start,j=0,k=0,l=0,m=0;
final char[]ms={'0','0','0'};
final Calendar cal = new GregorianCalendar();
final int endindex = (start+length)-1;
try
{
if (length < 16) throw new ParseException("Value is too short.",0);
cal.clear();
cal.setLenient(false);
// If there's a leading sign, set the appropriate Era.
if (value[i]=='-'||value[i]=='+')
{
cal.set(Calendar.ERA, (value[i]=='-'?GregorianCalendar.BC:GregorianCalendar.AD));
i++;
}
// Grab the year (might be > 9999), month, day, hour and minute fields
j=indexOf(value,i,'-',i+5);
if (j==-1 || j>endindex)throw new ParseException("Year separator is missing or misplaced.", i);
cal.set(Calendar.YEAR, parseInt(value,i,j-i));
i=j+1;
cal.set(Calendar.MONTH, parseInt(value,i,2)-1);
i+=2;
if (value[i]!='-')throw new ParseException("Month separator is missing or misplaced.",i);
cal.set(Calendar.DAY_OF_MONTH, parseInt(value,i+1,2));
i+=3;
if (value[i]!='T')throw new ParseException("Time separator is missing or misplaced.",i);
cal.set(Calendar.HOUR_OF_DAY, parseInt(value,i+1,2));
i+=3;
if (value[i]!=':')throw new ParseException("Hour separator is missing or misplaced.",i);
cal.set(Calendar.MINUTE, parseInt(value,i+1,2));
i+=3;
// Seconds are optional
if ((endindex-i)>1 && (value[i]==':'))
{
cal.set(Calendar.SECOND, parseInt(value,i+1,2));
i+=3;
// Grab optional fractional seconds to 3 decimal places.
if (i<endindex && value[i]=='.')
{
i++;k=0;
while ((i <= endindex) && (k<3) && Character.isDigit(value[i]))
ms[k++]=value[i++];
cal.set(Calendar.MILLISECOND, parseInt(ms,0,3));
}
// Eat any remaining digits.
while (i<=endindex && Character.isDigit(value[i])) i++;
}
// Check for timezone.
if (i<=endindex)
{
if (value[i]=='Z')
{
cal.set(Calendar.ZONE_OFFSET, 0);
}
// else if ((endindex-i)==2 || (endindex-i)==5)
else if (value[i]=='-' || value[i]=='+')
{
tznegative = (value[i]=='-');
tzhh=parseInt(value,i+1,2);
if ((endindex-i)==5)
{
if (value[i+3] != ':')throw new ParseException("time zone must be 'hh:mm'.",i);
tzmm=parseInt(value,i+4,2);
}
tzoffset=((tzhh*3600000)+(tzmm*60000));
cal.set(Calendar.ZONE_OFFSET, (tznegative?-tzoffset:tzoffset));
} else throw new ParseException("Unrecognized time zone.",i);
}
return(cal);
} catch (Exception e)
{
e.printStackTrace();
throw new InvalidDatatypeValueException("Unable to parse timeInstant "+e.toString());
}
}
/*
* check that a facet is in range, assumes that facets are compatible -- compatibility ensured by setFacets
*/
private void boundsCheck(long f) throws InvalidDatatypeFacetException {
boolean inUpperBound = false;
boolean inLowerBound = false;
if ( isMaxInclusiveDefined ) {
inUpperBound = ( f <= fMaxInclusive );
} else if ( isMaxExclusiveDefined ) {
inUpperBound = ( f < fMaxExclusive );
}
if ( isMinInclusiveDefined ) {
inLowerBound = ( f >= fMinInclusive );
} else if ( isMinExclusiveDefined ) {
inLowerBound = ( f > fMinExclusive );
}
if ( inUpperBound == false || inLowerBound == false ) { // within bounds ?
throw new InvalidDatatypeFacetException(
getErrorString(DatatypeMessageProvider.OutOfBounds,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Long(f)}));
}
}
private void enumCheck(long d) throws InvalidDatatypeValueException {
for (int i = 0; i < this.fEnumTimeDuration.length; i++) {
if (d == fEnumTimeDuration[i]) return;
}
throw new InvalidDatatypeValueException(
getErrorString(DatatypeMessageProvider.NotAnEnumValue,
DatatypeMessageProvider.MSG_NONE,
new Object [] { new Long( d ) }));
}
private String getErrorString(int major, int minor, Object args[]) {
try {
return fMessageProvider.createMessage(fLocale, major, minor, args);
} catch (Exception e) {
return "Illegal Errorcode "+minor;
}
}
private static final int indexOf(char[] value, int start, char s)
{
return(indexOf(value,start,s,value.length-1));
}
private static final int indexOf(char[] value, int start, char s, int max)
{
for (int i=start;i<=max;i++)if (value[i]==s) return(i);
return(-1);
}
private static final int indexOneOf(char[] value, int start, String s)
{
return(indexOneOf(value,start,s,value.length-1));
}
private static final int indexOneOf(char[] value, int start, String s, int max)
{
for (int i=start;i<max;i++)
for (int j=0;j<s.length();j++) if (value[i] == s.charAt(j))return(i);
return(-1);
}
// parseInt is a copy of the Integer.parseInt method, modified to accept
// a character array.
private static final int parseInt(char[] s, int start, int length) throws NumberFormatException
{
if (s == null) throw new NumberFormatException("null");
int radix=10;
int result = 0;
boolean negative = false;
int i= start;
int limit;
int multmin;
int digit=0;
if (length <= 0) throw new NumberFormatException(new String(s,start,length));
if (s[i] == '-')
{
negative = true;
limit = Integer.MIN_VALUE;
i++;
} else if (s[i]=='+')
{
negative = false;
limit = -Integer.MAX_VALUE;
i++;
} else
{
limit = -Integer.MAX_VALUE;
}
multmin = limit / radix;
if (i < (start+length))
{
digit = Character.digit(s[i++],radix);
if (digit < 0) throw new NumberFormatException(new String(s,start,length));
else result = -digit;
}
while (i < (start+length))
{
digit = Character.digit(s[i++],radix);
if (digit < 0) throw new NumberFormatException(new String(s,start,length));
if (result < multmin) throw new NumberFormatException(new String(s,start,length));
result *= radix;
if (result < limit + digit) throw new NumberFormatException(new String(s,start,length));
result -= digit;
}
if (negative)
{
if (i > 1) return result;
else throw new NumberFormatException(new String(s,start,length));
}
return -result;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/URIReferenceDatatypeValidator.java
Index: URIReferenceDatatypeValidator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import org.apache.xerces.validators.schema.SchemaSymbols;
/**
* URIValidator validates that XML content is a W3C uri type,
* according to RFC 2396
*
* @author Ted Leung
* @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.1 2000/06/02 05:36:26 jeffreyr Exp $
*/
public class URIReferenceDatatypeValidator extends AbstractDatatypeValidator {
private DatatypeValidator fBaseValidator = null;
private boolean fDerivedByList = false;
private int fLength = 0;
private int fMaxLength = 0;
private int fMinLength = 0;
private String fPattern = null;
private Vector fEnumeration = null;
private int fFacetsDefined = 0;
public URIReferenceDatatypeValidator () throws InvalidDatatypeFacetException{
this ( null, null, false ); // Native, No Facets defined, Restriction
}
public URIReferenceDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
setBasetype( base ); // Set base type
// Set Facets if any defined
if ( facets != null ){
if ( derivedByList == false) {
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else 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;
fEnumeration = (Vector)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
} else { //derived by list
fDerivedByList = true;
for (Enumeration e = facets.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if ( key.equals(SchemaSymbols.ELT_LENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_LENGTH;
String lengthValue = (String)facets.get(key);
try {
fLength = Integer.parseInt( lengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' is invalid.");
}
if ( fLength < 0 )
throw new InvalidDatatypeFacetException("Length value '"+lengthValue+"' must be a nonNegativeInteger.");
} else if (key.equals(SchemaSymbols.ELT_MINLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MINLENGTH;
String minLengthValue = (String)facets.get(key);
try {
fMinLength = Integer.parseInt( minLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+minLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_MAXLENGTH) ) {
fFacetsDefined += DatatypeValidator.FACET_MAXLENGTH;
String maxLengthValue = (String)facets.get(key);
try {
fMaxLength = Integer.parseInt( maxLengthValue );
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeFacetException("maxLength value '"+maxLengthValue+"' is invalid.");
}
} else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
fEnumeration = (Vector)facets.get(key);
} else {
throw new InvalidDatatypeFacetException();
}
}
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." );
} else if (((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH ) != 0 ) ) {
throw new InvalidDatatypeFacetException(
"It is an error for both length and minLength to be members of facets." );
}
}
if ( ( (fFacetsDefined & ( DatatypeValidator.FACET_MINLENGTH |
DatatypeValidator.FACET_MAXLENGTH) ) != 0 ) ) {
if ( fMinLength < fMaxLength ) {
throw new InvalidDatatypeFacetException( "Value of minLength = " + fMinLength +
"must be greater that the value of maxLength" + fMaxLength );
}
}
}
}// End of Facets Setting
}
/**
* Validates content to conform to a URIReference
* definition and to conform to the facets allowed
* for this datatype.
*
* @param content
* @param state
* @return
* @exception InvalidDatatypeValueException
*/
public Object validate(String content, Object state)
throws InvalidDatatypeValueException
{
StringTokenizer parsedList = null;
if ( fDerivedByList == true ) { //derived by list
parsedList = new StringTokenizer( content );
try {
while ( parsedList.hasMoreTokens() ) {
//checkContentList( parsedList.nextToken() ); TODO
}
} catch ( NoSuchElementException e ) {
e.printStackTrace();
}
} else { //derived by list
// checkContent( content ); TODO
}
return null;
}
/**
* Compares two URIReferences for equality.
* This is not really well defined.
*
* @param content1
* @param content2
* @return
*/
public int compare( String content1, String content2){
return 0;
}
/**
*
* @return Returns a Hashtable containing the facet information
* for this datatype.
*/
public Hashtable getFacets(){
return null;
}
// Private methods starts here
private void setBasetype(DatatypeValidator base) {
fBaseValidator = base;
}
}
1.1 xml-xerces/java/src/org/apache/xerces/validators/datatype/XMLException.java
Index: XMLException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.validators.datatype;
public class XMLException extends Exception {
public XMLException ( ) {
}
public XMLException ( String message ) {
}
public XMLException ( Exception exception ) {
}
public XMLException ( String message, Exception exception ) {
}
public Exception getException ( ) {
return null;
}
}