org.opensaml.xml.util
Class DatatypeHelper

java.lang.Object
  extended by org.opensaml.xml.util.DatatypeHelper

public final class DatatypeHelper
extends java.lang.Object

Helper class for working with various datatypes.


Method Summary
static javax.xml.datatype.DatatypeFactory getDataTypeFactory()
          Gets a static instance of a JAXP DatatypeFactory.
static java.lang.String inputstreamToString(java.io.InputStream input, java.nio.charset.CharsetDecoder decoder)
          Reads an input stream into a string.
static boolean isEmpty(java.lang.String s)
          A "safe" null/empty check for strings.
static
<T> boolean
safeEquals(T s1, T s2)
          Compares two strings for equality, allowing for nulls.
static java.lang.String safeTrim(java.lang.String s)
          A safe string trim that handles nulls.
static java.lang.String safeTrimOrNullString(java.lang.String s)
          Removes preceeding or proceeding whitespace from a string or return null if the string is null or of zero length after trimming (i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDataTypeFactory

public static javax.xml.datatype.DatatypeFactory getDataTypeFactory()
Gets a static instance of a JAXP DatatypeFactory.

Returns:
the factory or null if the factory could not be created

isEmpty

public static boolean isEmpty(java.lang.String s)
A "safe" null/empty check for strings.

Parameters:
s - The string to check
Returns:
true if the string is null or the trimmed string is length zero

safeEquals

public static <T> boolean safeEquals(T s1,
                                     T s2)
Compares two strings for equality, allowing for nulls.

Type Parameters:
T - type of object to compare
Parameters:
s1 - The first operand
s2 - The second operand
Returns:
true if both are null or both are non-null and the same strng value

safeTrim

public static java.lang.String safeTrim(java.lang.String s)
A safe string trim that handles nulls.

Parameters:
s - the string to trim
Returns:
the trimmed string or null if the given string was null

safeTrimOrNullString

public static java.lang.String safeTrimOrNullString(java.lang.String s)
Removes preceeding or proceeding whitespace from a string or return null if the string is null or of zero length after trimming (i.e. if the string only contained whitespace).

Parameters:
s - the string to trim
Returns:
the trimmed string or null

inputstreamToString

public static java.lang.String inputstreamToString(java.io.InputStream input,
                                                   java.nio.charset.CharsetDecoder decoder)
                                            throws java.io.IOException
Reads an input stream into a string. The provide stream is not closed.

Parameters:
input - the input stream to read
decoder - character decoder to use, if null, system default character set is used
Returns:
the string read from the stream
Throws:
java.io.IOException - thrown if there is a problem reading from the stream and decoding it