net.sourceforge.geeboss.util
Class StringUtil

java.lang.Object
  extended by net.sourceforge.geeboss.util.StringUtil

public class StringUtil
extends java.lang.Object

Utility methods for Strings

Author:
Frederic BORRY

Method Summary
static java.lang.String createFileName(java.lang.String str)
          Create a valid filename from the given String.
static java.lang.String decodeEntitys(java.lang.String text)
          Decode all encoded entitys if existing
static java.lang.String decodeISOChar(byte[] isoBytes)
          Decode ISO encoded character
static java.lang.String encodeBase64(java.lang.String str)
          Return BASE64 encoded value of String
static java.lang.String formatDate(java.util.Date date)
          Format a date
static boolean isset(java.lang.String str)
          Returns true in case the given String has a value that is not "".
static boolean isTerminating(java.lang.String ch)
          Check if a given char is a terminating an URL.
static boolean isWhiteSpaceOrEmpty(java.lang.String str)
          Returns true if the String only cosists of whitespaces or is null / empty.
static java.lang.String pointTrim(java.lang.String str, int length, boolean escapeMnemonics)
          Trims the given String to the given length and appends "..."
static java.lang.String printf(java.lang.String str, java.lang.String[] wildcard, java.lang.String[] substitution)
          Substitute wildcards in a String and return it
static java.lang.String replaceAll(java.lang.String str, java.lang.String search, java.lang.String replace)
          This method does exactly the same as String.replaceAll() with the difference that no regular expressions are used to perform the replacement.
static java.lang.String resolveVariables(java.lang.String string, java.util.Map<java.lang.String,java.lang.Object> variablesMap)
          Search a string for variable names of the form ${} and replace it by the potential values found in a given map.
static java.lang.String stripTags(java.lang.String str)
          Remove HTML tags from the given String
static java.lang.String unicodeToEntities(java.lang.String str)
          Convert the non ASCII-characters of a String into Unicode HTML entities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatDate

public static java.lang.String formatDate(java.util.Date date)
Format a date

Parameters:
date - the date to format
Returns:
the formated date

resolveVariables

public static java.lang.String resolveVariables(java.lang.String string,
                                                java.util.Map<java.lang.String,java.lang.Object> variablesMap)
Search a string for variable names of the form ${} and replace it by the potential values found in a given map.

Parameters:
string - the string to search and replace the variables.
variablesMap - the map containing the variable names associated to a string value.
Returns:
the string with variable references replaced

createFileName

public static java.lang.String createFileName(java.lang.String str)
Create a valid filename from the given String.

Parameters:
str - The String to convert to a valid filename.
Returns:
String A valid filename.

decodeEntitys

public static java.lang.String decodeEntitys(java.lang.String text)
Decode all encoded entitys if existing

Parameters:
text - Current Text
Returns:
Decoded Text

decodeISOChar

public static java.lang.String decodeISOChar(byte[] isoBytes)
Decode ISO encoded character

Parameters:
isoBytes - Bytes representing the char
Returns:
String representing the encoded char

encodeBase64

public static java.lang.String encodeBase64(java.lang.String str)
Return BASE64 encoded value of String

Parameters:
str - The String to encode to BASE64
Returns:
String BASE64 encoded value of the String

isset

public static boolean isset(java.lang.String str)
Returns true in case the given String has a value that is not "".

Parameters:
str - The String to check
Returns:
boolean true in case the String has an value not ""

isTerminating

public static boolean isTerminating(java.lang.String ch)
Check if a given char is a terminating an URL. URL-terminating symbols are whitespaces, single- and double quotes.

Parameters:
ch - Any char
Returns:
true if the char is terminating

isWhiteSpaceOrEmpty

public static boolean isWhiteSpaceOrEmpty(java.lang.String str)
Returns true if the String only cosists of whitespaces or is null / empty.

Parameters:
str - The string to check
Returns:
boolean true if the String only consists of whitespaces

pointTrim

public static java.lang.String pointTrim(java.lang.String str,
                                         int length,
                                         boolean escapeMnemonics)
Trims the given String to the given length and appends "..." Also replaces all occurances of "&" with "&&" if the String is used as title for controls that display "&" as mnemonic.

Parameters:
str - The String to Trim
length - The max. length of the String
escapeMnemonics - If true all "&" will be replaced with "&&"
Returns:
String The trimmed String

printf

public static java.lang.String printf(java.lang.String str,
                                      java.lang.String[] wildcard,
                                      java.lang.String[] substitution)
Substitute wildcards in a String and return it

Parameters:
str - The String to format
wildcard - Array of wildcards
substitution - Array of wildcards for the substitution of the wildcards.
Returns:
String The formatted String

replaceAll

public static java.lang.String replaceAll(java.lang.String str,
                                          java.lang.String search,
                                          java.lang.String replace)
This method does exactly the same as String.replaceAll() with the difference that no regular expressions are used to perform the replacement.

Parameters:
str - The source String to search and replace
search - The search term that should get replaced
replace - The value that replaces the search term
Returns:
String The new String with all replaced search terms

stripTags

public static java.lang.String stripTags(java.lang.String str)
Remove HTML tags from the given String

Parameters:
str - The String to remove the Tags from
Returns:
String The Tag removed String

unicodeToEntities

public static java.lang.String unicodeToEntities(java.lang.String str)
Convert the non ASCII-characters of a String into Unicode HTML entities.

Parameters:
str - The String to convert
Returns:
String The converted String


Copyright (c) 2005 The Geeboss team (http://geeboss.sourceforge.net). All Rights Reserved.