com.groiss.util
Class StringUtil

java.lang.Object
  extended by com.groiss.util.StringUtil

public class StringUtil
extends java.lang.Object

Some convenient string manipulation methods.


Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String decodeURL(java.lang.String url)
           
static java.lang.String encodeURL(java.lang.String url)
           
static boolean equalStrings(java.lang.String first, java.lang.String second)
          Checks if both strings are equal.
static boolean escapeForSQL(java.lang.StringBuffer arg)
          Escapes all occurencies of character '_' in the passed string buffer with the escape character '\'.
static java.lang.String format(java.lang.String pattern, java.lang.Object[] arguments)
          Formats the passed pattern with the passed argument (as known by java.text.MessageFormat(String, Object []) but it guarantees that single quotes remain in the pattern (class MessageFormat would remove them).
static java.lang.String getCharset()
           
static java.lang.String htmlEncode(java.lang.Object o)
          Translates some special characters to their representation in HTML.
static boolean isEmpty(java.lang.String s)
          Is the string null or the empty string
static boolean isRTL(java.util.Locale loc)
          Is the writing direction in the given locale right-to-left?
static java.lang.String noEmpty(java.lang.Object o)
          Returns " " when argument is null, otherwise o.toString()
static java.lang.String noEmpty(java.lang.String s)
          Returns " " when argument is null, otherwise the string itself.
static java.lang.String noNull(java.lang.Object s)
          Returns the empty string when argument is null, otherwise s.toString()
static java.lang.String noNull(java.lang.String s)
          Returns the empty string when argument is null, otherwise the string itself.
static java.lang.String noTags(java.lang.String text)
          De-HTMLize a string.
static java.lang.String quoteForSQL(java.lang.String arg)
          Doubles the singe quote ' to ''.
static java.lang.String replaceChar(java.lang.String str, char oldch, java.lang.String newStr)
          Replace a character by a string.
static void setCharset(java.lang.String charSet)
           
static java.util.Vector split(java.lang.String mask, java.lang.String pat)
          Split a string into pieces.
static java.util.Vector split(java.lang.String mask, java.lang.String pat, boolean withPat)
           
static java.lang.String substitute(java.lang.String mask, java.lang.String pat, java.lang.String value)
          Substitute a value for a pattern
static java.lang.String transformForSQL(java.lang.String arg)
          Replaces '*' with '%' and '?'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

substitute

public static java.lang.String substitute(java.lang.String mask,
                                          java.lang.String pat,
                                          java.lang.String value)
Substitute a value for a pattern

Parameters:
mask - the mask containing the patterns
pat - the pattern to substitute
value - the value inserted instead of the pattern
Returns:
the mask with the substitutions

noNull

public static java.lang.String noNull(java.lang.String s)
Returns the empty string when argument is null, otherwise the string itself.

Parameters:
s - a string
Returns:
a string, never null

noNull

public static java.lang.String noNull(java.lang.Object s)
Returns the empty string when argument is null, otherwise s.toString()

Parameters:
s - a object
Returns:
a string, never null

noEmpty

public static java.lang.String noEmpty(java.lang.String s)
Returns " " when argument is null, otherwise the string itself.

Parameters:
s - a string
Returns:
a string, never null or ""

noEmpty

public static java.lang.String noEmpty(java.lang.Object o)
Returns " " when argument is null, otherwise o.toString()

Parameters:
o - a object
Returns:
a string, never null or ""

quoteForSQL

public static java.lang.String quoteForSQL(java.lang.String arg)
Doubles the singe quote ' to ''. For use in sql expressions.

Parameters:
arg - a string
Returns:
a string

transformForSQL

public static java.lang.String transformForSQL(java.lang.String arg)
Replaces '*' with '%' and '?' with '_' which are the correct wildcards for sql queries. Also method quoteForSQL(String) is called

Parameters:
arg - the string in which the replacements and quotes should be performed
Returns:
the sql conform string

escapeForSQL

public static boolean escapeForSQL(java.lang.StringBuffer arg)
Escapes all occurencies of character '_' in the passed string buffer with the escape character '\'. If the escape character itself is an element of arg it will also be escaped.

Parameters:
arg - holds the string which should be escaped
Returns:
true if something had to be escaped, false otherwise

htmlEncode

public static java.lang.String htmlEncode(java.lang.Object o)
Translates some special characters to their representation in HTML.

Parameters:
o - an object with a toString method, the string is translated
Returns:
the HTML string

replaceChar

public static java.lang.String replaceChar(java.lang.String str,
                                           char oldch,
                                           java.lang.String newStr)
Replace a character by a string.

Parameters:
str - the string
oldch - the character to replace
newStr - the new string
Returns:
the result of replacements

split

public static java.util.Vector split(java.lang.String mask,
                                     java.lang.String pat)
Split a string into pieces.

Parameters:
mask - the mask to split
pat - the separator for splitting
Returns:
a vector containing the pieces

split

public static java.util.Vector split(java.lang.String mask,
                                     java.lang.String pat,
                                     boolean withPat)

noTags

public static java.lang.String noTags(java.lang.String text)
De-HTMLize a string.

Parameters:
text - a string containing HTML tags
Returns:
the string without HTML tags

equalStrings

public static boolean equalStrings(java.lang.String first,
                                   java.lang.String second)
Checks if both strings are equal. Null is definied to be equal to the empty string within this method.


isEmpty

public static boolean isEmpty(java.lang.String s)
Is the string null or the empty string

Parameters:
s - the string
Returns:
true, if the string is null or the empty string

encodeURL

public static java.lang.String encodeURL(java.lang.String url)

decodeURL

public static java.lang.String decodeURL(java.lang.String url)

getCharset

public static java.lang.String getCharset()

setCharset

public static void setCharset(java.lang.String charSet)

isRTL

public static boolean isRTL(java.util.Locale loc)
Is the writing direction in the given locale right-to-left? This is for example true in Hebrew, Arabic, or Persian

Parameters:
loc - the locale
Returns:
boolean true, if right to left

format

public static java.lang.String format(java.lang.String pattern,
                                      java.lang.Object[] arguments)
Formats the passed pattern with the passed argument (as known by java.text.MessageFormat(String, Object []) but it guarantees that single quotes remain in the pattern (class MessageFormat would remove them).

Parameters:
pattern - the pattern to format
arguments - the arguments for the pattern
Returns:


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.