Class XMLDatatypes


  • public final class XMLDatatypes
    extends java.lang.Object

    Utility for XML schema datatypes

    Since:
    1.0
    Version:
    1.0
    Author:
    Arjohn Kampman, Michael Grove
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String collapseWhiteSpace​(java.lang.String s)
      Replaces all contiguous sequences of #x9 (tab), #xA (line feed) and #xD (carriage return) with a single #x20 (space) character, and removes any leading and trailing whitespace characters, as specified for whiteSpace facet collapse.
      static int compareCanonicalDecimals​(java.lang.String dec1, java.lang.String dec2)
      Compares two canonical decimals to eachother.
      static int compareCanonicalIntegers​(java.lang.String int1, java.lang.String int2)
      Compares two canonical integers to eachother.
      static boolean isBuiltInDatatype​(Datatype theDatatype)
      Return whether or not the Datatype is a built-in XML schema type.
      static boolean isBuiltInDatatype​(IRI theIRI)
      Return whether or not the IRI is a built-in XML schema type.
      static boolean isCalendarDatatype​(Datatype theDatatype)
      Return whether or not the Datatype is an XML datatype calendar type
      static boolean isDecimalDatatype​(Datatype theDatatype)
      Return whether or not the Datatype is `xsd:decimal` or derived from it
      static boolean isDurationDatatype​(Datatype theDatatype)  
      static boolean isFloatingPointDatatype​(Datatype theDatatype)  
      static boolean isIntegerDatatype​(Datatype theDatatype)
      Return whether or not the Datatype is `xsd:integer` or derived from it
      static boolean isNumericDatatype​(Datatype theDatatype)
      Return whether or not the Datatype is a numeric datatype such as `xsd:long` or `xsd:decimal`.
      static boolean isPrimitiveDatatype​(Datatype theDatatype)
      Return whether or not the Datatype is a primitive XML schema type.
      static boolean isValidBoolean​(java.lang.String value)  
      static boolean isValidByte​(java.lang.String value)  
      static boolean isValidDate​(java.lang.String value)
      Determines if the supplied value is a valid xsd:date string.
      static boolean isValidDateTime​(java.lang.String value)  
      static boolean isValidDayTimeDuration​(java.lang.String value)  
      static boolean isValidDecimal​(java.lang.String value)  
      static boolean isValidDouble​(java.lang.String value)  
      static boolean isValidDuration​(java.lang.String value)  
      static boolean isValidFloat​(java.lang.String value)  
      static boolean isValidGDay​(java.lang.String value)
      Determines if the supplied value is a valid xsd:gDay string.
      static boolean isValidGMonth​(java.lang.String value)
      Determines if the supplied value is a valid xsd:gMonth string.
      static boolean isValidGMonthDay​(java.lang.String value)
      Determines if the supplied value is a valid xsd:gMonthDay string.
      static boolean isValidGYear​(java.lang.String value)
      Determines if the supplied value is a valid xsd:gYear string.
      static boolean isValidGYearMonth​(java.lang.String value)
      Determines if the supplied value is a valid xsd:gYearMonth string.
      static boolean isValidInt​(java.lang.String value)  
      static boolean isValidInteger​(java.lang.String value)  
      static boolean isValidLong​(java.lang.String value)  
      static boolean isValidNegativeInteger​(java.lang.String value)  
      static boolean isValidNonNegativeInteger​(java.lang.String value)  
      static boolean isValidNonPositiveInteger​(java.lang.String value)  
      static boolean isValidPositiveInteger​(java.lang.String value)  
      static boolean isValidQName​(java.lang.String value)
      Determines if the supplied value is a valid xsd:QName string.
      static boolean isValidShort​(java.lang.String value)  
      static boolean isValidTime​(java.lang.String value)
      Determines if the supplied value is a valid xsd:time string.
      static boolean isValidUnsignedByte​(java.lang.String value)  
      static boolean isValidUnsignedInt​(java.lang.String value)  
      static boolean isValidUnsignedLong​(java.lang.String value)  
      static boolean isValidUnsignedShort​(java.lang.String value)  
      static boolean isValidValue​(Literal theLiteral)
      Verifies if the supplied lexical value is valid for the given literal.
      static boolean isValidValue​(java.lang.String theValue, Datatype theDatatype)
      Verifies if the supplied lexical value is valid for the given datatype.
      static java.lang.String normalize​(java.lang.String value, Datatype datatype)
      Normalizes the supplied value according to the normalization rules for the supplied datatype.
      static java.lang.String normalizeBoolean​(java.lang.String theValue)
      Normalizes a boolean value to its canonical representation.
      static java.lang.String normalizeByte​(java.lang.String value)
      Normalizes an xsd:byte.
      static java.lang.String normalizeDateTime​(java.lang.String value)
      Normalizes an xsd:dateTime.
      static java.lang.String normalizeDecimal​(java.lang.String decimal)
      Normalizes a decimal to its canonical representation.
      static java.lang.String normalizeDouble​(java.lang.String value)
      Normalizes a double to its canonical representation.
      static java.lang.String normalizeFloat​(java.lang.String value)
      Normalizes a float to its canonical representation.
      static java.lang.String normalizeInt​(java.lang.String value)
      Normalizes an xsd:int.
      static java.lang.String normalizeInteger​(java.lang.String value)
      Normalizes an integer to its canonical representation.
      static java.lang.String normalizeLong​(java.lang.String value)
      Normalizes an xsd:long.
      static java.lang.String normalizeNegativeInteger​(java.lang.String value)
      Normalizes an xsd:negativeInteger.
      static java.lang.String normalizeNonNegativeInteger​(java.lang.String value)
      Normalizes an xsd:nonNegativeInteger.
      static java.lang.String normalizeNonPositiveInteger​(java.lang.String value)
      Normalizes an xsd:nonPositiveInteger.
      static java.lang.String normalizePositiveInteger​(java.lang.String value)
      Normalizes an xsd:positiveInteger.
      static java.lang.String normalizeShort​(java.lang.String value)
      Normalizes an xsd:short.
      static java.lang.String normalizeUnsignedByte​(java.lang.String value)
      Normalizes an xsd:unsignedByte.
      static java.lang.String normalizeUnsignedInt​(java.lang.String value)
      Normalizes an xsd:unsignedInt.
      static java.lang.String normalizeUnsignedLong​(java.lang.String value)
      Normalizes an xsd:unsignedLong.
      static java.lang.String normalizeUnsignedShort​(java.lang.String value)
      Normalizes an xsd:unsignedShort.
      static javax.xml.datatype.XMLGregorianCalendar parseCalendar​(java.lang.String s)
      Parses the supplied calendar value string and returns its value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isPrimitiveDatatype

        public static boolean isPrimitiveDatatype​(@Nonnull
                                                  Datatype theDatatype)
        Return whether or not the Datatype is a primitive XML schema type.
        Parameters:
        theDatatype - the datatype
        Returns:
        `true` if a built-in type, `false` otherwise
      • isCalendarDatatype

        public static boolean isCalendarDatatype​(@Nonnull
                                                 Datatype theDatatype)
        Return whether or not the Datatype is an XML datatype calendar type
        Parameters:
        theDatatype - the datatype
        Returns:
        `true` if a calendar type, `false` otherwise
      • isBuiltInDatatype

        public static boolean isBuiltInDatatype​(@Nonnull
                                                IRI theIRI)
        Return whether or not the IRI is a built-in XML schema type.
        Parameters:
        theIRI - the datatype theIRI
        Returns:
        `true` if a built-in type, `false` otherwise
      • isBuiltInDatatype

        public static boolean isBuiltInDatatype​(@Nonnull
                                                Datatype theDatatype)
        Return whether or not the Datatype is a built-in XML schema type.
        Parameters:
        theDatatype - the datatype
        Returns:
        `true` if a built-in type, `false` otherwise
      • isNumericDatatype

        public static boolean isNumericDatatype​(@Nonnull
                                                Datatype theDatatype)
        Return whether or not the Datatype is a numeric datatype such as `xsd:long` or `xsd:decimal`.
        Parameters:
        theDatatype - the datatype
        Returns:
        `true` if a numeric type, `false` otherwise
      • isDecimalDatatype

        public static boolean isDecimalDatatype​(@Nonnull
                                                Datatype theDatatype)
        Return whether or not the Datatype is `xsd:decimal` or derived from it
        Parameters:
        theDatatype - the datatype
        Returns:
        `true` if a decimal type, `false` otherwise
      • isDurationDatatype

        public static boolean isDurationDatatype​(@Nonnull
                                                 Datatype theDatatype)
      • isIntegerDatatype

        public static boolean isIntegerDatatype​(@Nonnull
                                                Datatype theDatatype)
        Return whether or not the Datatype is `xsd:integer` or derived from it
        Parameters:
        theDatatype - the datatype
        Returns:
        `true` if a integer type, `false` otherwise
      • isFloatingPointDatatype

        public static boolean isFloatingPointDatatype​(@Nonnull
                                                      Datatype theDatatype)
      • isValidValue

        public static boolean isValidValue​(@Nonnull
                                           Literal theLiteral)
        Verifies if the supplied lexical value is valid for the given literal.
        Parameters:
        theLiteral - the literal
        Returns:
        `true` if the supplied lexical value is valid, `false` otherwise.
      • isValidValue

        public static boolean isValidValue​(@Nonnull
                                           java.lang.String theValue,
                                           @Nonnull
                                           Datatype theDatatype)
        Verifies if the supplied lexical value is valid for the given datatype.
        Parameters:
        theValue - a lexical value
        theDatatype - an XML Schema datatatype.
        Returns:
        `true` if the supplied lexical value is valid, `false` otherwise.
      • isValidDecimal

        public static boolean isValidDecimal​(java.lang.String value)
      • isValidInteger

        public static boolean isValidInteger​(java.lang.String value)
      • isValidNegativeInteger

        public static boolean isValidNegativeInteger​(java.lang.String value)
      • isValidNonPositiveInteger

        public static boolean isValidNonPositiveInteger​(java.lang.String value)
      • isValidNonNegativeInteger

        public static boolean isValidNonNegativeInteger​(java.lang.String value)
      • isValidPositiveInteger

        public static boolean isValidPositiveInteger​(java.lang.String value)
      • isValidLong

        public static boolean isValidLong​(java.lang.String value)
      • isValidInt

        public static boolean isValidInt​(java.lang.String value)
      • isValidShort

        public static boolean isValidShort​(java.lang.String value)
      • isValidByte

        public static boolean isValidByte​(java.lang.String value)
      • isValidUnsignedLong

        public static boolean isValidUnsignedLong​(java.lang.String value)
      • isValidUnsignedInt

        public static boolean isValidUnsignedInt​(java.lang.String value)
      • isValidUnsignedShort

        public static boolean isValidUnsignedShort​(java.lang.String value)
      • isValidUnsignedByte

        public static boolean isValidUnsignedByte​(java.lang.String value)
      • isValidFloat

        public static boolean isValidFloat​(java.lang.String value)
      • isValidDouble

        public static boolean isValidDouble​(java.lang.String value)
      • isValidBoolean

        public static boolean isValidBoolean​(java.lang.String value)
      • isValidDuration

        public static boolean isValidDuration​(java.lang.String value)
      • isValidDayTimeDuration

        public static boolean isValidDayTimeDuration​(java.lang.String value)
      • isValidDateTime

        public static boolean isValidDateTime​(java.lang.String value)
      • isValidDate

        public static boolean isValidDate​(java.lang.String value)
        Determines if the supplied value is a valid xsd:date string.
        Parameters:
        value - the date
        Returns:
        `true` if valid, `false` otherwise
      • isValidTime

        public static boolean isValidTime​(java.lang.String value)
        Determines if the supplied value is a valid xsd:time string.
        Parameters:
        value - the time
        Returns:
        `true` if valid, `false` otherwise
      • isValidGDay

        public static boolean isValidGDay​(java.lang.String value)
        Determines if the supplied value is a valid xsd:gDay string.
        Parameters:
        value - the gday
        Returns:
        `true` if valid, `false` otherwise
      • isValidGMonth

        public static boolean isValidGMonth​(java.lang.String value)
        Determines if the supplied value is a valid xsd:gMonth string.
        Parameters:
        value - the gmonth
        Returns:
        `true` if valid, `false` otherwise
      • isValidGMonthDay

        public static boolean isValidGMonthDay​(java.lang.String value)
        Determines if the supplied value is a valid xsd:gMonthDay string.
        Parameters:
        value - the gmonthday
        Returns:
        `true` if valid, `false` otherwise
      • isValidGYear

        public static boolean isValidGYear​(java.lang.String value)
        Determines if the supplied value is a valid xsd:gYear string.
        Parameters:
        value - the value
        Returns:
        `true` if valid, `false` otherwise
      • isValidGYearMonth

        public static boolean isValidGYearMonth​(java.lang.String value)
        Determines if the supplied value is a valid xsd:gYearMonth string.
        Parameters:
        value - the value
        Returns:
        `true` if valid, `false` otherwise
      • isValidQName

        public static boolean isValidQName​(java.lang.String value)
        Determines if the supplied value is a valid xsd:QName string. Note that this method only checks for syntax errors in the supplied string itself. It does not validate that the prefix is a declared and in-scope namespace prefix.
        Parameters:
        value - the qname
        Returns:
        `true` if valid, `false` otherwise
      • normalize

        public static java.lang.String normalize​(java.lang.String value,
                                                 Datatype datatype)
        Normalizes the supplied value according to the normalization rules for the supplied datatype.
        Parameters:
        value - The value to normalize.
        datatype - The value's datatype.
        Returns:
        The normalized value if there are any (supported) normalization rules for the supplied datatype, or the original supplied value otherwise.
        Throws:
        java.lang.IllegalArgumentException - If the supplied value is illegal considering the supplied datatype.
      • normalizeBoolean

        public static java.lang.String normalizeBoolean​(java.lang.String theValue)
        Normalizes a boolean value to its canonical representation. More specifically, the values 1 and 0 will be normalized to the canonical values `true` and `false`, respectively. Supplied canonical values will remain as is.
        Parameters:
        theValue - The boolean value to normalize.
        Returns:
        The normalized value.
        Throws:
        java.lang.IllegalArgumentException - If the supplied value is not a legal boolean.
      • normalizeDecimal

        public static java.lang.String normalizeDecimal​(java.lang.String decimal)
        Normalizes a decimal to its canonical representation. For example: 120 becomes 120.0, +.3 becomes 0.3, 00012.45000 becomes 12.45 and -.0 becomes 0.0.
        Parameters:
        decimal - The decimal to normalize.
        Returns:
        The canonical representation of decimal.
        Throws:
        java.lang.IllegalArgumentException - If one of the supplied strings is not a legal decimal.
      • normalizeInteger

        public static java.lang.String normalizeInteger​(java.lang.String value)
        Normalizes an integer to its canonical representation. For example: +120 becomes 120 and 00012 becomes 12.
        Parameters:
        value - The value to normalize.
        Returns:
        The canonical representation of value.
        Throws:
        java.lang.IllegalArgumentException - If the supplied value is not a legal integer.
      • normalizeNegativeInteger

        public static java.lang.String normalizeNegativeInteger​(java.lang.String value)
        Normalizes an xsd:negativeInteger.
      • normalizeNonPositiveInteger

        public static java.lang.String normalizeNonPositiveInteger​(java.lang.String value)
        Normalizes an xsd:nonPositiveInteger.
      • normalizeNonNegativeInteger

        public static java.lang.String normalizeNonNegativeInteger​(java.lang.String value)
        Normalizes an xsd:nonNegativeInteger.
      • normalizePositiveInteger

        public static java.lang.String normalizePositiveInteger​(java.lang.String value)
        Normalizes an xsd:positiveInteger.
      • normalizeLong

        public static java.lang.String normalizeLong​(java.lang.String value)
        Normalizes an xsd:long.
      • normalizeInt

        public static java.lang.String normalizeInt​(java.lang.String value)
        Normalizes an xsd:int.
      • normalizeShort

        public static java.lang.String normalizeShort​(java.lang.String value)
        Normalizes an xsd:short.
      • normalizeByte

        public static java.lang.String normalizeByte​(java.lang.String value)
        Normalizes an xsd:byte.
      • normalizeUnsignedLong

        public static java.lang.String normalizeUnsignedLong​(java.lang.String value)
        Normalizes an xsd:unsignedLong.
      • normalizeUnsignedInt

        public static java.lang.String normalizeUnsignedInt​(java.lang.String value)
        Normalizes an xsd:unsignedInt.
      • normalizeUnsignedShort

        public static java.lang.String normalizeUnsignedShort​(java.lang.String value)
        Normalizes an xsd:unsignedShort.
      • normalizeUnsignedByte

        public static java.lang.String normalizeUnsignedByte​(java.lang.String value)
        Normalizes an xsd:unsignedByte.
      • normalizeFloat

        public static java.lang.String normalizeFloat​(java.lang.String value)
        Normalizes a float to its canonical representation.
        Parameters:
        value - The value to normalize.
        Returns:
        The canonical representation of value.
        Throws:
        java.lang.IllegalArgumentException - If the supplied value is not a legal float.
      • normalizeDouble

        public static java.lang.String normalizeDouble​(java.lang.String value)
        Normalizes a double to its canonical representation.
        Parameters:
        value - The value to normalize.
        Returns:
        The canonical representation of value.
        Throws:
        java.lang.IllegalArgumentException - If the supplied value is not a legal double.
      • normalizeDateTime

        public static java.lang.String normalizeDateTime​(java.lang.String value)
        Normalizes an xsd:dateTime.
        Parameters:
        value - The value to normalize.
        Returns:
        The normalized value.
        Throws:
        java.lang.IllegalArgumentException - If the supplied value is not a legal xsd:dateTime value.
      • collapseWhiteSpace

        public static java.lang.String collapseWhiteSpace​(java.lang.String s)
        Replaces all contiguous sequences of #x9 (tab), #xA (line feed) and #xD (carriage return) with a single #x20 (space) character, and removes any leading and trailing whitespace characters, as specified for whiteSpace facet collapse.
      • compareCanonicalDecimals

        public static int compareCanonicalDecimals​(java.lang.String dec1,
                                                   java.lang.String dec2)
        Compares two canonical decimals to eachother.
        Returns:
        A negative number if dec1 is smaller than dec2, 0 if they are equal, or positive (>0) if dec1 is larger than dec2. The result is undefined when one or both of the arguments is not a canonical decimal.
        Throws:
        java.lang.IllegalArgumentException - If one of the supplied strings is not a legal decimal.
      • compareCanonicalIntegers

        public static int compareCanonicalIntegers​(java.lang.String int1,
                                                   java.lang.String int2)
        Compares two canonical integers to eachother.
        Returns:
        A negative number if int1 is smaller than int2, 0 if they are equal, or positive (>0) if int1 is larger than int2. The result is undefined when one or both of the arguments is not a canonical integer.
        Throws:
        java.lang.IllegalArgumentException - If one of the supplied strings is not a legal integer.
      • parseCalendar

        public static javax.xml.datatype.XMLGregorianCalendar parseCalendar​(java.lang.String s)
        Parses the supplied calendar value string and returns its value.
        Parameters:
        s - A string representation of an xsd:dateTime, xsd:time, xsd:date, xsd:gYearMonth, xsd:gMonthDay, xsd:gYear, xsd:gMonth or xsd:gDay value.
        Returns:
        The calendar value represented by the supplied string argument.
        Throws:
        java.lang.NumberFormatException - If the supplied string is not a valid calendar value.