com.ds.fw.utils
Class FwStringUtility

java.lang.Object
  |
  +--com.ds.fw.utils.FwStringUtility

public class FwStringUtility
extends java.lang.Object

I maintain a bunch of static methods that are sometimes useful but that are difficult to organize somewhere else. Basically I put these methods here because I didn't know where else to put them. In general, this class should NOT reference other Fw classes. It may be reasonable to reference other utility classes but I should not reference the domain or other application specific packages.


Field Summary
static char[] _buf65
          This variable should only be used in appendToString62(long, int, char[], StringBuffer)
static char[] RADIX_62
           
 
Constructor Summary
FwStringUtility()
           
 
Method Summary
static void appendToString62(long i, int radix, char[] chars, java.lang.StringBuffer sb)
          This method must be synchronized since it uses the static variable _buf65.
static void appendToString62(long i, java.lang.StringBuffer sb)
           
static double asDouble(java.lang.String s)
           
static int asInt(java.lang.String s)
           
static int asInteger(java.lang.String s)
           
static java.lang.String encodeHTML(java.lang.String s)
           
static java.lang.String encodeSQL(java.lang.String s)
           
static java.lang.String encodeURL(java.lang.String s)
           
static java.lang.String formatDouble(double d, int decimalPlaces)
           
static java.lang.String formatDouble(double d, int decimalPlaces, boolean includeCommas)
           
static java.lang.String getDecimalPattern(int places, boolean commas)
           
static int getInt(java.lang.String s)
           
static int getInt(java.lang.String s, int i)
           
static boolean hasValue(java.lang.String s)
          return true if the string is non-null and not empty.
static boolean isEmpty(java.lang.String s)
          return true if the string is null or empty.
static java.lang.String leftPad(java.lang.String s, char c, int n)
           
static java.lang.String newUniqueId()
          Create a unique string using a random long and the current time.
static java.lang.String nl2br(java.lang.String s)
           
static java.lang.String normStr(java.lang.String s, int i)
           
static java.util.List parseTokens(java.lang.String line, char delimiter)
          Get the list of tokens parsed from a line using a delimiter.
static void parseTokens(java.lang.String line, char delimiter, java.util.List target)
          Append all tokens in line to the target list.
static void printUnicode(java.lang.String jstr, java.io.PrintStream out)
           
static java.lang.String purgeBlanks(java.lang.String source)
          Elimina gli spazi consecutivi sostituendoli con un unico spazio.
static java.lang.String replaceAll(java.lang.String s, java.lang.String a, java.lang.String b)
          Replace all occurances of a with b in s.
static java.lang.String replaceFirst(java.lang.String s, java.lang.String a, java.lang.String b)
          Replace first occurance of a with b in s.
static java.lang.String replaceLFwithCRLF(java.lang.String source)
          Se il carattere LF non è preceduto da CR lo aggiunge.
static java.lang.String stripNonAlpha(java.lang.String s)
           
static java.lang.String strReplace(java.lang.String s, java.util.Date jDate)
           
static java.lang.String strReplace(java.lang.String s, com.ds.fw.servlet.FwAdapter adapter)
           
static java.lang.String strReplace(java.lang.String s, java.util.Locale lnLocale)
           
static java.lang.String strReplace(java.lang.String sOld, java.lang.String sNew, java.lang.String s)
           
static java.lang.String strReplace1(java.lang.String s, java.util.Date jDate)
           
static java.lang.String strTab(java.lang.String s, long l)
           
static java.lang.String szEscape(java.lang.String source)
          Sostituisce alcuni caratteri di una stringa con spazi o anteponedo il carattere di escape "\".
static java.lang.String szEscape(java.lang.String source, int[] original, java.lang.String[] changed)
          Sostituisce i caratteri di una stringa con altri passati come parametro.
static java.lang.String toStr(double l, long sLength)
           
static java.lang.String toStr(long l, long sLength)
           
static java.lang.String toString(long i, int radix, char[] chars)
           
