org.openrdf.model.datatypes
Class XMLDatatypeUtil

java.lang.Object
  extended by org.openrdf.model.datatypes.XMLDatatypeUtil

public class XMLDatatypeUtil
extends Object

Provides methods for handling the standard XML Schema datatypes.

Author:
Arjohn Kampman

Constructor Summary
XMLDatatypeUtil()
           
 
Method Summary
static String collapseWhiteSpace(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 compare(String value1, String value2, URI datatype)
           
static int compareBytes(String int1, String int2)
           
static int compareCanonicalDecimals(String dec1, String dec2)
          Compares two canonical decimals to eachother.
static int compareCanonicalDoubles(String double1, String double2)
          Compares two canonical doubles to eachother.
static int compareCanonicalFloats(String float1, String float2)
          Compares two canonical floats to eachother.
static int compareCanonicalFPNumbers(String float1, String float2)
          Compares two canonical floating point numbers to eachother.
static int compareCanonicalIntegers(String int1, String int2)
          Compares two canonical integers to eachother.
static int compareDateTime(String value1, String value2)
          Compares two dateTime objects.
static int compareDecimals(String dec1, String dec2)
          Compares two decimals to eachother.
static int compareDoubles(String double1, String double2)
          Compares two doubles to eachother.
static int compareFloats(String float1, String float2)
          Compares two floats to eachother.
static int compareFPNumbers(String fp1, String fp2)
          Compares two floating point numbers to eachother.
static int compareIntegers(String int1, String int2)
          Compares two integers to eachother.
static int compareInts(String int1, String int2)
           
static int compareLongs(String int1, String int2)
           
static int compareNegativeIntegers(String int1, String int2)
           
static int compareNonNegativeIntegers(String int1, String int2)
           
static int compareNonPositiveIntegers(String int1, String int2)
           
static int comparePositiveIntegers(String int1, String int2)
           
static int compareShorts(String int1, String int2)
           
static int compareUnsignedBytes(String int1, String int2)
           
static int compareUnsignedInts(String int1, String int2)
           
static int compareUnsignedLongs(String int1, String int2)
           
static int compareUnsignedShorts(String int1, String int2)
           
static boolean isBuiltInDatatype(URI datatype)
          Checks whether the supplied datatype is a built-in XML Schema datatype.
static boolean isCalendarDatatype(URI datatype)
          Checks whether the supplied datatype is equal to xsd:dateTime, xsd:date, xsd:time, xsd:gYearMonth, xsd:gMonthDay, xsd:gYear, xsd:gMonth or xsd:gDay.
static boolean isDecimalDatatype(URI datatype)
          Checks whether the supplied datatype is equal to xsd:decimal or one of the built-in datatypes that is derived from xsd:decimal.
static boolean isDerivedDatatype(URI datatype)
          Checks whether the supplied datatype is a derived XML Schema datatype.
static boolean isFloatingPointDatatype(URI datatype)
          Checks whether the supplied datatype is equal to xsd:float or xsd:double.
static boolean isIntegerDatatype(URI datatype)
          Checks whether the supplied datatype is equal to xsd:integer or one of the built-in datatypes that is derived from xsd:integer.
static boolean isNumericDatatype(URI datatype)
          Checks whether the supplied datatype is a numeric datatype, i.e.
static boolean isOrderedDatatype(URI datatype)
          Checks whether the supplied datatype is ordered.
static boolean isPrimitiveDatatype(URI datatype)
          Checks whether the supplied datatype is a primitive XML Schema datatype.
static boolean isValidBoolean(String value)
           
static boolean isValidByte(String value)
           
static boolean isValidDateTime(String value)
           
static boolean isValidDecimal(String value)
           
static boolean isValidDouble(String value)
           
static boolean isValidFloat(String value)
           
static boolean isValidInt(String value)
           
static boolean isValidInteger(String value)
           
static boolean isValidLong(String value)
           
static boolean isValidNegativeInteger(String value)
           
static boolean isValidNonNegativeInteger(String value)
           
static boolean isValidNonPositiveInteger(String value)
           
static boolean isValidPositiveInteger(String value)
           
static boolean isValidShort(String value)
           
static boolean isValidUnsignedByte(String value)
           
static boolean isValidUnsignedInt(String value)
           
static boolean isValidUnsignedLong(String value)
           
static boolean isValidUnsignedShort(String value)
           
static boolean isValidValue(String value, URI datatype)
           
static String normalize(String value, URI datatype)
          Normalizes the supplied value according to the normalization rules for the supplied datatype.
static String normalizeBoolean(String value)
          Normalizes a boolean value to its canonical representation.
static String normalizeByte(String value)
          Normalizes an xsd:byte.
static String normalizeDateTime(String value)
          Normalizes an xsd:dateTime.
static String normalizeDecimal(String decimal)
          Normalizes a decimal to its canonical representation.
static String normalizeDouble(String value)
          Normalizes a double to its canonical representation.
static String normalizeFloat(String value)
          Normalizes a float to its canonical representation.
static String normalizeFPNumber(String value)
          Normalizes a floating point number to its canonical representation.
static String normalizeInt(String value)
          Normalizes an xsd:int.
static String normalizeInteger(String value)
          Normalizes an integer to its canonical representation.
static String normalizeLong(String value)
          Normalizes an xsd:long.
static String normalizeNegativeInteger(String value)
          Normalizes an xsd:negativeInteger.
static String normalizeNonNegativeInteger(String value)
          Normalizes an xsd:nonNegativeInteger.
static String normalizeNonPositiveInteger(String value)
          Normalizes an xsd:nonPositiveInteger.
static String normalizePositiveInteger(String value)
          Normalizes an xsd:positiveInteger.
static String normalizeShort(String value)
          Normalizes an xsd:short.
static String normalizeUnsignedByte(String value)
          Normalizes an xsd:unsignedByte.
static String normalizeUnsignedInt(String value)
          Normalizes an xsd:unsignedInt.
static String normalizeUnsignedLong(String value)
          Normalizes an xsd:unsignedLong.
static String normalizeUnsignedShort(String value)
          Normalizes an xsd:unsignedShort.
static boolean parseBoolean(String s)
          Parses the supplied xsd:boolean string and returns its value.
static byte parseByte(String s)
          Parses the supplied xsd:byte string and returns its value.
static XMLGregorianCalendar parseCalendar(String s)
          Parses the supplied calendar value string and returns its value.
static BigDecimal parseDecimal(String s)
          Parses the supplied decimal/floating point string and returns its value.
static double parseDouble(String s)
          Parses the supplied xsd:double string and returns its value.
static float parseFloat(String s)
          Parses the supplied xsd:float string and returns its value.
static int parseInt(String s)
          Parses the supplied xsd:int strings and returns its value.
static BigInteger parseInteger(String s)
          Parses the supplied xsd:integer string and returns its value.
static long parseLong(String s)
          Parses the supplied xsd:long string and returns its value.
static short parseShort(String s)
          Parses the supplied xsd:short string and returns its value.
static URI qnameToURI(QName qname)
          Maps a datatype QName from the javax.xml.namespace package to an XML Schema URI for the corresponding datatype.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLDatatypeUtil

public XMLDatatypeUtil()
Method Detail

isPrimitiveDatatype

public static boolean isPrimitiveDatatype(URI datatype)
Checks whether the supplied datatype is a primitive XML Schema datatype.


isDerivedDatatype

public static boolean isDerivedDatatype(URI datatype)
Checks whether the supplied datatype is a derived XML Schema datatype.


isBuiltInDatatype

public static boolean isBuiltInDatatype(URI datatype)
Checks whether the supplied datatype is a built-in XML Schema datatype.


isNumericDatatype

public static boolean isNumericDatatype(URI datatype)
Checks whether the supplied datatype is a numeric datatype, i.e. if it is equal to xsd:float, xsd:double, xsd:decimal or one of the datatypes derived from xsd:decimal.


isDecimalDatatype

public static boolean isDecimalDatatype(URI datatype)
Checks whether the supplied datatype is equal to xsd:decimal or one of the built-in datatypes that is derived from xsd:decimal.


isIntegerDatatype

public static boolean isIntegerDatatype(URI datatype)
Checks whether the supplied datatype is equal to xsd:integer or one of the built-in datatypes that is derived from xsd:integer.


isFloatingPointDatatype

public static boolean isFloatingPointDatatype(URI datatype)
Checks whether the supplied datatype is equal to xsd:float or xsd:double.


isCalendarDatatype

public static boolean isCalendarDatatype(URI datatype)
Checks whether the supplied datatype is equal to xsd:dateTime, xsd:date, xsd:time, xsd:gYearMonth, xsd:gMonthDay, xsd:gYear, xsd:gMonth or xsd:gDay. These are the primitive datatypes that represent dates and/or times.

See Also:
XMLGregorianCalendar

isOrderedDatatype

public static boolean isOrderedDatatype(URI datatype)
Checks whether the supplied datatype is ordered. The values of an ordered datatype can be compared to eachother using operators like < and >.


isValidValue

public static boolean isValidValue(String value,
                                   URI datatype)

isValidDecimal

public static boolean isValidDecimal(String value)

isValidInteger

public static boolean isValidInteger(String value)

isValidNegativeInteger

public static boolean isValidNegativeInteger(String value)

isValidNonPositiveInteger

public static boolean isValidNonPositiveInteger(String value)

isValidNonNegativeInteger

public static boolean isValidNonNegativeInteger(String value)

isValidPositiveInteger

public static boolean isValidPositiveInteger(String value)

isValidLong

public static boolean isValidLong(String value)

isValidInt

public static boolean isValidInt(String value)

isValidShort

public static boolean isValidShort(String value)

isValidByte

public static boolean isValidByte(String value)

isValidUnsignedLong

public static boolean isValidUnsignedLong(String value)

isValidUnsignedInt

public static boolean isValidUnsignedInt(String value)

isValidUnsignedShort

public static boolean isValidUnsignedShort(String value)

isValidUnsignedByte

public static boolean isValidUnsignedByte(String value)

isValidFloat

public static boolean isValidFloat(String value)

isValidDouble

public static boolean isValidDouble(String value)

isValidBoolean

public static boolean isValidBoolean(String value)

isValidDateTime

public static boolean isValidDateTime(String value)

normalize

public static String normalize(String value,
                               URI 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:
IllegalArgumentException - If the supplied value is illegal considering the supplied datatype.

normalizeBoolean

public static String normalizeBoolean(String value)
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:
value - The boolean value to normalize.
Returns:
The normalized value.
Throws:
IllegalArgumentException - If the supplied value is not a legal boolean.

normalizeDecimal

public static String normalizeDecimal(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:
IllegalArgumentException - If one of the supplied strings is not a legal decimal.

normalizeInteger

public static String normalizeInteger(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:
IllegalArgumentException - If the supplied value is not a legal integer.

normalizeNegativeInteger

public static String normalizeNegativeInteger(String value)
Normalizes an xsd:negativeInteger.


normalizeNonPositiveInteger

public static String normalizeNonPositiveInteger(String value)
Normalizes an xsd:nonPositiveInteger.


normalizeNonNegativeInteger

public static String normalizeNonNegativeInteger(String value)
Normalizes an xsd:nonNegativeInteger.


normalizePositiveInteger

public static String normalizePositiveInteger(String value)
Normalizes an xsd:positiveInteger.


normalizeLong

public static String normalizeLong(String value)
Normalizes an xsd:long.


normalizeInt

public static String normalizeInt(String value)
Normalizes an xsd:int.


normalizeShort

public static String normalizeShort(String value)
Normalizes an xsd:short.


normalizeByte

public static String normalizeByte(String value)
Normalizes an xsd:byte.


normalizeUnsignedLong

public static String normalizeUnsignedLong(String value)
Normalizes an xsd:unsignedLong.


normalizeUnsignedInt

public static String normalizeUnsignedInt(String value)
Normalizes an xsd:unsignedInt.


normalizeUnsignedShort

public static String normalizeUnsignedShort(String value)
Normalizes an xsd:unsignedShort.


normalizeUnsignedByte

public static String normalizeUnsignedByte(String value)
Normalizes an xsd:unsignedByte.


normalizeFloat

public static String normalizeFloat(String value)
Normalizes a float to its canonical representation.

Parameters:
value - The value to normalize.
Returns:
The canonical representation of value.
Throws:
IllegalArgumentException - If the supplied value is not a legal float.

normalizeDouble

public static String normalizeDouble(String value)
Normalizes a double to its canonical representation.

Parameters:
value - The value to normalize.
Returns:
The canonical representation of value.
Throws:
IllegalArgumentException - If the supplied value is not a legal double.

normalizeFPNumber

public static String normalizeFPNumber(String value)
Normalizes a floating point number to its canonical representation.

Parameters:
value - The value to normalize.
Returns:
The canonical representation of value.
Throws:
IllegalArgumentException - If the supplied value is not a legal floating point number.

normalizeDateTime

public static String normalizeDateTime(String value)
Normalizes an xsd:dateTime.

Parameters:
value - The value to normalize.
Returns:
The normalized value.
Throws:
IllegalArgumentException - If the supplied value is not a legal xsd:dateTime value.

collapseWhiteSpace

public static String collapseWhiteSpace(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.


compare

public static int compare(String value1,
                          String value2,
                          URI datatype)

compareDecimals

public static int compareDecimals(String dec1,
                                  String dec2)
Compares two 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.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal decimal.

compareCanonicalDecimals

public static int compareCanonicalDecimals(String dec1,
                                           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:
IllegalArgumentException - If one of the supplied strings is not a legal decimal.

compareIntegers

public static int compareIntegers(String int1,
                                  String int2)
Compares two 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.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal integer.

compareCanonicalIntegers

public static int compareCanonicalIntegers(String int1,
                                           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:
IllegalArgumentException - If one of the supplied strings is not a legal integer.

compareNegativeIntegers

public static int compareNegativeIntegers(String int1,
                                          String int2)

compareNonPositiveIntegers

public static int compareNonPositiveIntegers(String int1,
                                             String int2)

compareNonNegativeIntegers

public static int compareNonNegativeIntegers(String int1,
                                             String int2)

comparePositiveIntegers

public static int comparePositiveIntegers(String int1,
                                          String int2)

compareLongs

public static int compareLongs(String int1,
                               String int2)

compareInts

public static int compareInts(String int1,
                              String int2)

compareShorts

public static int compareShorts(String int1,
                                String int2)

compareBytes

public static int compareBytes(String int1,
                               String int2)

compareUnsignedLongs

public static int compareUnsignedLongs(String int1,
                                       String int2)

compareUnsignedInts

public static int compareUnsignedInts(String int1,
                                      String int2)

compareUnsignedShorts

public static int compareUnsignedShorts(String int1,
                                        String int2)

compareUnsignedBytes

public static int compareUnsignedBytes(String int1,
                                       String int2)

compareFloats

public static int compareFloats(String float1,
                                String float2)
Compares two floats to eachother.

Returns:
A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal float or if NaN is compared to a float other than NaN.

compareCanonicalFloats

public static int compareCanonicalFloats(String float1,
                                         String float2)
Compares two canonical floats to eachother.

Returns:
A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2. The result is undefined when one or both of the arguments is not a canonical float.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal float or if NaN is compared to a float other than NaN.

compareDoubles

public static int compareDoubles(String double1,
                                 String double2)
Compares two doubles to eachother.

Returns:
A negative number if double1 is smaller than double2, 0 if they are equal, or positive (>0) if double1 is larger than double2.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal double or if NaN is compared to a double other than NaN.

compareCanonicalDoubles

public static int compareCanonicalDoubles(String double1,
                                          String double2)
Compares two canonical doubles to eachother.

Returns:
A negative number if double1 is smaller than double2, 0 if they are equal, or positive (>0) if double1 is larger than double2. The result is undefined when one or both of the arguments is not a canonical double.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal double or if NaN is compared to a double other than NaN.

compareFPNumbers

public static int compareFPNumbers(String fp1,
                                   String fp2)
Compares two floating point numbers to eachother.

Returns:
A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal floating point number or if NaN is compared to a floating point number other than NaN.

compareCanonicalFPNumbers

public static int compareCanonicalFPNumbers(String float1,
                                            String float2)
Compares two canonical floating point numbers to eachother.

Returns:
A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2. The result is undefined when one or both of the arguments is not a canonical floating point number.
Throws:
IllegalArgumentException - If one of the supplied strings is not a legal floating point number or if NaN is compared to a floating point number other than NaN.

compareDateTime

public static int compareDateTime(String value1,
                                  String value2)
Compares two dateTime objects. Important: The comparison only works if both values have, or both values don't have specified a valid value for the timezone.

Parameters:
value1 - An xsd:dateTime value.
value2 - An xsd:dateTime value.
Returns:
-1 if value1 is before value2 (i.e. if the dateTime object represented by value1 is before the dateTime object represented by value2), 0 if both are equal and 1 if value2 is before value1
.

parseBoolean

public static boolean parseBoolean(String s)
Parses the supplied xsd:boolean string and returns its value.

Parameters:
s - A string representation of an xsd:boolean value.
Returns:
The boolean value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:boolean value.

parseByte

public static byte parseByte(String s)
Parses the supplied xsd:byte string and returns its value.

Parameters:
s - A string representation of an xsd:byte value.
Returns:
The byte value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:byte value.

parseShort

public static short parseShort(String s)
Parses the supplied xsd:short string and returns its value.

Parameters:
s - A string representation of an xsd:short value.
Returns:
The short value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:short value.

parseInt

public static int parseInt(String s)
Parses the supplied xsd:int strings and returns its value.

Parameters:
s - A string representation of an xsd:int value.
Returns:
The int value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:int value.

parseLong

public static long parseLong(String s)
Parses the supplied xsd:long string and returns its value.

Parameters:
s - A string representation of an xsd:long value.
Returns:
The long value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:long value.

parseFloat

public static float parseFloat(String s)
Parses the supplied xsd:float string and returns its value.

Parameters:
s - A string representation of an xsd:float value.
Returns:
The float value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:float value.

parseDouble

public static double parseDouble(String s)
Parses the supplied xsd:double string and returns its value.

Parameters:
s - A string representation of an xsd:double value.
Returns:
The double value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:double value.

parseInteger

public static BigInteger parseInteger(String s)
Parses the supplied xsd:integer string and returns its value.

Parameters:
s - A string representation of an xsd:integer value.
Returns:
The integer value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:integer value.

parseDecimal

public static BigDecimal parseDecimal(String s)
Parses the supplied decimal/floating point string and returns its value.

Parameters:
s - A string representation of an xsd:decimal or xsd:double value.
Returns:
The decimal/floating point value represented by the supplied string argument.
Throws:
NumberFormatException - If the supplied string is not a valid xsd:decimal or xsd:double value.

parseCalendar

public static XMLGregorianCalendar parseCalendar(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:
NumberFormatException - If the supplied string is not a valid calendar value.

qnameToURI

public static URI qnameToURI(QName qname)
Maps a datatype QName from the javax.xml.namespace package to an XML Schema URI for the corresponding datatype. This method recognizes the XML Schema qname mentioned in DatatypeConstants.

Parameters:
qname - One of the XML Schema qnames from DatatypeConstants.
Returns:
A URI for the specified datatype.
Throws:
IllegalArgumentException - If the supplied qname was not recognized by this method.
See Also:
DatatypeConstants


Copyright © 2001-2008 Aduna. All Rights Reserved.