diff options
Diffstat (limited to 'libjava/classpath/gnu/xml/validation/datatype')
68 files changed, 8027 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/xml/validation/datatype/Annotation.java b/libjava/classpath/gnu/xml/validation/datatype/Annotation.java new file mode 100644 index 000000000..6438e2ebb --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/Annotation.java @@ -0,0 +1,60 @@ +/* Annotation.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * A schema component annotation. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class Annotation +{ + + public final String documentation; + + public Annotation(String documentation) + { + this.documentation = documentation; + } + + public String toString() + { + return documentation; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/AnySimpleType.java b/libjava/classpath/gnu/xml/validation/datatype/AnySimpleType.java new file mode 100644 index 000000000..36fb98daa --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/AnySimpleType.java @@ -0,0 +1,58 @@ +/* AnySimpleType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Set; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +final class AnySimpleType + extends SimpleType +{ + + AnySimpleType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "anySimpleType"), + ANY, /* variety */ + (Set) null, /* facets */ + 0, /* fundametalFacets */ + (SimpleType) Type.ANY_TYPE, /* baseType */ + null); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/AnyType.java b/libjava/classpath/gnu/xml/validation/datatype/AnyType.java new file mode 100644 index 000000000..2a3f116dd --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/AnyType.java @@ -0,0 +1,57 @@ +/* AnyType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +final class AnyType + extends SimpleType +{ + + AnyType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "anyType"), + ANY, /* variety */ + null, /* facets */ + 0, /* fundamentalFacets */ + null, /* baseType */ + null); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/AnyURIType.java b/libjava/classpath/gnu/xml/validation/datatype/AnyURIType.java new file mode 100644 index 000000000..ef409b99c --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/AnyURIType.java @@ -0,0 +1,93 @@ +/* AnyURIType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.net.URI; +import java.net.URISyntaxException; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema anyURI type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class AnyURIType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + AnyURIType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "anyURI"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + try + { + new URI(value); + } + catch (URISyntaxException e) + { + DatatypeException e2 = new DatatypeException(e.getIndex(), + e.getReason()); + e2.initCause(e); + throw e2; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/AtomicSimpleType.java b/libjava/classpath/gnu/xml/validation/datatype/AtomicSimpleType.java new file mode 100644 index 000000000..38528eecf --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/AtomicSimpleType.java @@ -0,0 +1,77 @@ +/* AtomicSimpleType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Set; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * An XML Schema atomic simple type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class AtomicSimpleType + extends SimpleType +{ + + public AtomicSimpleType(QName name, + Set facets, + int fundamentalFacets, + SimpleType baseType, + Annotation annotation) + { + super(name, ATOMIC, facets, fundamentalFacets, baseType, annotation); + } + + // Only for use by built-in types + AtomicSimpleType(QName name, SimpleType baseType) + { + super(name, ATOMIC, null, 0, baseType, null); + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (baseType != null) + baseType.checkValid(value, context); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/Base64BinaryType.java b/libjava/classpath/gnu/xml/validation/datatype/Base64BinaryType.java new file mode 100644 index 000000000..3f3442f8c --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/Base64BinaryType.java @@ -0,0 +1,128 @@ +/* Base64BinaryType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema base64Binary type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class Base64BinaryType + extends AtomicSimpleType +{ + + static final String B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + "abcdefghijklmnopqrstuvwxyz0123456789+/"; + static final String B16 = "AEIMQUYcgkosw048"; + static final String B04 = "AQgw"; + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + Base64BinaryType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "base64Binary"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + // TODO value = collapseWhitespace(value); + int len = value.length(); + try + { + for (int i = len - 1; i >= 0; ) + { + char c4 = value.charAt(i--); + if (c4 == ' ') + c4 = value.charAt(i--); + char c3 = value.charAt(i--); + if (c3 == ' ') + c3 = value.charAt(i--); + char c2 = value.charAt(i--); + if (c2 == ' ') + c2 = value.charAt(i--); + char c1 = value.charAt(i--); + if (c1 == ' ') + c1 = value.charAt(i--); + + if (c4 == '=') + { + if (c3 == '=') + { + if (B04.indexOf(c2) != -1 && + B64.indexOf(c1) != -1) + continue; + } + else if (B16.indexOf(c3) != -1) + { + if (B64.indexOf(c2) != -1 && + B64.indexOf(c1) != -1) + continue; + } + } + else if (B64.indexOf(c4) != -1) + continue; + throw new DatatypeException(i, "illegal BASE64"); + } + } + catch (IndexOutOfBoundsException e) + { + throw new DatatypeException("illegal BASE64"); + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/BooleanType.java b/libjava/classpath/gnu/xml/validation/datatype/BooleanType.java new file mode 100644 index 000000000..5d98d2412 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/BooleanType.java @@ -0,0 +1,89 @@ +/* BooleanType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema boolean type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class BooleanType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.WHITESPACE + }; + + static final Set VALUE_SPACE = + new TreeSet(Arrays.asList(new String[] {"true", "false", "1", "0"})); + + BooleanType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "boolean"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (!VALUE_SPACE.contains(value)) + throw new DatatypeException("invalid boolean value"); + } + + public Object createValue(String literal, ValidationContext context) { + return ("1".equals(literal) || "true".equals(literal)) ? Boolean.TRUE : + Boolean.FALSE; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/ByteType.java b/libjava/classpath/gnu/xml/validation/datatype/ByteType.java new file mode 100644 index 000000000..9bce45bf9 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/ByteType.java @@ -0,0 +1,132 @@ +/* ByteType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema byte type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class ByteType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "127"; + static final String MIN_VALUE = "128"; + static final int LENGTH = MAX_VALUE.length(); + + ByteType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "byte"), + TypeLibrary.SHORT); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValue(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid byte value"); + int i = 0, off = 0; + boolean compare = false; + String compareTo = MAX_VALUE; + char c = value.charAt(0); + if (c == '+') + i++; + else if (c == '-') + { + compareTo = MIN_VALUE; + i++; + } + if (len - i > LENGTH) + throw new DatatypeException(0, "invalid byte value"); + else if (len - i == LENGTH) + compare = true; + for (; i < len; i++) + { + c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = compareTo.charAt(off); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid byte value"); + } + off++; + continue; + } + throw new DatatypeException(i, "invalid byte value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Byte(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/DateTimeType.java b/libjava/classpath/gnu/xml/validation/datatype/DateTimeType.java new file mode 100644 index 000000000..81d2785bc --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/DateTimeType.java @@ -0,0 +1,334 @@ +/* DateTimeType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema dateTime type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class DateTimeType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + DateTimeType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "dateTime"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValue(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && i == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + String year = value.substring(start, i); + if ("0000".equals(year) || year.length() < 4) + throw new DatatypeException(i, "invalid dateTime value"); + state = 1; + start = i + 1; + continue; + } + break; + case 1: // month + if (c == '-') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 2; + start = i + 1; + continue; + } + break; + case 2: // day + if (c == 'T') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 3; + start = i + 1; + continue; + } + break; + case 3: // hour + if (c == ':') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 4; + start = i + 1; + continue; + } + break; + case 4: // minute + if (c == ':') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 5; + start = i + 1; + continue; + } + break; + case 5: // second + if (c == '.') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 6; + start = i + 1; + continue; + } + else if (c == ' ') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 7; + start = i + 1; + continue; + } + break; + case 6: // second fraction + if (c == ' ') + { + state = 7; + start = i + 1; + continue; + } + break; + case 7: // timezone 1 + if (start == i) + { + if (c == '+' || c == '-') + continue; + else if (c == 'Z') + { + state = 9; + start = i + 1; + continue; + } + } + if (c == ':') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid dateTime value"); + state = 8; + start = i + 1; + continue; + } + break; + } + throw new DatatypeException(i, "invalid dateTime value"); + } + switch (state) + { + case 5: // second + if (len - start != 2) + throw new DatatypeException(len, "invalid dateTime value"); + break; + case 6: // second fraction + break; + case 8: // timezone 2 + if (len - start != 2) + throw new DatatypeException(len, "invalid dateTime value"); + break; + case 9: // post Z + break; + default: + throw new DatatypeException(len, "invalid dateTime value"); + } + } + + public Object createValue(String value, ValidationContext context) { + int len = value.length(); + int state = 0; + int start = 0; + Calendar cal = new GregorianCalendar(); + try + { + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && i == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + cal.set(Calendar.YEAR, + Integer.parseInt(value.substring(0, i))); + state = 1; + start = i + 1; + continue; + } + break; + case 1: // month + if (c == '-') + { + cal.set(Calendar.MONTH, + Integer.parseInt(value.substring(start, i))); + state = 2; + start = i + 1; + continue; + } + break; + case 2: // day + if (c == 'T') + { + cal.set(Calendar.DATE, + Integer.parseInt(value.substring(start, i))); + state = 3; + start = i + 1; + continue; + } + break; + case 3: // hour + if (c == ':') + { + cal.set(Calendar.HOUR, + Integer.parseInt(value.substring(start, i))); + state = 4; + start = i + 1; + continue; + } + break; + case 4: // minute + if (c == ':') + { + cal.set(Calendar.MINUTE, + Integer.parseInt(value.substring(start, i))); + state = 5; + start = i + 1; + continue; + } + break; + case 5: // second + if (c == ' ') + { + float second = Float.parseFloat(value.substring(start, i)); + // TODO adjust non-integer values + cal.set(Calendar.SECOND, (int) second); + state = 7; + start = i + 1; + continue; + } + break; + } + } + // end of input + if (len - start > 0 && state == 7) + { + // Timezone + String timezone = value.substring(len - start); + int i = timezone.indexOf(':'); + if (i == -1) + { + if ("Z".equals(timezone)) + timezone = "UTC"; + TimeZone tz = TimeZone.getTimeZone(timezone); + if (tz == null) + return null; + cal.set(Calendar.ZONE_OFFSET, tz.getRawOffset()); + } + else + { + String tzh = timezone.substring(0, i); + String tzm = timezone.substring(i + 1); + int offset = Integer.parseInt(tzh) * 360000; + if (offset < 0) + offset -= Integer.parseInt(tzm) * 60000; + else + offset += Integer.parseInt(tzm) * 60000; + cal.set(Calendar.ZONE_OFFSET, offset); + } + } + return cal.getTime(); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/DateType.java b/libjava/classpath/gnu/xml/validation/datatype/DateType.java new file mode 100644 index 000000000..8e6e3c35a --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/DateType.java @@ -0,0 +1,221 @@ +/* DateType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema date type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class DateType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + DateType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "date"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && i == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + String year = value.substring(start, i); + if ("0000".equals(year) || year.length() < 4) + throw new DatatypeException(i, "invalid date value"); + state = 1; + start = i + 1; + continue; + } + break; + case 1: // month + if (c == '-') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid date value"); + state = 2; + start = i + 1; + continue; + } + break; + } + throw new DatatypeException(i, "invalid date value"); + } + switch (state) + { + case 2: // day + if (len - start != 2) + throw new DatatypeException("invalid date value"); + break; + default: + throw new DatatypeException("invalid date value"); + } + } + + public Object createValue(String value, ValidationContext context) { + int len = value.length(); + int state = 0; + int start = 0; + Calendar cal = new GregorianCalendar(); + cal.set(Calendar.HOUR, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + try + { + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && i == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + cal.set(Calendar.YEAR, + Integer.parseInt(value.substring(0, i))); + state = 1; + start = i + 1; + continue; + } + break; + case 1: // month + if (c == '-') + { + cal.set(Calendar.MONTH, + Integer.parseInt(value.substring(start, i))); + state = 2; + start = i + 1; + continue; + } + break; + case 2: // day + if (c == 'T') + { + cal.set(Calendar.DATE, + Integer.parseInt(value.substring(start, i))); + state = 7; + start = i + 1; + continue; + } + break; + } + } + // end of input + if (len - start > 0 && state == 7) + { + // Timezone + String timezone = value.substring(len - start); + int i = timezone.indexOf(':'); + if (i == -1) + { + if ("Z".equals(timezone)) + timezone = "UTC"; + TimeZone tz = TimeZone.getTimeZone(timezone); + if (tz == null) + return null; + cal.set(Calendar.ZONE_OFFSET, tz.getRawOffset()); + } + else + { + String tzh = timezone.substring(0, i); + String tzm = timezone.substring(i + 1); + int offset = Integer.parseInt(tzh) * 360000; + if (offset < 0) + offset -= Integer.parseInt(tzm) * 60000; + else + offset += Integer.parseInt(tzm) * 60000; + cal.set(Calendar.ZONE_OFFSET, offset); + } + } + return cal.getTime(); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/DecimalType.java b/libjava/classpath/gnu/xml/validation/datatype/DecimalType.java new file mode 100644 index 000000000..43a26a399 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/DecimalType.java @@ -0,0 +1,118 @@ +/* DecimalType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigDecimal; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema decimal type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class DecimalType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + DecimalType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "decimal"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException("invalid decimal value"); + boolean seenDot = false; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + continue; + else if (c == '.') + { + if (seenDot) + throw new DatatypeException(i, "invalid decimal value"); + seenDot = true; + continue; + } + else if (c == '+' && i == 0) + continue; + else if (c == '-' && i == 0) + continue; + else + throw new DatatypeException(i, "invalid decimal value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new BigDecimal(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/DoubleType.java b/libjava/classpath/gnu/xml/validation/datatype/DoubleType.java new file mode 100644 index 000000000..dfaa7c8cb --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/DoubleType.java @@ -0,0 +1,110 @@ +/* DoubleType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema double type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class DoubleType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final Set SPECIAL = + new TreeSet(Arrays.asList(new String[] {"INF", "-INF", "NaN"})); + + DoubleType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "double"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (SPECIAL.contains(value)) + return; + try + { + Double.parseDouble(value); + } + catch (NumberFormatException e) + { + DatatypeException e2 = new DatatypeException("invalid double value"); + e2.initCause(e); + throw e2; + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Double(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/DurationType.java b/libjava/classpath/gnu/xml/validation/datatype/DurationType.java new file mode 100644 index 000000000..6c0f7b889 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/DurationType.java @@ -0,0 +1,238 @@ +/* DurationType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema duration type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class DurationType + extends AtomicSimpleType +{ + + static class Duration + implements Comparable + { + int years; + int months; + int days; + int minutes; + float seconds; + + public int hashCode() + { + int hc = years; + hc = hc * 31 + months; + hc = hc * 31 + days; + hc = hc * 31 + minutes; + hc = hc * 31 + new Float(seconds).hashCode(); + return hc; + } + + public boolean equals(Object other) + { + if (other instanceof Duration) + { + Duration duration = (Duration) other; + return duration.years ==years && + duration.months == months && + duration.days == days && + duration.minutes == minutes && + duration.seconds == seconds; + } + return false; + } + + public int compareTo(Object other) + { + if (other instanceof Duration) + { + Duration duration = (Duration) other; + if (duration.years != years) + return years - duration.years; + if (duration.months != months) + return months - duration.months; + if (duration.days != days) + return days - duration.days; + if (duration.minutes != minutes) + return minutes = duration.minutes; + if (duration.seconds == seconds) + return 0; + return (seconds < duration.seconds) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + DurationType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "duration"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + char expect = 'P'; + boolean seenT = false; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && expect == 'P') + continue; + if (c == expect) + { + if (c == 'P') + expect = 'Y'; + else if (c == 'Y') + expect = 'M'; + else if (c == 'M' && !seenT) + expect = 'D'; + else if (c == 'D') + expect = 'T'; + else if (c == 'T') + { + expect = 'H'; + seenT = true; + } + else if (c == 'H') + expect = 'M'; + else if (c == 'M' && seenT) + expect = 'S'; + else if (c == 'S') + { + if (i + 1 != len) + throw new DatatypeException(i, "illegal duration value"); + } + continue; + } + if (c >= 0x30 && c <= 0x39 && expect != 'P' && expect != 'T') + continue; + throw new DatatypeException(i, "illegal duration value"); + } + } + + public Object createValue(String value, ValidationContext context) { + boolean negative = false; + int days = 0, months = 0, years = 0; + int minutes = 0; + float seconds = 0.0f; + int len = value.length(); + char expect = 'P'; + boolean seenT = false; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && expect == 'P') + { + negative = true; + continue; + } + if (c == expect) + { + if (c == 'P') + expect = 'Y'; + else if (c == 'Y') + { + expect = 'M'; + years = Integer.parseInt(value.substring(start, i)); + } + else if (c == 'M' && !seenT) + expect = 'D'; + else if (c == 'D') + expect = 'T'; + else if (c == 'T') + { + expect = 'H'; + seenT = true; + } + else if (c == 'H') + expect = 'M'; + else if (c == 'M' && seenT) + expect = 'S'; + else if (c == 'S') + { + if (i + 1 != len) + return null; + } + start = i + 1; + continue; + } + if (c >= 0x30 && c <= 0x39 && expect != 'P' && expect != 'T') + continue; + return null; + } + if (negative) + { + days = days * -1; + minutes = minutes * -1; + seconds = seconds * -1.0f; + } + Duration duration = new Duration(); + duration.days = days; + duration.minutes = minutes; + duration.seconds = seconds; + return duration; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java b/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java new file mode 100644 index 000000000..5415e88e2 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java @@ -0,0 +1,108 @@ +/* EntitiesType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import gnu.java.lang.CPStringBuilder; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema ENTITIES type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class EntitiesType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + EntitiesType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "ENTITIES"), + TypeLibrary.ENTITY); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + CPStringBuilder buf = new CPStringBuilder(); + int len = value.length(); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == ' ') + { + String token = buf.toString(); + if (token.length() > 0) + { + if (!context.isUnparsedEntity(token)) + throw new DatatypeException(i, "invalid ENTITIES value"); + } + buf.setLength(0); + } + else + buf.append(c); + } + String token = buf.toString(); + if (token.length() == 0 || !context.isUnparsedEntity(token)) + throw new DatatypeException("invalid ENTITIES value"); + } + + public boolean isContextDependent() + { + return true; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/EntityType.java b/libjava/classpath/gnu/xml/validation/datatype/EntityType.java new file mode 100644 index 000000000..f4a10bd50 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/EntityType.java @@ -0,0 +1,87 @@ +/* EntityType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema ENTITY type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class EntityType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + EntityType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "ENTITY"), + TypeLibrary.NCNAME); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (value.length() == 0 || !context.isUnparsedEntity(value)) + throw new DatatypeException("invalid ENTITY value"); + } + + public boolean isContextDependent() + { + return true; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/EnumerationFacet.java b/libjava/classpath/gnu/xml/validation/datatype/EnumerationFacet.java new file mode 100644 index 000000000..45b9c2378 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/EnumerationFacet.java @@ -0,0 +1,68 @@ +/* EnumerationFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>enumeration</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class EnumerationFacet + extends Facet +{ + + public final String value; + + public EnumerationFacet(String value, Annotation annotation) + { + super(ENUMERATION, annotation); + this.value = value; + } + + public int hashCode() + { + return value.hashCode(); + } + + public boolean equals(Object other) + { + return (other instanceof EnumerationFacet && + ((EnumerationFacet) other).value.equals(value)); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/Facet.java b/libjava/classpath/gnu/xml/validation/datatype/Facet.java new file mode 100644 index 000000000..9f18bedc8 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/Facet.java @@ -0,0 +1,77 @@ +/* Facet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * An XML Schema constraining facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public abstract class Facet +{ + + public static final int LENGTH = 1; + public static final int MIN_LENGTH = 2; + public static final int MAX_LENGTH = 3; + public static final int PATTERN = 4; + public static final int ENUMERATION = 5; + public static final int WHITESPACE = 6; + public static final int MAX_INCLUSIVE = 7; + public static final int MAX_EXCLUSIVE = 8; + public static final int MIN_EXCLUSIVE = 9; + public static final int MIN_INCLUSIVE = 10; + public static final int TOTAL_DIGITS = 11; + public static final int FRACTION_DIGITS = 12; + + /** + * The type of this facet. + */ + public final int type; + + /** + * Optional annotation. + */ + public Annotation annotation; + + protected Facet(int type, Annotation annotation) + { + this.type = type; + this.annotation = annotation; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/FloatType.java b/libjava/classpath/gnu/xml/validation/datatype/FloatType.java new file mode 100644 index 000000000..8dbb4aa56 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/FloatType.java @@ -0,0 +1,110 @@ +/* FloatType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema float type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class FloatType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final Set SPECIAL = + new TreeSet(Arrays.asList(new String[] {"INF", "-INF", "NaN"})); + + FloatType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "float"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (SPECIAL.contains(value)) + return; + try + { + Float.parseFloat(value); + } + catch (NumberFormatException e) + { + DatatypeException e2 = new DatatypeException("invalid float value"); + e2.initCause(e); + throw e2; + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Float(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/FractionDigitsFacet.java b/libjava/classpath/gnu/xml/validation/datatype/FractionDigitsFacet.java new file mode 100644 index 000000000..c0d714578 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/FractionDigitsFacet.java @@ -0,0 +1,71 @@ +/* FractionDigitsFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>fractionDigits</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class FractionDigitsFacet + extends Facet +{ + + public final int value; + + public final boolean fixed; + + public FractionDigitsFacet(int value, boolean fixed, Annotation annotation) + { + super(FRACTION_DIGITS, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value; + } + + public boolean equals(Object other) + { + return (other instanceof FractionDigitsFacet && + ((FractionDigitsFacet) other).value == value); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/GDayType.java b/libjava/classpath/gnu/xml/validation/datatype/GDayType.java new file mode 100644 index 000000000..cc6b8e3d4 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/GDayType.java @@ -0,0 +1,174 @@ +/* GDayType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema gDay type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class GDayType + extends AtomicSimpleType +{ + + static class GDay + implements Comparable + { + + int day; + + public int hashCode() + { + return day; + } + + public boolean equals(Object other) + { + if (other instanceof GDay) + return ((GDay) other).day == day; + return false; + } + + public int compareTo(Object other) + { + if (other instanceof GDay) + { + GDay gd = (GDay) other; + if (gd.day == day) + return 0; + return (day < gd.day) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + GDayType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gDay"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + switch (i) + { + case 0: + continue; + case 1: + state = 1; + start = i + 1; + continue; + default: + throw new DatatypeException(i, "invalid GDay value"); + } + } + break; + case 1: // month + if (c == '-') + { + if (i - start != 0) + throw new DatatypeException(i, "invalid GDay value"); + state = 2; + start = i + 1; + continue; + } + break; + } + throw new DatatypeException(i, "invalid GDay value"); + } + switch (state) + { + case 2: // day + if (len - start != 2) + throw new DatatypeException("invalid GDay value"); + break; + default: + throw new DatatypeException("invalid GDay value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + GDay ret = new GDay(); + ret.day = Integer.parseInt(literal.substring(3)); + return ret; + } + catch (Exception e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/GMonthDayType.java b/libjava/classpath/gnu/xml/validation/datatype/GMonthDayType.java new file mode 100644 index 000000000..d293d9b57 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/GMonthDayType.java @@ -0,0 +1,183 @@ +/* GMonthDayType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema gMonthDay type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class GMonthDayType + extends AtomicSimpleType +{ + + static class GMonthDay + implements Comparable + { + + int month; + int day; + + public int hashCode() + { + return month * 31 + day; + } + + public boolean equals(Object other) + { + if (other instanceof GMonthDay) + { + GMonthDay gmd = (GMonthDay) other; + return gmd.month == month && gmd.day == day; + } + return false; + } + + public int compareTo(Object other) + { + if (other instanceof GMonthDay) + { + GMonthDay gmd = (GMonthDay) other; + if (gmd.month == month) + { + if (gmd.day == day) + return 0; + return (day < gmd.day) ? -1 : 1; + } + return (month < gmd.month) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + GMonthDayType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gMonthDay"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + switch (i) + { + case 0: + continue; + case 1: + state = 1; + start = i + 1; + continue; + default: + throw new DatatypeException(i, "illegal GMonthDay type"); + } + } + break; + case 1: // month + if (c == '-') + { + if (i - start != 2) + throw new DatatypeException(i, "illegal GMonthDay type"); + state = 2; + start = i + 1; + continue; + } + break; + } + throw new DatatypeException(i, "illegal GMonthDay type"); + } + switch (state) + { + case 2: // day + if (len - start != 2) + throw new DatatypeException("illegal GMonthDay type"); + break; + default: + throw new DatatypeException("illegal GMonthDay type"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + GMonthDay ret = new GMonthDay(); + ret.month = Integer.parseInt(literal.substring(2, 5)); + ret.day = Integer.parseInt(literal.substring(6)); + return ret; + } + catch (Exception e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/GMonthType.java b/libjava/classpath/gnu/xml/validation/datatype/GMonthType.java new file mode 100644 index 000000000..9450874b9 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/GMonthType.java @@ -0,0 +1,163 @@ +/* GMonthType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema gMonth type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class GMonthType + extends AtomicSimpleType +{ + + static class GMonth + implements Comparable + { + + int month; + + public int hashCode() + { + return month; + } + + public boolean equals(Object other) + { + if (other instanceof GMonth) + return ((GMonth) other).month == month; + return false; + } + + public int compareTo(Object other) + { + if (other instanceof GMonth) + { + GMonth gm = (GMonth) other; + if (gm.month == month) + return 0; + return (month < gm.month) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + GMonthType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gMonth"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + switch (i) + { + case 0: + continue; + case 1: + state = 1; + start = i + 1; + continue; + default: + throw new DatatypeException(i, "illegal GMonth value"); + } + } + break; + } + throw new DatatypeException(i, "illegal GMonth value"); + } + switch (state) + { + case 1: // month + if (len - start != 2) + throw new DatatypeException("illegal GMonth value"); + break; + default: + throw new DatatypeException("illegal GMonth value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + GMonth ret = new GMonth(); + ret.month = Integer.parseInt(literal.substring(2)); + return ret; + } + catch (Exception e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/GYearMonthType.java b/libjava/classpath/gnu/xml/validation/datatype/GYearMonthType.java new file mode 100644 index 000000000..9aabfb61c --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/GYearMonthType.java @@ -0,0 +1,176 @@ +/* GYearMonthType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema gYearMonth type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class GYearMonthType + extends AtomicSimpleType +{ + + static class GYearMonth + implements Comparable + { + + int year; + int month; + + public int hashCode() + { + return year * 31 + month; + } + + public boolean equals(Object other) + { + if (other instanceof GYearMonth) + { + GYearMonth gmy = (GYearMonth) other; + return gmy.year == year && gmy.month == month; + } + return false; + } + + public int compareTo(Object other) + { + if (other instanceof GYearMonth) + { + GYearMonth gmy = (GYearMonth) other; + if (gmy.year == year) + { + if (gmy.month == month) + return 0; + return (month < gmy.month) ? -1 : 1; + } + return (year < gmy.year) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + GYearMonthType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gYearMonth"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && i == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 0: // year + if (c == '-') + { + String year = value.substring(start, i); + if (year.length() < 4 || Integer.parseInt(year) == 0) + throw new DatatypeException(i, "illegal GYear value"); + state = 1; + start = i + 1; + continue; + } + break; + } + throw new DatatypeException(i, "illegal GYear value"); + } + switch (state) + { + case 1: // month + if (len - start != 2) + throw new DatatypeException("illegal GYear value"); + break; + default: + throw new DatatypeException("illegal GYear value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + int offset = 5; + if (literal.charAt(0) == '-') + offset++; + GYearMonth ret = new GYearMonth(); + ret.year = Integer.parseInt(literal.substring(0, offset)); + ret.month = Integer.parseInt(literal.substring(offset + 1)); + return ret; + } + catch (Exception e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/GYearType.java b/libjava/classpath/gnu/xml/validation/datatype/GYearType.java new file mode 100644 index 000000000..5b1e03232 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/GYearType.java @@ -0,0 +1,151 @@ +/* GYearType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema gYear type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class GYearType + extends AtomicSimpleType +{ + + static class GYear + implements Comparable + { + + int year; + + public int hashCode() + { + return year; + } + + public boolean equals(Object other) + { + if (other instanceof GYear) + return ((GYear) other).year == year; + return false; + } + + public int compareTo(Object other) + { + if (other instanceof GYear) + { + GYear gy = (GYear) other; + if (gy.year == year) + return 0; + return (year < gy.year) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + GYearType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gYear"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 0; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && i == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + throw new DatatypeException(i, "invalid GYear value"); + } + switch (state) + { + case 0: // year + String year = value.substring(start, len); + if (year.length() < 4 || Integer.parseInt(year) == 0) + throw new DatatypeException("invalid GYear value"); + break; + default: + throw new DatatypeException("invalid GYear value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + GYear ret = new GYear(); + ret.year = Integer.parseInt(literal); + return ret; + } + catch (Exception e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/HexBinaryType.java b/libjava/classpath/gnu/xml/validation/datatype/HexBinaryType.java new file mode 100644 index 000000000..5f133e322 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/HexBinaryType.java @@ -0,0 +1,89 @@ +/* HexBinaryType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema hexBinary type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class HexBinaryType + extends AtomicSimpleType +{ + + static final String HEX = "0123456789ABCDEF"; + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + HexBinaryType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "hexBinary"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (HEX.indexOf(c) == -1) + throw new DatatypeException(i, "invalid hexBinary value"); + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/IDRefType.java b/libjava/classpath/gnu/xml/validation/datatype/IDRefType.java new file mode 100644 index 000000000..932089549 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/IDRefType.java @@ -0,0 +1,86 @@ +/* IDRefType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema IDREF type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class IDRefType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + IDRefType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "IDREF"), + TypeLibrary.NCNAME); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + // TODO + } + + public int getIdType() + { + return ID_TYPE_IDREF; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/IDRefsType.java b/libjava/classpath/gnu/xml/validation/datatype/IDRefsType.java new file mode 100644 index 000000000..6adaed13b --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/IDRefsType.java @@ -0,0 +1,86 @@ +/* IDRefsType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema IDREFS type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class IDRefsType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + IDRefsType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "IDREFS"), + TypeLibrary.IDREF); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + // TODO + } + + public int getIdType() + { + return ID_TYPE_IDREFS; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/IDType.java b/libjava/classpath/gnu/xml/validation/datatype/IDType.java new file mode 100644 index 000000000..792601d78 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/IDType.java @@ -0,0 +1,86 @@ +/* IDType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema ID type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class IDType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + IDType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "ID"), + TypeLibrary.NCNAME); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + // TODO + } + + public int getIdType() + { + return ID_TYPE_ID; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/IntType.java b/libjava/classpath/gnu/xml/validation/datatype/IntType.java new file mode 100644 index 000000000..c8f756832 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/IntType.java @@ -0,0 +1,132 @@ +/* IntType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema int type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class IntType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "2147483647"; + static final String MIN_VALUE = "2147483648"; + static final int LENGTH = MAX_VALUE.length(); + + IntType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "int"), + TypeLibrary.LONG); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid int value"); + int i = 0, off = 0; + boolean compare = false; + String compareTo = MAX_VALUE; + char c = value.charAt(0); + if (c == '+') + i++; + else if (c == '-') + { + compareTo = MIN_VALUE; + i++; + } + if (len - i > LENGTH) + throw new DatatypeException("invalid int value"); + else if (len - i == LENGTH) + compare = true; + for (; i < len; i++) + { + c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = compareTo.charAt(off); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid int value"); + } + off++; + continue; + } + throw new DatatypeException(i, "invalid int value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Integer(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/IntegerType.java b/libjava/classpath/gnu/xml/validation/datatype/IntegerType.java new file mode 100644 index 000000000..b9a2a564a --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/IntegerType.java @@ -0,0 +1,109 @@ +/* IntegerType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigInteger; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema integer type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class IntegerType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + IntegerType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "integer"), + TypeLibrary.DECIMAL); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid integer value"); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + continue; + else if (c == '+' && i == 0) + continue; + else if (c == '-' && i == 0) + continue; + throw new DatatypeException(i, "invalid integer value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new BigInteger(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/LanguageType.java b/libjava/classpath/gnu/xml/validation/datatype/LanguageType.java new file mode 100644 index 000000000..d30cc538f --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/LanguageType.java @@ -0,0 +1,86 @@ +/* LanguageType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.regex.Pattern; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema language type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class LanguageType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + static final Pattern PATTERN = + Pattern.compile("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*"); + + LanguageType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "language"), + TypeLibrary.TOKEN); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (!PATTERN.matcher(value).matches()) + throw new DatatypeException("invalid language value"); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/LengthFacet.java b/libjava/classpath/gnu/xml/validation/datatype/LengthFacet.java new file mode 100644 index 000000000..d6eaacd71 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/LengthFacet.java @@ -0,0 +1,71 @@ +/* LengthFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>length</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class LengthFacet + extends Facet +{ + + public final int value; + + public final boolean fixed; + + public LengthFacet(int value, boolean fixed, Annotation annotation) + { + super(LENGTH, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value; + } + + public boolean equals(Object other) + { + return (other instanceof LengthFacet && + ((LengthFacet) other).value == value); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/ListSimpleType.java b/libjava/classpath/gnu/xml/validation/datatype/ListSimpleType.java new file mode 100644 index 000000000..1e0d41d01 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/ListSimpleType.java @@ -0,0 +1,82 @@ +/* ListSimpleType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Set; +import java.util.StringTokenizer; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * An XML Schema list simple type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class ListSimpleType + extends SimpleType +{ + + /** + * The type of the items in this list (atomic or union). + */ + public final SimpleType itemType; + + public ListSimpleType(QName name, Set facets, + int fundamentalFacets, SimpleType baseType, + Annotation annotation, SimpleType itemType) + { + super(name, LIST, facets, fundamentalFacets, baseType, annotation); + this.itemType = itemType; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + StringTokenizer st = new StringTokenizer(value, " "); + if (!st.hasMoreTokens()) + throw new DatatypeException("invalid list value"); + while (st.hasMoreTokens()) + { + String token = st.nextToken(); + itemType.checkValid(token, context); + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/LongType.java b/libjava/classpath/gnu/xml/validation/datatype/LongType.java new file mode 100644 index 000000000..781b17f62 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/LongType.java @@ -0,0 +1,132 @@ +/* LongType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema long type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class LongType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "9223372036854775807"; + static final String MIN_VALUE = "9223372036854775808"; + static final int LENGTH = MAX_VALUE.length(); + + LongType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "long"), + TypeLibrary.INTEGER); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid long value"); + int i = 0, off = 0; + boolean compare = false; + String compareTo = MAX_VALUE; + char c = value.charAt(0); + if (c == '+') + i++; + else if (c == '-') + { + compareTo = MIN_VALUE; + i++; + } + if (len - i > LENGTH) + throw new DatatypeException(i, "invalid long value"); + else if (len - i == LENGTH) + compare = true; + for (; i < len; i++) + { + c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = compareTo.charAt(off); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid long value"); + } + off++; + continue; + } + throw new DatatypeException(i, "invalid long value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Long(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/MaxExclusiveFacet.java b/libjava/classpath/gnu/xml/validation/datatype/MaxExclusiveFacet.java new file mode 100644 index 000000000..90e940371 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/MaxExclusiveFacet.java @@ -0,0 +1,110 @@ +/* MaxExclusiveFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Date; + +/** + * The <code>maxExclusive</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class MaxExclusiveFacet + extends Facet +{ + + public final Object value; // date or number + + public final boolean fixed; + + public MaxExclusiveFacet(Object value, boolean fixed, Annotation annotation) + { + super(MAX_EXCLUSIVE, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value.hashCode(); + } + + public boolean equals(Object other) + { + return (other instanceof MaxExclusiveFacet && + ((MaxExclusiveFacet) other).value.equals(value)); + } + + boolean matches(Object test) + { + if (value instanceof Date) + { + Date dvalue = (Date) value; + if (!(test instanceof Date)) + return false; + return ((Date) test).before(dvalue); + } + else if (value instanceof BigInteger) + { + BigInteger ivalue = (BigInteger) value; + if (!(test instanceof BigInteger)) + return false; + return ((BigInteger) test).compareTo(ivalue) < 0; + } + else if (value instanceof BigDecimal) + { + BigDecimal dvalue = (BigDecimal) value; + if (!(test instanceof BigDecimal)) + return false; + return ((BigDecimal) test).compareTo(dvalue) < 0; + } + else if (value instanceof Comparable) + { + if (!(test.getClass().equals(value.getClass()))) + return false; + return ((Comparable) test).compareTo(value) < 0; + } + Number nvalue = (Number) value; + if (!(test instanceof Number)) + return false; + return ((Number) test).doubleValue() < nvalue.doubleValue(); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/MaxInclusiveFacet.java b/libjava/classpath/gnu/xml/validation/datatype/MaxInclusiveFacet.java new file mode 100644 index 000000000..c260113da --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/MaxInclusiveFacet.java @@ -0,0 +1,111 @@ +/* MaxInclusiveFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Date; + +/** + * The <code>maxInclusive</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class MaxInclusiveFacet + extends Facet +{ + + public final Object value; + + public final boolean fixed; + + public MaxInclusiveFacet(Object value, boolean fixed, Annotation annotation) + { + super(MAX_INCLUSIVE, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value.hashCode(); + } + + public boolean equals(Object other) + { + return (other instanceof MaxInclusiveFacet && + ((MaxInclusiveFacet) other).value.equals(value)); + } + + boolean matches(Object test) + { + if (value instanceof Date) + { + Date dvalue = (Date) value; + if (!(test instanceof Date)) + return false; + Date dtest = (Date) test; + return dtest.equals(dvalue) || dtest.before(dvalue); + } + else if (value instanceof BigInteger) + { + BigInteger ivalue = (BigInteger) value; + if (!(test instanceof BigInteger)) + return false; + return ((BigInteger) test).compareTo(ivalue) <= 0; + } + else if (value instanceof BigDecimal) + { + BigDecimal dvalue = (BigDecimal) value; + if (!(test instanceof BigDecimal)) + return false; + return ((BigDecimal) test).compareTo(dvalue) <= 0; + } + else if (value instanceof Comparable) + { + if (!(test.getClass().equals(value.getClass()))) + return false; + return ((Comparable) test).compareTo(value) <= 0; + } + Number nvalue = (Number) value; + if (!(test instanceof Number)) + return false; + return ((Number) test).doubleValue() <= nvalue.doubleValue(); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/MaxLengthFacet.java b/libjava/classpath/gnu/xml/validation/datatype/MaxLengthFacet.java new file mode 100644 index 000000000..ba77ff2df --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/MaxLengthFacet.java @@ -0,0 +1,71 @@ +/* MaxLengthFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>maxLength</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class MaxLengthFacet + extends Facet +{ + + public final int value; + + public final boolean fixed; + + public MaxLengthFacet(int value, boolean fixed, Annotation annotation) + { + super(MAX_LENGTH, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value; + } + + public boolean equals(Object other) + { + return (other instanceof MaxLengthFacet && + ((MaxLengthFacet) other).value == value); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/MinExclusiveFacet.java b/libjava/classpath/gnu/xml/validation/datatype/MinExclusiveFacet.java new file mode 100644 index 000000000..a779d09d8 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/MinExclusiveFacet.java @@ -0,0 +1,110 @@ +/* MinExclusiveFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Date; + +/** + * The <code>minExclusive</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class MinExclusiveFacet + extends Facet +{ + + public final Object value; + + public final boolean fixed; + + public MinExclusiveFacet(Object value, boolean fixed, Annotation annotation) + { + super(MIN_EXCLUSIVE, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value.hashCode(); + } + + public boolean equals(Object other) + { + return (other instanceof MinExclusiveFacet && + ((MinExclusiveFacet) other).value.equals(value)); + } + + boolean matches(Object test) + { + if (value instanceof Date) + { + Date dvalue = (Date) value; + if (!(test instanceof Date)) + return false; + return ((Date) test).after(dvalue); + } + else if (value instanceof BigInteger) + { + BigInteger ivalue = (BigInteger) value; + if (!(test instanceof BigInteger)) + return false; + return ((BigInteger) test).compareTo(ivalue) > 0; + } + else if (value instanceof BigDecimal) + { + BigDecimal dvalue = (BigDecimal) value; + if (!(test instanceof BigDecimal)) + return false; + return ((BigDecimal) test).compareTo(dvalue) > 0; + } + else if (value instanceof Comparable) + { + if (!(test.getClass().equals(value.getClass()))) + return false; + return ((Comparable) test).compareTo(value) > 0; + } + Number nvalue = (Number) value; + if (!(test instanceof Number)) + return false; + return ((Number) test).doubleValue() > nvalue.doubleValue(); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/MinInclusiveFacet.java b/libjava/classpath/gnu/xml/validation/datatype/MinInclusiveFacet.java new file mode 100644 index 000000000..6138c9af8 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/MinInclusiveFacet.java @@ -0,0 +1,111 @@ +/* MinInclusiveFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Date; + +/** + * The <code>minInclusive</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class MinInclusiveFacet + extends Facet +{ + + public final Object value; + + public final boolean fixed; + + public MinInclusiveFacet(Object value, boolean fixed, Annotation annotation) + { + super(MIN_INCLUSIVE, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value.hashCode(); + } + + public boolean equals(Object other) + { + return (other instanceof MinInclusiveFacet && + ((MinInclusiveFacet) other).value.equals(value)); + } + + boolean matches(Object test) + { + if (value instanceof Date) + { + Date dvalue = (Date) value; + if (!(test instanceof Date)) + return false; + Date dtest = (Date) test; + return dtest.equals(dvalue) || dtest.after(dvalue); + } + else if (value instanceof BigInteger) + { + BigInteger ivalue = (BigInteger) value; + if (!(test instanceof BigInteger)) + return false; + return ((BigInteger) test).compareTo(ivalue) >= 0; + } + else if (value instanceof BigDecimal) + { + BigDecimal dvalue = (BigDecimal) value; + if (!(test instanceof BigDecimal)) + return false; + return ((BigDecimal) test).compareTo(dvalue) >= 0; + } + else if (value instanceof Comparable) + { + if (!(test.getClass().equals(value.getClass()))) + return false; + return ((Comparable) test).compareTo(value) >= 0; + } + Number nvalue = (Number) value; + if (!(test instanceof Number)) + return false; + return ((Number) test).doubleValue() >= nvalue.doubleValue(); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/MinLengthFacet.java b/libjava/classpath/gnu/xml/validation/datatype/MinLengthFacet.java new file mode 100644 index 000000000..f13e80b62 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/MinLengthFacet.java @@ -0,0 +1,71 @@ +/* MinLengthFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>minLength</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class MinLengthFacet + extends Facet +{ + + public final int value; + + public final boolean fixed; + + public MinLengthFacet(int value, boolean fixed, Annotation annotation) + { + super(MIN_LENGTH, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value; + } + + public boolean equals(Object other) + { + return (other instanceof MinLengthFacet && + ((MinLengthFacet) other).value == value); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NCNameType.java b/libjava/classpath/gnu/xml/validation/datatype/NCNameType.java new file mode 100644 index 000000000..3f2088f9b --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NCNameType.java @@ -0,0 +1,110 @@ +/* NCNameType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.io.IOException; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; +import gnu.xml.stream.UnicodeReader; +import gnu.xml.stream.XMLParser; + +/** + * The XML Schema NCName type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NCNameType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + NCNameType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "NCName"), + TypeLibrary.NAME); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + try + { + int[] cp = UnicodeReader.toCodePointArray(value); + if (cp.length == 0) + throw new DatatypeException("invalid NCName value"); + // XXX XML 1.1 documents? + if (cp[0] == ':' || !XMLParser.isNameStartCharacter(cp[0], false)) + throw new DatatypeException(0, "invalid NCName value"); + boolean seenColon = false; + for (int i = 1; i < cp.length; i++) + { + if (cp[i] == ':') + { + if (seenColon || (i + 1 == cp.length)) + throw new DatatypeException(i, "invalid NCName value"); + seenColon = true; + } + else if (!XMLParser.isNameCharacter(cp[i], false)) + throw new DatatypeException(i, "invalid NCName value"); + } + } + catch (IOException e) + { + DatatypeException e2 = new DatatypeException("invalid NCName value"); + e2.initCause(e); + throw e2; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NMTokenType.java b/libjava/classpath/gnu/xml/validation/datatype/NMTokenType.java new file mode 100644 index 000000000..ca3271fef --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NMTokenType.java @@ -0,0 +1,101 @@ +/* NMTokenType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.io.IOException; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; +import gnu.xml.stream.UnicodeReader; +import gnu.xml.stream.XMLParser; + +/** + * The XML Schema NMTOKEN type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NMTokenType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + NMTokenType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "NMTOKEN"), + TypeLibrary.TOKEN); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + try + { + int[] cp = UnicodeReader.toCodePointArray(value); + if (cp.length == 0) + throw new DatatypeException("invalid NMTOKEN value"); + for (int i = 0; i < cp.length; i++) + { + // XXX XML 1.1 documents? + if (!XMLParser.isNameCharacter(cp[i], false)) + throw new DatatypeException(i, "invalid NMTOKEN value"); + } + } + catch (IOException e) + { + DatatypeException e2 = new DatatypeException("invalid NMTOKEN value"); + e2.initCause(e); + throw e2; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java b/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java new file mode 100644 index 000000000..388b451db --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java @@ -0,0 +1,125 @@ +/* NMTokensType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import gnu.java.lang.CPStringBuilder; + +import java.io.IOException; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; +import gnu.xml.stream.UnicodeReader; +import gnu.xml.stream.XMLParser; + +/** + * The XML Schema NMTOKENS type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NMTokensType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + NMTokensType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "NMTOKENS"), + TypeLibrary.NMTOKEN); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + CPStringBuilder buf = new CPStringBuilder(); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == ' ') + { + String token = buf.toString(); + if (token.length() > 0) + checkNmtoken(token, i); + buf.setLength(0); + } + else + buf.append(c); + } + checkNmtoken(buf.toString(), len); + } + + private void checkNmtoken(String text, int i) + throws DatatypeException + { + try + { + int[] cp = UnicodeReader.toCodePointArray(text); + if (cp.length == 0) + throw new DatatypeException("invalid NMTOKEN value"); + for (int j = 0; j < cp.length; j++) + { + // XXX XML 1.1 documents? + if (!XMLParser.isNameCharacter(cp[j], false)) + throw new DatatypeException(i, "invalid NMTOKEN value"); + } + } + catch (IOException e) + { + DatatypeException e2 = new DatatypeException("invalid NMTOKEN value"); + e2.initCause(e); + throw e2; + } + } + + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NameType.java b/libjava/classpath/gnu/xml/validation/datatype/NameType.java new file mode 100644 index 000000000..70349aed8 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NameType.java @@ -0,0 +1,103 @@ +/* NameType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.io.IOException; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; +import gnu.xml.stream.UnicodeReader; +import gnu.xml.stream.XMLParser; + +/** + * The XML Schema Name type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NameType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + NameType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "Name"), + TypeLibrary.TOKEN); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + try + { + int[] cp = UnicodeReader.toCodePointArray(value); + if (cp.length == 0) + throw new DatatypeException("invalid Name value"); + // XXX XML 1.1 documents? + if (!XMLParser.isNameStartCharacter(cp[0], false)) + throw new DatatypeException(0, "invalid Name value"); + for (int i = 1; i < cp.length; i++) + { + if (!XMLParser.isNameCharacter(cp[i], false)) + throw new DatatypeException(i, "invalid Name value"); + } + } + catch (IOException e) + { + DatatypeException e2 = new DatatypeException("invalid Name value"); + e2.initCause(e); + throw e2; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NegativeIntegerType.java b/libjava/classpath/gnu/xml/validation/datatype/NegativeIntegerType.java new file mode 100644 index 000000000..1e6439c99 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NegativeIntegerType.java @@ -0,0 +1,110 @@ +/* NegativeIntegerType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigInteger; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema negativeInteger type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NegativeIntegerType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + NegativeIntegerType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "negativeInteger"), + TypeLibrary.NON_POSITIVE_INTEGER); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValue(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid negative integer value"); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-') + { + if (i == 0) + continue; + } + else if (c >= 0x30 && c <= 0x39) + continue; + throw new DatatypeException(i, "invalid negative integer value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new BigInteger(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NonNegativeIntegerType.java b/libjava/classpath/gnu/xml/validation/datatype/NonNegativeIntegerType.java new file mode 100644 index 000000000..c5192f346 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NonNegativeIntegerType.java @@ -0,0 +1,120 @@ +/* NonNegativeIntegerType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigInteger; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema nonNegativeInteger type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NonNegativeIntegerType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + NonNegativeIntegerType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "nonNegativeInteger"), + TypeLibrary.INTEGER); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid non-negative integer value"); + boolean negative = false; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == 0x30) + continue; + else if (c >= 0x31 && c <= 0x39) + { + if (negative) + throw new DatatypeException(i, + "invalid non-negative integer value"); + continue; + } + else if (c == '+' && i == 0) + continue; + else if (c == '-' && i == 0) + { + negative = true; + continue; + } + throw new DatatypeException(i, "invalid non-negative integer value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new BigInteger(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NonPositiveIntegerType.java b/libjava/classpath/gnu/xml/validation/datatype/NonPositiveIntegerType.java new file mode 100644 index 000000000..e418c0615 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NonPositiveIntegerType.java @@ -0,0 +1,120 @@ +/* NonPositiveIntegerType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigInteger; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema nonPositiveInteger type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NonPositiveIntegerType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + NonPositiveIntegerType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "nonPositiveInteger"), + TypeLibrary.INTEGER); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid non-positive integer value"); + boolean positive = true; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == 0x30) + continue; + else if (c >= 0x31 && c <= 0x39) + { + if (positive) + throw new DatatypeException(i, + "invalid non-positive integer value"); + continue; + } + else if (c == '+' && i == 0) + continue; + else if (c == '-' && i == 0) + { + positive = false; + continue; + } + throw new DatatypeException(i, "invalid non-positive integer value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new BigInteger(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NormalizedStringType.java b/libjava/classpath/gnu/xml/validation/datatype/NormalizedStringType.java new file mode 100644 index 000000000..9009f648a --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NormalizedStringType.java @@ -0,0 +1,87 @@ +/* NormalizedStringType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema normalizedString type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NormalizedStringType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + NormalizedStringType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "normalizedString"), + TypeLibrary.STRING); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == 0x0a || c == 0x0d || c == 0x09) + throw new DatatypeException(i, "invalid normalized-string value"); + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/NotationType.java b/libjava/classpath/gnu/xml/validation/datatype/NotationType.java new file mode 100644 index 000000000..b661cb4e1 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/NotationType.java @@ -0,0 +1,87 @@ +/* NotationType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema NOTATION type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class NotationType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + NotationType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "NOTATION"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + if (!context.isNotation(value)) + throw new DatatypeException("invalid NOTATION value"); + } + + public boolean isContextDependent() + { + return true; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/PatternFacet.java b/libjava/classpath/gnu/xml/validation/datatype/PatternFacet.java new file mode 100644 index 000000000..9c1cb7e30 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/PatternFacet.java @@ -0,0 +1,70 @@ +/* PatternFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.regex.Pattern; + +/** + * The <code>pattern</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class PatternFacet + extends Facet +{ + + public final Pattern value; + + public PatternFacet(Pattern value, Annotation annotation) + { + super(PATTERN, annotation); + this.value = value; + } + + public int hashCode() + { + return value.hashCode(); + } + + public boolean equals(Object other) + { + return (other instanceof PatternFacet && + ((PatternFacet) other).value.equals(value)); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/PositiveIntegerType.java b/libjava/classpath/gnu/xml/validation/datatype/PositiveIntegerType.java new file mode 100644 index 000000000..15d0febfc --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/PositiveIntegerType.java @@ -0,0 +1,110 @@ +/* PositiveIntegerType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.math.BigInteger; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema positiveInteger type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class PositiveIntegerType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + PositiveIntegerType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "positiveInteger"), + TypeLibrary.NON_NEGATIVE_INTEGER); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid positive integer value"); + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '+') + { + if (i == 0) + continue; + } + else if (c >= 0x30 && c <= 0x39) + continue; + throw new DatatypeException(i, "invalid positive integer value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new BigInteger(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/QNameType.java b/libjava/classpath/gnu/xml/validation/datatype/QNameType.java new file mode 100644 index 000000000..bdc40c97f --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/QNameType.java @@ -0,0 +1,121 @@ +/* QNameType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.io.IOException; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; +import gnu.xml.stream.UnicodeReader; +import gnu.xml.stream.XMLParser; + +/** + * The XML Schema QName type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class QNameType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + QNameType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "QName"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int ci = -1; + try + { + int[] cp = UnicodeReader.toCodePointArray(value); + if (cp.length == 0) + throw new DatatypeException("invalid NCName value"); + // XXX XML 1.1 documents? + if (cp[0] == ':' || !XMLParser.isNameStartCharacter(cp[0], false)) + throw new DatatypeException(0, "invalid NCName value"); + for (int i = 1; i < cp.length; i++) + { + if (cp[i] == ':') + { + if (ci != -1 || (i + 1 == cp.length)) + throw new DatatypeException(i, "invalid NCName value"); + ci = i; + } + else if (!XMLParser.isNameCharacter(cp[i], false)) + throw new DatatypeException(i, "invalid NCName value"); + } + } + catch (IOException e) + { + DatatypeException e2 = new DatatypeException("invalid NCName value"); + e2.initCause(e); + throw e2; + } + if (ci != -1) + { + String prefix = value.substring(0, ci); + if (context.resolveNamespacePrefix(prefix) == null) + throw new DatatypeException("invalid namespace prefix"); + } + } + + public boolean isContextDependent() + { + return true; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/ShortType.java b/libjava/classpath/gnu/xml/validation/datatype/ShortType.java new file mode 100644 index 000000000..43255571d --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/ShortType.java @@ -0,0 +1,132 @@ +/* ShortType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema short type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class ShortType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "32767"; + static final String MIN_VALUE = "32768"; + static final int LENGTH = MAX_VALUE.length(); + + ShortType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "short"), + TypeLibrary.INT); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid short value"); + int i = 0, off = 0; + boolean compare = false; + String compareTo = MAX_VALUE; + char c = value.charAt(0); + if (c == '+') + i++; + else if (c == '-') + { + compareTo = MIN_VALUE; + i++; + } + if (len - i > LENGTH) + throw new DatatypeException(i, "invalid short value"); + else if (len - i == LENGTH) + compare = true; + for (; i < len; i++) + { + c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = compareTo.charAt(off); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid short value"); + } + off++; + continue; + } + throw new DatatypeException(i, "invalid short value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Short(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/SimpleType.java b/libjava/classpath/gnu/xml/validation/datatype/SimpleType.java new file mode 100644 index 000000000..1233723bd --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/SimpleType.java @@ -0,0 +1,255 @@ +/* SimpleType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Iterator; +import java.util.Set; +import java.util.regex.Matcher; +import javax.xml.namespace.QName; +import org.relaxng.datatype.Datatype; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.DatatypeStreamingValidator; +import org.relaxng.datatype.ValidationContext; + +/** + * An XML Schema simple type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class SimpleType + extends Type + implements Datatype +{ + + /** + * The variety of the <code>anySimpleType</code> datatype. + */ + public static final int ANY = 0; + + /** + * The atomic variety. + */ + public static final int ATOMIC = 1; + + /** + * The list variety. + */ + public static final int LIST = 2; + + /** + * The union variety. + */ + public static final int UNION = 3; + + public static final int ID_TYPE_NULL = 0; + public static final int ID_TYPE_ID = 1; + public static final int ID_TYPE_IDREF = 2; + public static final int ID_TYPE_IDREFS = 3; + + /** + * The variety of this simple type. + */ + public final int variety; + + /** + * The facets of this simple type. + */ + public Set facets; + + /** + * The fundamental facets of this simple type. + */ + public int fundamentalFacets; + + /** + * If this datatype has been derived by restriction, then the component + * from which it was derived. + */ + public final SimpleType baseType; + + /** + * Optional annotation. + */ + public final Annotation annotation; + + public SimpleType(QName name, int variety, Set facets, + int fundamentalFacets, SimpleType baseType, + Annotation annotation) + { + super(name); + this.variety = variety; + this.facets = facets; + this.fundamentalFacets = fundamentalFacets; + this.baseType = baseType; + this.annotation = annotation; + } + + /** + * Indicates whether this type permits the specified value. + */ + public boolean isValid(String value, ValidationContext context) + { + try + { + checkValid(value, context); + return true; + } + catch (DatatypeException e) + { + return false; + } + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + if (facets != null && !facets.isEmpty()) + { + Object parsedValue = createValue(value, context); + for (Iterator i = facets.iterator(); i.hasNext(); ) + { + Facet facet = (Facet) i.next(); + switch (facet.type) + { + case Facet.LENGTH: + LengthFacet lf = (LengthFacet) facet; + if (value.length() != lf.value) + throw new DatatypeException("invalid length"); + break; + case Facet.MIN_LENGTH: + MinLengthFacet nlf = (MinLengthFacet) facet; + if (value.length() < nlf.value) + throw new DatatypeException("invalid minimum length"); + break; + case Facet.MAX_LENGTH: + MaxLengthFacet xlf = (MaxLengthFacet) facet; + if (value.length() > xlf.value) + throw new DatatypeException("invalid maximum length"); + break; + case Facet.PATTERN: + PatternFacet pf = (PatternFacet) facet; + Matcher matcher = pf.value.matcher(value); + if (!matcher.find()) + throw new DatatypeException("invalid match for pattern"); + break; + case Facet.ENUMERATION: + // TODO + break; + case Facet.WHITESPACE: + // TODO + break; + case Facet.MAX_INCLUSIVE: + MaxInclusiveFacet xif = (MaxInclusiveFacet) facet; + if (!xif.matches(parsedValue)) + throw new DatatypeException("beyond upper bound"); + break; + case Facet.MAX_EXCLUSIVE: + MaxExclusiveFacet xef = (MaxExclusiveFacet) facet; + if (!xef.matches(parsedValue)) + throw new DatatypeException("beyond upper bound"); + break; + case Facet.MIN_EXCLUSIVE: + MinExclusiveFacet nef = (MinExclusiveFacet) facet; + if (!nef.matches(parsedValue)) + throw new DatatypeException("beyond lower bound"); + break; + case Facet.MIN_INCLUSIVE: + MinInclusiveFacet nif = (MinInclusiveFacet) facet; + if (!nif.matches(parsedValue)) + throw new DatatypeException("beyond lower bound"); + break; + case Facet.TOTAL_DIGITS: + TotalDigitsFacet tdf = (TotalDigitsFacet) facet; + if (countDigits(value, true) > tdf.value) + throw new DatatypeException("too many digits"); + break; + case Facet.FRACTION_DIGITS: + FractionDigitsFacet fdf = (FractionDigitsFacet) facet; + if (countDigits(value, false) > fdf.value) + throw new DatatypeException("too many fraction digits"); + break; + } + } + } + } + + private static int countDigits(String value, boolean any) + { + int count = 0; + int len = value.length(); + boolean seenDecimal = false; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == 0x2e) + seenDecimal = true; + else if (c >= 0x30 && c <= 0x39 && (any || seenDecimal)) + count++; + } + return count; + } + + // TODO createStreamingValidator + public DatatypeStreamingValidator createStreamingValidator(ValidationContext context) + { + throw new UnsupportedOperationException(); + } + + public Object createValue(String literal, ValidationContext context) { + return literal; + } + + public boolean sameValue(Object value1, Object value2) { + return value1.equals(value2); + } + + public int valueHashCode(Object value) { + return value.hashCode(); + } + + public int getIdType() + { + return ID_TYPE_NULL; + } + + public boolean isContextDependent() + { + return false; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/StringType.java b/libjava/classpath/gnu/xml/validation/datatype/StringType.java new file mode 100644 index 000000000..e20d1b87e --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/StringType.java @@ -0,0 +1,72 @@ +/* StringType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; + +/** + * The XML Schema string type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class StringType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + StringType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/TimeType.java b/libjava/classpath/gnu/xml/validation/datatype/TimeType.java new file mode 100644 index 000000000..83ada5bc6 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/TimeType.java @@ -0,0 +1,302 @@ +/* TimeType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.TimeZone; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema time type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class TimeType + extends AtomicSimpleType +{ + + static class Time + implements Comparable + { + int minutes; + float seconds; + + public int hashCode() + { + return minutes * 31 + new Float(seconds).hashCode(); + } + + public boolean equals(Object other) + { + if (other instanceof Time) + { + Time time = (Time) other; + return time.minutes == minutes && time.seconds == seconds; + } + return false; + } + + public int compareTo(Object other) + { + if (other instanceof Time) + { + Time time = (Time) other; + if (time.minutes != minutes) + return minutes - time.minutes; + if (time.seconds == seconds) + return 0; + return (seconds < time.seconds) ? -1 : 1; + } + return 0; + } + + } + + static final int[] CONSTRAINING_FACETS = { + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + TimeType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "time"), + TypeLibrary.ANY_SIMPLE_TYPE); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + int state = 3; + int start = 0; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == '-' && state == 0) + { + start++; + continue; + } + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 3: // hour + if (c == ':') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid time value"); + state = 4; + start = i + 1; + continue; + } + break; + case 4: // minute + if (c == ':') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid time value"); + state = 5; + start = i + 1; + continue; + } + break; + case 5: // second + if (c == '.') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid time value"); + state = 6; + start = i + 1; + continue; + } + else if (c == ' ') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid time value"); + state = 7; + start = i + 1; + continue; + } + break; + case 6: // second fraction + if (c == ' ') + { + state = 7; + start = i + 1; + continue; + } + break; + case 7: // timezone 1 + if (start == i) + { + if (c == '+' || c == '-') + continue; + else if (c == 'Z') + { + state = 9; + start = i + 1; + continue; + } + } + if (c == ':') + { + if (i - start != 2) + throw new DatatypeException(i, "invalid time value"); + state = 8; + start = i + 1; + continue; + } + break; + } + throw new DatatypeException(i, "invalid time value"); + } + switch (state) + { + case 5: // second + if (len - start != 2) + throw new DatatypeException(len, "invalid time value"); + break; + case 6: // second fraction + break; + case 8: // timezone 2 + if (len - start != 2) + throw new DatatypeException(len, "invalid time value"); + break; + case 9: // post Z + break; + default: + throw new DatatypeException(len, "invalid time value"); + } + } + + public Object createValue(String value, ValidationContext context) { + int len = value.length(); + int state = 3; + int start = 0; + Time time = new Time(); + try + { + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + continue; + switch (state) + { + case 3: // hour + if (c == ':') + { + time.minutes = + Integer.parseInt(value.substring(start, i)) * 60; + state = 4; + start = i + 1; + continue; + } + break; + case 4: // minute + if (c == ':') + { + time.minutes += + Integer.parseInt(value.substring(start, i)); + state = 5; + start = i + 1; + continue; + } + break; + case 5: // second + if (c == ' ') + { + time.seconds = + Float.parseFloat(value.substring(start, i)); + state = 7; + start = i + 1; + continue; + } + break; + } + } + // end of input + if (len - start > 0 && state == 7) + { + // Timezone + String timezone = value.substring(len - start); + int i = timezone.indexOf(':'); + if (i == -1) + { + if ("Z".equals(timezone)) + timezone = "UTC"; + TimeZone tz = TimeZone.getTimeZone(timezone); + if (tz == null) + return null; + time.minutes += tz.getRawOffset(); + } + else + { + String tzh = timezone.substring(0, i); + String tzm = timezone.substring(i + 1); + int offset = Integer.parseInt(tzh) * 60; + if (offset < 0) + offset -= Integer.parseInt(tzm); + else + offset += Integer.parseInt(tzm); + time.minutes += offset; + } + } + return time; + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/TokenType.java b/libjava/classpath/gnu/xml/validation/datatype/TokenType.java new file mode 100644 index 000000000..dfe5f14ce --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/TokenType.java @@ -0,0 +1,95 @@ +/* TokenType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema token type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class TokenType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.LENGTH, + Facet.MIN_LENGTH, + Facet.MAX_LENGTH, + Facet.PATTERN, + Facet.ENUMERATION, + Facet.WHITESPACE + }; + + TokenType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "token"), + TypeLibrary.NORMALIZED_STRING); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid token value"); + if (value.charAt(0) == ' ' || value.charAt(len - 1) == ' ') + throw new DatatypeException(0, "invalid token value"); + char last = '\u0000'; + for (int i = 0; i < len; i++) + { + char c = value.charAt(i); + if (c == 0x0a || c == 0x0d || c == 0x09) + throw new DatatypeException(i, "invalid token value"); + if (c == ' ' && last == ' ') + throw new DatatypeException(i, "invalid token value"); + last = c; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/TotalDigitsFacet.java b/libjava/classpath/gnu/xml/validation/datatype/TotalDigitsFacet.java new file mode 100644 index 000000000..25b50cd6f --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/TotalDigitsFacet.java @@ -0,0 +1,71 @@ +/* TotalDigitsFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>totalDigits</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class TotalDigitsFacet + extends Facet +{ + + public final int value; + + public final boolean fixed; + + public TotalDigitsFacet(int value, boolean fixed, Annotation annotation) + { + super(TOTAL_DIGITS, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value; + } + + public boolean equals(Object other) + { + return (other instanceof TotalDigitsFacet && + ((TotalDigitsFacet) other).value == value); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/Type.java b/libjava/classpath/gnu/xml/validation/datatype/Type.java new file mode 100644 index 000000000..ebd650933 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/Type.java @@ -0,0 +1,62 @@ +/* Type.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.namespace.QName; +/** + * Abstract base class for XML Schema datatypes. + * @see http://www.w3.org/TR/xmlschema-2/ + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public abstract class Type +{ + + public static final Type ANY_TYPE = new AnyType(); + + /** + * The name of this type. + */ + public final QName name; + + public Type(QName name) + { + this.name = name; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/TypeBuilder.java b/libjava/classpath/gnu/xml/validation/datatype/TypeBuilder.java new file mode 100644 index 000000000..087333153 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/TypeBuilder.java @@ -0,0 +1,278 @@ +/* TypeBuilder.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.LinkedHashSet; +import java.util.regex.Pattern; +import org.relaxng.datatype.Datatype; +import org.relaxng.datatype.DatatypeBuilder; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * Datatype builder. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class TypeBuilder + implements DatatypeBuilder +{ + + final SimpleType type; + + TypeBuilder(SimpleType type) + { + this.type = type; + // TODO fundamental facets + type.facets = new LinkedHashSet(); + } + + public void addParameter(String name, String value, ValidationContext context) + throws DatatypeException + { + // TODO fundamental facets + if ("length".equals(name)) + type.facets.add(parseLengthFacet(value)); + else if ("minLength".equals(name)) + type.facets.add(parseMinLengthFacet(value)); + else if ("maxLength".equals(name)) + type.facets.add(parseMaxLengthFacet(value)); + else if ("pattern".equals(name)) + type.facets.add(parsePatternFacet(value)); + else if ("enumeration".equals(name)) + type.facets.add(parseEnumerationFacet(value)); + else if ("whiteSpace".equals(name)) + type.facets.add(parseWhiteSpaceFacet(value)); + else if ("maxInclusive".equals(name)) + type.facets.add(parseMaxInclusiveFacet(value, context)); + else if ("maxExclusive".equals(name)) + type.facets.add(parseMaxExclusiveFacet(value, context)); + else if ("minExclusive".equals(name)) + type.facets.add(parseMinExclusiveFacet(value, context)); + else if ("minInclusive".equals(name)) + type.facets.add(parseMinInclusiveFacet(value, context)); + else if ("totalDigits".equals(name)) + type.facets.add(parseTotalDigitsFacet(value)); + else if ("fractionDigits".equals(name)) + type.facets.add(parseFractionDigitsFacet(value)); + } + + LengthFacet parseLengthFacet(String value) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new LengthFacet(Integer.parseInt(value), fixed, null); + } + + MinLengthFacet parseMinLengthFacet(String value) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new MinLengthFacet(Integer.parseInt(value), fixed, null); + } + + MaxLengthFacet parseMaxLengthFacet(String value) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new MaxLengthFacet(Integer.parseInt(value), fixed, null); + } + + PatternFacet parsePatternFacet(String value) + throws DatatypeException + { + return new PatternFacet(Pattern.compile(value), null); + } + + EnumerationFacet parseEnumerationFacet(String value) + throws DatatypeException + { + return new EnumerationFacet(value, null); + } + + WhiteSpaceFacet parseWhiteSpaceFacet(String value) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + if ("preserve".equals(value)) + return new WhiteSpaceFacet(WhiteSpaceFacet.PRESERVE, fixed, null); + if ("replace".equals(value)) + return new WhiteSpaceFacet(WhiteSpaceFacet.REPLACE, fixed, null); + if ("collapse".equals(value)) + return new WhiteSpaceFacet(WhiteSpaceFacet.COLLAPSE, fixed, null); + throw new DatatypeException("argument must be preserve, replace, or collapse"); + } + + MaxInclusiveFacet parseMaxInclusiveFacet(String value, + ValidationContext context) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new MaxInclusiveFacet(type.createValue(value, context), fixed, null); + } + + MaxExclusiveFacet parseMaxExclusiveFacet(String value, + ValidationContext context) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new MaxExclusiveFacet(type.createValue(value, context), fixed, null); + } + + MinExclusiveFacet parseMinExclusiveFacet(String value, + ValidationContext context) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new MinExclusiveFacet(type.createValue(value, context), fixed, null); + } + + MinInclusiveFacet parseMinInclusiveFacet(String value, + ValidationContext context) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + return new MinInclusiveFacet(type.createValue(value, context), fixed, null); + } + + TotalDigitsFacet parseTotalDigitsFacet(String value) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + int val = Integer.parseInt(value); + if (val < 0) + throw new DatatypeException("value must be a positiveInteger"); + return new TotalDigitsFacet(val, fixed, null); + } + + FractionDigitsFacet parseFractionDigitsFacet(String value) + throws DatatypeException + { + int si = value.indexOf(' '); + boolean fixed = false; + if (si != -1) + { + if (!"FIXED".equalsIgnoreCase(value.substring(si + 1))) + throw new DatatypeException("second argument must be FIXED if present"); + fixed = true; + value = value.substring(0, si); + } + int val = Integer.parseInt(value); + if (val < 0) + throw new DatatypeException("value must be a positiveInteger"); + return new FractionDigitsFacet(val, fixed, null); + } + + public Datatype createDatatype() + { + return type; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/TypeLibrary.java b/libjava/classpath/gnu/xml/validation/datatype/TypeLibrary.java new file mode 100644 index 000000000..4db48f799 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/TypeLibrary.java @@ -0,0 +1,173 @@ +/* TypeLibrary.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.HashMap; +import java.util.Map; +import org.relaxng.datatype.Datatype; +import org.relaxng.datatype.DatatypeBuilder; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.DatatypeLibrary; + +/** + * Datatype library for XML Schema datatypes. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class TypeLibrary + implements DatatypeLibrary +{ + + public static final SimpleType ANY_SIMPLE_TYPE = new AnySimpleType(); + + public static final SimpleType STRING = new StringType(); + public static final SimpleType BOOLEAN = new BooleanType(); + public static final SimpleType DECIMAL = new DecimalType(); + public static final SimpleType FLOAT = new FloatType(); + public static final SimpleType DOUBLE = new DoubleType(); + public static final SimpleType DURATION = new DurationType(); + public static final SimpleType DATE_TIME = new DateTimeType(); + public static final SimpleType TIME = new TimeType(); + public static final SimpleType DATE = new DateType(); + public static final SimpleType G_YEAR_MONTH = new GYearMonthType(); + public static final SimpleType G_YEAR = new GYearType(); + public static final SimpleType G_MONTH_DAY = new GMonthDayType(); + public static final SimpleType G_DAY = new GDayType(); + public static final SimpleType G_MONTH = new GMonthType(); + public static final SimpleType HEX_BINARY = new HexBinaryType(); + public static final SimpleType BASE64_BINARY = new Base64BinaryType(); + public static final SimpleType ANY_URI = new AnyURIType(); + public static final SimpleType QNAME = new QNameType(); + public static final SimpleType NOTATION = new NotationType(); + + public static final SimpleType NORMALIZED_STRING = new NormalizedStringType(); + public static final SimpleType TOKEN = new TokenType(); + public static final SimpleType LANGUAGE = new LanguageType(); + public static final SimpleType NMTOKEN = new NMTokenType(); + public static final SimpleType NMTOKENS = new NMTokensType(); + public static final SimpleType NAME = new NameType(); + public static final SimpleType NCNAME = new NCNameType(); + public static final SimpleType ID = new IDType(); + public static final SimpleType IDREF = new IDRefType(); + public static final SimpleType IDREFS = new IDRefsType(); + public static final SimpleType ENTITY = new EntityType(); + public static final SimpleType ENTITIES = new EntitiesType(); + public static final SimpleType INTEGER = new IntegerType(); + public static final SimpleType NON_POSITIVE_INTEGER = new NonPositiveIntegerType(); + public static final SimpleType NEGATIVE_INTEGER = new NegativeIntegerType(); + public static final SimpleType LONG = new LongType(); + public static final SimpleType INT = new IntType(); + public static final SimpleType SHORT = new ShortType(); + public static final SimpleType BYTE = new ByteType(); + public static final SimpleType NON_NEGATIVE_INTEGER = new NonNegativeIntegerType(); + public static final SimpleType UNSIGNED_LONG = new UnsignedLongType(); + public static final SimpleType UNSIGNED_INT = new UnsignedIntType(); + public static final SimpleType UNSIGNED_SHORT = new UnsignedShortType(); + public static final SimpleType UNSIGNED_BYTE = new UnsignedByteType(); + public static final SimpleType POSITIVE_INTEGER = new PositiveIntegerType(); + + private static Map byName; + static + { + byName = new HashMap(); + byName.put("anySimpleType", ANY_SIMPLE_TYPE); + byName.put("string", STRING); + byName.put("boolean", BOOLEAN); + byName.put("decimal", DECIMAL); + byName.put("float", FLOAT); + byName.put("double", DOUBLE); + byName.put("duration", DURATION); + byName.put("dateTime", DATE_TIME); + byName.put("time", TIME); + byName.put("date", DATE); + byName.put("gYearMonth", G_YEAR_MONTH); + byName.put("gYear", G_YEAR); + byName.put("gMonthDay", G_MONTH_DAY); + byName.put("gDay", G_DAY); + byName.put("gMonth",G_MONTH); + byName.put("hexBinary", HEX_BINARY); + byName.put("base64Binary", BASE64_BINARY); + byName.put("anyURI", ANY_URI); + byName.put("QName", QNAME); + byName.put("NOTATION", NOTATION); + byName.put("normalizedString", NORMALIZED_STRING); + byName.put("token", TOKEN); + byName.put("language", LANGUAGE); + byName.put("NMTOKEN", NMTOKEN); + byName.put("NMTOKENS", NMTOKENS); + byName.put("Name", NAME); + byName.put("NCName", NCNAME); + byName.put("ID", ID); + byName.put("IDREF", IDREF); + byName.put("IDREFS", IDREFS); + byName.put("ENTITY", ENTITY); + byName.put("ENTITIES", ENTITIES); + byName.put("integer", INTEGER); + byName.put("nonPositiveInteger", NON_POSITIVE_INTEGER); + byName.put("negativeInteger", NEGATIVE_INTEGER); + byName.put("long", LONG); + byName.put("int", INT); + byName.put("short", SHORT); + byName.put("byte", BYTE); + byName.put("nonNegativeInteger", NON_NEGATIVE_INTEGER); + byName.put("unsignedLong", UNSIGNED_LONG); + byName.put("unsignedInt", UNSIGNED_INT); + byName.put("unsignedShort", UNSIGNED_SHORT); + byName.put("unsignedByte", UNSIGNED_BYTE); + byName.put("positiveInteger", POSITIVE_INTEGER); + } + + public DatatypeBuilder createDatatypeBuilder(String baseTypeLocalName) + throws DatatypeException + { + SimpleType type = (SimpleType) byName.get(baseTypeLocalName); + if (type == null) + throw new DatatypeException("Unknown type name: " + baseTypeLocalName); + return new TypeBuilder(type); + } + + public Datatype createDatatype(String typeLocalName) + throws DatatypeException + { + SimpleType type = (SimpleType) byName.get(typeLocalName); + if (type == null) + throw new DatatypeException("Unknown type name: " + typeLocalName); + return type; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/TypeLibraryFactory.java b/libjava/classpath/gnu/xml/validation/datatype/TypeLibraryFactory.java new file mode 100644 index 000000000..2f9bbd3c6 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/TypeLibraryFactory.java @@ -0,0 +1,60 @@ +/* TypeLibraryFactory.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import org.relaxng.datatype.DatatypeLibrary; +import org.relaxng.datatype.DatatypeLibraryFactory; + +/** + * Datatype library factory for XML Schema datatypes. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class TypeLibraryFactory + implements DatatypeLibraryFactory +{ + + public DatatypeLibrary createDatatypeLibrary(String namespaceURI) + { + if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(namespaceURI)) + return new TypeLibrary(); + return null; + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/UnionSimpleType.java b/libjava/classpath/gnu/xml/validation/datatype/UnionSimpleType.java new file mode 100644 index 000000000..253e1df7b --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/UnionSimpleType.java @@ -0,0 +1,82 @@ +/* UnionSimpleType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * An XML Schema union simple type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public class UnionSimpleType + extends SimpleType +{ + + /** + * The member types in this union. + */ + public final List memberTypes; + + public UnionSimpleType(QName name, Set facets, + int fundamentalFacets, SimpleType baseType, + Annotation annotation, List memberTypes) + { + super(name, UNION, facets, fundamentalFacets, baseType, annotation); + this.memberTypes = memberTypes; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + for (Iterator i = memberTypes.iterator(); i.hasNext(); ) + { + SimpleType type = (SimpleType) i.next(); + if (type.isValid(value, context)) + return; + } + throw new DatatypeException("invalid union type value"); + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/UnsignedByteType.java b/libjava/classpath/gnu/xml/validation/datatype/UnsignedByteType.java new file mode 100644 index 000000000..cf12abe3a --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/UnsignedByteType.java @@ -0,0 +1,120 @@ +/* UnsignedByteType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema unsignedByte type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class UnsignedByteType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "255"; + static final int LENGTH = MAX_VALUE.length(); + + UnsignedByteType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "unsignedByte"), + TypeLibrary.UNSIGNED_SHORT); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid unsigned byte value"); + boolean compare = false; + for (int i = 0; i < len; i++) + { + if (len - i > LENGTH) + throw new DatatypeException(i, "invalid unsigned byte value"); + else if (len - i == LENGTH) + compare = true; + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = MAX_VALUE.charAt(i); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid unsigned byte value"); + } + continue; + } + throw new DatatypeException(i, "invalid unsigned byte value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Byte(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/UnsignedIntType.java b/libjava/classpath/gnu/xml/validation/datatype/UnsignedIntType.java new file mode 100644 index 000000000..b634442bb --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/UnsignedIntType.java @@ -0,0 +1,120 @@ +/* UnsignedIntType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema unsignedInt type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class UnsignedIntType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "4294967295"; + static final int LENGTH = MAX_VALUE.length(); + + UnsignedIntType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "unsignedInt"), + TypeLibrary.UNSIGNED_LONG); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid unsigned int value"); + boolean compare = false; + for (int i = 0; i < len; i++) + { + if (len - i > LENGTH) + throw new DatatypeException(i, "invalid unsigned int value"); + else if (len - i == LENGTH) + compare = true; + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = MAX_VALUE.charAt(i); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid unsigned int value"); + } + continue; + } + throw new DatatypeException(i, "invalid unsigned int value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Integer(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/UnsignedLongType.java b/libjava/classpath/gnu/xml/validation/datatype/UnsignedLongType.java new file mode 100644 index 000000000..784b86663 --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/UnsignedLongType.java @@ -0,0 +1,120 @@ +/* UnsignedLongType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema unsignedLong type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class UnsignedLongType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "18446744073709551615"; + static final int LENGTH = MAX_VALUE.length(); + + UnsignedLongType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "unsignedLong"), + TypeLibrary.NON_NEGATIVE_INTEGER); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid unsigned long value"); + boolean compare = false; + for (int i = 0; i < len; i++) + { + if (len - i > LENGTH) + throw new DatatypeException(i, "invalid unsigned long value"); + else if (len - i == LENGTH) + compare = true; + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = MAX_VALUE.charAt(i); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, "invalid unsigned long value"); + } + continue; + } + throw new DatatypeException(i, "invalid unsigned long value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Long(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/UnsignedShortType.java b/libjava/classpath/gnu/xml/validation/datatype/UnsignedShortType.java new file mode 100644 index 000000000..ececb608c --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/UnsignedShortType.java @@ -0,0 +1,121 @@ +/* UnsignedShortType.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import org.relaxng.datatype.DatatypeException; +import org.relaxng.datatype.ValidationContext; + +/** + * The XML Schema unsignedShort type. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +final class UnsignedShortType + extends AtomicSimpleType +{ + + static final int[] CONSTRAINING_FACETS = { + Facet.TOTAL_DIGITS, + Facet.FRACTION_DIGITS, + Facet.PATTERN, + Facet.WHITESPACE, + Facet.ENUMERATION, + Facet.MAX_INCLUSIVE, + Facet.MAX_EXCLUSIVE, + Facet.MIN_INCLUSIVE, + Facet.MIN_EXCLUSIVE + }; + + static final String MAX_VALUE = "65535"; + static final int LENGTH = MAX_VALUE.length(); + + UnsignedShortType() + { + super(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "unsignedShort"), + TypeLibrary.UNSIGNED_INT); + } + + public int[] getConstrainingFacets() + { + return CONSTRAINING_FACETS; + } + + public void checkValid(String value, ValidationContext context) + throws DatatypeException + { + super.checkValid(value, context); + int len = value.length(); + if (len == 0) + throw new DatatypeException(0, "invalid unsigned short value"); + boolean compare = false; + for (int i = 0; i < len; i++) + { + if (len - i > LENGTH) + throw new DatatypeException(i, "invalid unsigned short value"); + else if (len - i == LENGTH) + compare = true; + char c = value.charAt(i); + if (c >= 0x30 && c <= 0x39) + { + if (compare) + { + char d = MAX_VALUE.charAt(i); + if (Character.digit(c, 10) > Character.digit(d, 10)) + throw new DatatypeException(i, + "invalid unsigned short value"); + } + continue; + } + throw new DatatypeException(i, "invalid unsigned short value"); + } + } + + public Object createValue(String literal, ValidationContext context) { + try + { + return new Short(literal); + } + catch (NumberFormatException e) + { + return null; + } + } + +} diff --git a/libjava/classpath/gnu/xml/validation/datatype/WhiteSpaceFacet.java b/libjava/classpath/gnu/xml/validation/datatype/WhiteSpaceFacet.java new file mode 100644 index 000000000..0f2109cfc --- /dev/null +++ b/libjava/classpath/gnu/xml/validation/datatype/WhiteSpaceFacet.java @@ -0,0 +1,74 @@ +/* WhiteSpaceFacet.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.validation.datatype; + +/** + * The <code>whiteSpace</code> facet. + * + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> + */ +public final class WhiteSpaceFacet + extends Facet +{ + + public static final int PRESERVE = 0; + public static final int REPLACE = 1; + public static final int COLLAPSE = 2; + + public final int value; + public final boolean fixed; + + public WhiteSpaceFacet(int value, boolean fixed, Annotation annotation) + { + super(WHITESPACE, annotation); + this.value = value; + this.fixed = fixed; + } + + public int hashCode() + { + return value; + } + + public boolean equals(Object other) + { + return (other instanceof WhiteSpaceFacet && + ((WhiteSpaceFacet) other).value == value); + } + +} |