static java.lang.String toString62(long i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RADIX_62

public static final char[] RADIX_62

_buf65

public static char[] _buf65
This variable should only be used in appendToString62(long, int, char[], StringBuffer)

Constructor Detail

FwStringUtility

public FwStringUtility()
Method Detail

encodeSQL

public static java.lang.String encodeSQL(java.lang.String s)

encodeURL

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

encodeHTML

public static java.lang.String encodeHTML(java.lang.String s)

normStr

public static java.lang.String normStr(java.lang.String s,
                                       int i)

nl2br

public static java.lang.String nl2br(java.lang.String s)

strTab

public static java.lang.String strTab(java.lang.String s,
                                      long l)

strReplace

public static java.lang.String strReplace(java.lang.String sOld,
                                          java.lang.String sNew,
                                          java.lang.String s)

stripNonAlpha

public static java.lang.String stripNonAlpha(java.lang.String s)

hasValue

public static boolean hasValue(java.lang.String s)
return true if the string is non-null and not empty.


isEmpty

public static boolean isEmpty(java.lang.String s)
return true if the string is null or empty.


formatDouble

public static java.lang.String formatDouble(double d,
                                            int decimalPlaces)

formatDouble

public static java.lang.String formatDouble(double d,
                                            int decimalPlaces,
                                            boolean includeCommas)

getDecimalPattern

public static java.lang.String getDecimalPattern(int places,
                                                 boolean commas)

asInteger

public static int asInteger(java.lang.String s)

leftPad

public static java.lang.String leftPad(java.lang.String s,
                                       char c,
                                       int n)

replaceAll

public static java.lang.String replaceAll(java.lang.String s,
                                          java.lang.String a,
                                          java.lang.String b)
Replace all occurances of a with b in s.


replaceFirst

public static java.lang.String replaceFirst(java.lang.String s,
                                            java.lang.String a,
                                            java.lang.String b)
Replace first occurance of a with b in s.


newUniqueId

public static java.lang.String newUniqueId()
Create a unique string using a random long and the current time. All id are exactly 24 characters long and may contain only the characters, [a-z][0-9]. Example id: "gc4k.hr3d.6n3l.i8lb.srwb".


toString62

public static java.lang.String toString62(long i)

toString

public static java.lang.String toString(long i,
                                        int radix,
                                        char[] chars)

appendToString62

public static void appendToString62(long i,
                                    java.lang.StringBuffer sb)

appendToString62

public static void appendToString62(long i,
                                    int radix,
                                    char[] chars,
                                    java.lang.StringBuffer sb)
This method must be synchronized since it uses the static variable _buf65. This static variable is used to avoid creating and new character array for every time a domain object is created that needs a uid.


asInt

public static int asInt(java.lang.String s)

getInt

public static int getInt(java.lang.String s)

getInt

public static int getInt(java.lang.String s,
                         int i)

toStr

public static java.lang.String toStr(double l,
                                     long sLength)

toStr

public static java.lang.String toStr(long l,
                                     long sLength)

asDouble

public static double asDouble(java.lang.String s)

parseTokens

public static java.util.List parseTokens(java.lang.String line,
                                         char delimiter)
Get the list of tokens parsed from a line using a delimiter.

See Also:

parseTokens

public static void parseTokens(java.lang.String line,
                               char delimiter,
                               java.util.List target)
Append all tokens in line to the target list. The delimiter is used to break the line into multiple tokens. The delimiters are not considered tokens are not added to the target list.


strReplace

public static java.lang.String strReplace(java.lang.String s,
                                          java.util.Date jDate)

strReplace1

public static java.lang.String strReplace1(java.lang.String s,
                                           java.util.Date jDate)

strReplace

public static java.lang.String strReplace(java.lang.String s,
                                          java.util.Locale lnLocale)

strReplace

public static java.lang.String strReplace(java.lang.String s,
                                          com.ds.fw.servlet.FwAdapter adapter)

szEscape

public static java.lang.String szEscape(java.lang.String source,
                                        int[] original,
                                        java.lang.String[] changed)
Sostituisce i caratteri di una stringa con altri passati come parametro. La sostituzione è posizionale ed in caso di errore il valore di ritorno è la stringa originale.

Parameters:
source - stringa da modificare
original - array di caratteri da sostituire
changed - array di valori (Stringa) sostitutivi
Returns:
valore String della stringa modificata

szEscape

public static java.lang.String szEscape(java.lang.String source)
Sostituisce alcuni caratteri di una stringa con spazi o anteponedo il carattere di escape "\". Consigliata per gli inserimenti in database. Caratteri sostituiti:
\n (ascii 10), \r (ascii 13), ' (ascii 39), \ (ascii 92), | (ascii 124)

Parameters:
source - stringa da modificare
Returns:
valore String della stringa modificata

replaceLFwithCRLF

public static java.lang.String replaceLFwithCRLF(java.lang.String source)
Se il carattere LF non è preceduto da CR lo aggiunge.


purgeBlanks

public static java.lang.String purgeBlanks(java.lang.String source)
Elimina gli spazi consecutivi sostituendoli con un unico spazio.

Parameters:
source - stringa da elaborare
Returns:
stringa senza spazi contigui

printUnicode

public static void printUnicode(java.lang.String jstr,
                                java.io.PrintStream out)