fr.opensagres.xdocreport.core.utils
Class StringUtils

java.lang.Object
  extended by fr.opensagres.xdocreport.core.utils.StringUtils

public class StringUtils
extends Object

String Utilities.


Field Summary
static String[] EMPTY_STRING_ARRAY
           
static String FALSE
           
static String TRUE
           
 
Constructor Summary
StringUtils()
           
 
Method Summary
static boolean asBoolean(String value)
           
static boolean asBoolean(String value, boolean defaultValue)
           
static Boolean asBooleanObject(String value)
           
static Boolean asBooleanObject(String value, Boolean defaultValue)
           
static Integer asInteger(String value)
          Returns the given value String as Integer.
static Integer asInteger(String value, Integer defaultValue)
          Returns the given value String as Integer.
static Long asLong(String value)
          Returns the given value String as Long.
static Long asLong(String value, Long defaultValue)
          Returns the given value String as Long.
static String decode(String s)
          Decode the given String to UTF-8.
static boolean isEmpty(String str)
           Checks if a String is empty ("") or null.
static boolean isNotEmpty(String str)
           Checks if a String is not empty ("") and not null.
static String replaceAll(String line, String oldString, String newString)
          Replace the oldString by the newString in the line and returns the result.
static String replaceEach(String text, String[] searchList, String[] replacementList)
           Replaces all occurrences of Strings within another String.
static String xmlEscape(String s)
          Re-escape xml special characters
static String xmlUnescape(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING_ARRAY

public static final String[] EMPTY_STRING_ARRAY

TRUE

public static final String TRUE
See Also:
Constant Field Values

FALSE

public static final String FALSE
See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

replaceAll

public static final String replaceAll(String line,
                                      String oldString,
                                      String newString)
Replace the oldString by the newString in the line and returns the result.

Parameters:
line - the line to replace.
oldString - old token to replace.
newString - new token to replace.
Returns:

isEmpty

public static boolean isEmpty(String str)

Checks if a String is empty ("") or null.

 StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true
 StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false
 StringUtils.isEmpty(" bob ") = false
 

Parameters:
str - the String to check, may be null
Returns:
true if the String is empty or null

isNotEmpty

public static boolean isNotEmpty(String str)

Checks if a String is not empty ("") and not null.

 StringUtils.isNotEmpty(null) = false
 StringUtils.isNotEmpty("") = false
 StringUtils.isNotEmpty(" ") = true
 StringUtils.isNotEmpty("bob") = true
 StringUtils.isNotEmpty(" bob ") = true
 

Parameters:
str - the String to check, may be null
Returns:
true if the String is not empty and not null

asBoolean

public static boolean asBoolean(String value)

asBoolean

public static boolean asBoolean(String value,
                                boolean defaultValue)

asBooleanObject

public static Boolean asBooleanObject(String value)

asBooleanObject

public static Boolean asBooleanObject(String value,
                                      Boolean defaultValue)

asInteger

public static Integer asInteger(String value)
Returns the given value String as Integer.

Parameters:
value -
Returns:

asInteger

public static Integer asInteger(String value,
                                Integer defaultValue)
Returns the given value String as Integer.

Parameters:
value -
defaultValue -
Returns:

asLong

public static Long asLong(String value)
Returns the given value String as Long.

Parameters:
value -
Returns:

asLong

public static Long asLong(String value,
                          Long defaultValue)
Returns the given value String as Long.

Parameters:
value -
defaultValue -
Returns:

replaceEach

public static String replaceEach(String text,
                                 String[] searchList,
                                 String[] replacementList)

Replaces all occurrences of Strings within another String.

A null reference passed to this method is a no-op, or if any "search string" or "string to replace" is null, that replace will be ignored. This will not repeat. For repeating replaces, call the overloaded method.

  StringUtils.replaceEach(null, *, *)        = null
  StringUtils.replaceEach("", *, *)          = ""
  StringUtils.replaceEach("aba", null, null) = "aba"
  StringUtils.replaceEach("aba", new String[0], null) = "aba"
  StringUtils.replaceEach("aba", null, new String[0]) = "aba"
  StringUtils.replaceEach("aba", new String[]{"a"}, null)  = "aba"
  StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""})  = "b"
  StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"})  = "aba"
  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"})  = "wcte"
  (example of how it does not repeat)
  StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"})  = "dcte"
 

Parameters:
text - text to search and replace in, no-op if null
searchList - the Strings to search for, no-op if null
replacementList - the Strings to replace them with, no-op if null
Returns:
the text with any replacements processed, null if null String input
Throws:
IndexOutOfBoundsException - if the lengths of the arrays are not the same (null is ok, and/or size 0)
Since:
2.4

decode

public static String decode(String s)
Decode the given String to UTF-8.

Parameters:
content -
Returns:

xmlUnescape

public static String xmlUnescape(String s)

xmlEscape

public static String xmlEscape(String s)
Re-escape xml special characters

Parameters:
s -
Returns:


Copyright © 2013. All rights reserved.