net.sf.jzeno.util
Class StringUtils

java.lang.Object
  extended by net.sf.jzeno.util.StringUtils

public class StringUtils
extends java.lang.Object

Utility methods for manipulating strings.


Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String addLeadingChar(long number, int length, char character)
          Method addLeadingChar.
static java.lang.String addLeadingZero(float number, int lengthInt, int nrDec)
          Method addLeadingZero. returns a String representation of the number. if nrDec > 0, the number will have exactly nrDec positions otherwice it will have no decimal positions at all.
static java.lang.String addLeadingZero(long number, int length)
          Method addLeadingZero.
static boolean beginsWith(java.lang.String s, java.lang.String sub)
           This method checks if a given string begins with another string The search is case sensitive !!
static java.lang.String[] breakIntoTokens(java.lang.String string, java.lang.String token)
          Breaks a string into tokens and gives back an array
static java.lang.String Capital(java.lang.String s)
           
static java.lang.String composeAction(java.lang.String action, java.util.Map parameters)
          This method composes an action based on the original action and a number of extra parameters.
static boolean contains(java.lang.String s, char c)
           This method checks if a given string contains a certain char
static boolean contains(java.lang.String s, java.lang.String sub)
           This method checks if a given string contains another string The search is case sensitive !!
static boolean containsIgnoreCase(java.lang.String s, java.lang.String sub)
           This method checks if a given string contains another string The search is case insensitive !!
static java.lang.String convertByteArrayToString(byte[] ba)
           
static java.lang.String convertLF2CRLF(java.lang.String s)
           
static byte[] convertToBytesUSASCII(java.lang.String s)
           
static java.lang.String escapeAllHTML(java.lang.String s)
          Replaces characters that may be confused by a HTML parser with their equivalent character entity references.
static java.lang.String escapeConstructionHint(java.lang.String value)
           
static java.lang.String escapeHTML(java.lang.String s)
           Replaces characters that may be confused by a HTML parser with their equivalent character entity references.
static java.lang.String filterCharNum(java.lang.String str)
           
static java.lang.String format(java.util.Date date)
          Deprecated.  
static java.lang.String format(java.util.Date date, java.lang.String format)
          Deprecated.  
static java.lang.String getAttributeValue(java.lang.String attribute, java.lang.String in)
          Checks the given string for an occurrence of an attribute and returns its value.
static java.lang.String getStackTrace(java.lang.Throwable throwable)
          Returns a string representation of the stack trace of the given Throwable.
static boolean isNumeric(java.lang.String s)
           Checks that the supplied string is only composed of digits.
static java.lang.String prepad(java.lang.String originalString, char prepadChar, int targetLength)
           
static java.lang.String removeLineBreaks(java.lang.String txt)
           Replace Line separators with a space.
static java.lang.String removeNonAlphaNumericSpace(java.lang.String input)
           Removes everything that is not an alphabetic, numeric or space character from the input string.
static java.lang.String replace(java.lang.String what, java.lang.String with, java.lang.String in)
          Substring replacer.
static java.lang.String replace(java.lang.String in, java.lang.String what, java.lang.String[] with)
           Method replace.
static java.util.Collection split(java.lang.String string, java.lang.String separator)
           
static java.lang.String trunc(java.lang.String aString, int numberOfChars)
           Method trunc. returns the substring starting at the beginning of the string. at most numberOfChars are returned.
static java.lang.String wrap(java.lang.String txt, int size)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

isNumeric

public static boolean isNumeric(java.lang.String s)

Checks that the supplied string is only composed of digits.


trunc

public static java.lang.String trunc(java.lang.String aString,
                                     int numberOfChars)

Method trunc. returns the substring starting at the beginning of the string. at most numberOfChars are returned.


contains

public static boolean contains(java.lang.String s,
                               char c)

This method checks if a given string contains a certain char

Parameters:
s - the string to be checked
c - the character that needs to be searched in the given string
Returns:
true if contains , false otherwise false if is null or empty

contains

public static boolean contains(java.lang.String s,
                               java.lang.String sub)

This method checks if a given string contains another string The search is case sensitive !!

Parameters:
s - the string to be checked
sub - the substring that needs to be searched in the given string
Returns:
true if contains , false otherwise false if is null or empty false if is null or empty

containsIgnoreCase

public static boolean containsIgnoreCase(java.lang.String s,
                                         java.lang.String sub)

This method checks if a given string contains another string The search is case insensitive !!

Parameters:
s - the string to be checked
sub - the substring that needs to be searched in the given string
Returns:
true if contains , false otherwise false if is null or empty false if is null or empty

beginsWith

public static boolean beginsWith(java.lang.String s,
                                 java.lang.String sub)

This method checks if a given string begins with another string The search is case sensitive !!

Parameters:
s - the string to be checked
sub - the substring that needs to be searched in the given string
Returns:
true if begins with , false otherwise false if is null or empty false if is null or empty

replace

public static java.lang.String replace(java.lang.String in,
                                       java.lang.String what,
                                       java.lang.String[] with)

Method replace. This method replaces all occurences of a certain substring "what" into another substring. The first occurance is replaced with with[0]. The second with with[1],... . If there are not enough "with" strings, the rest of the occurance of what stay unchanged.


replace

public static java.lang.String replace(java.lang.String what,
                                       java.lang.String with,
                                       java.lang.String in)
Substring replacer. This method replaces all occurences of a certain substring into another substring

Parameters:
what - substring to be replaced
with - substring to include in the result
in - string in which the substrings need to be replaced
Returns:
a string based on , where all occurences of are replaced with a substring null if was null

breakIntoTokens

public static java.lang.String[] breakIntoTokens(java.lang.String string,
                                                 java.lang.String token)
Breaks a string into tokens and gives back an array

Parameters:
string - The string that needs to be formatted
token - Delimiter
Returns:
a String array with the different tokens

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable throwable)
Returns a string representation of the stack trace of the given Throwable.

Parameters:
throwable - The Throwable for which the stack trace is returned.
Returns:
The stack trace.

getAttributeValue

public static java.lang.String getAttributeValue(java.lang.String attribute,
                                                 java.lang.String in)
Checks the given string for an occurrence of an attribute and returns its value. For example: A string contains /test.do?id=8&selection=true. The value of the 'id' attribute is '8'

Parameters:
attribute - attribute name
in - the string to be searched
Returns:
the value for the given attribute or null if doesn't contain

composeAction

public static java.lang.String composeAction(java.lang.String action,
                                             java.util.Map parameters)
This method composes an action based on the original action and a number of extra parameters. For Example: The original action contains /test/list.do and the parameters are [id:58, behavior:search] The returned action will than be /test/list.do?id=58&behavior=search

Parameters:
action - the original action
parameters - the extra parameters to be added to the action url a parameter is included if both the key and the value are set
Returns:
an action url composed of the original action and the parameters, null if is null if is null or empty

Capital

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

addLeadingChar

public static java.lang.String addLeadingChar(long number,
                                              int length,
                                              char character)
Method addLeadingChar. Will convert an int to a string The Size of the string is set via the length parameter. If the int is not big enough, the remaining possitions will be replaced by the character parameter at the left-hand side.

Parameters:
number - int to be converted to a string.
length - Minimum length of the String.
character - Character that will be uszed as leading character
Returns:
Object

addLeadingZero

public static java.lang.String addLeadingZero(long number,
                                              int length)
Method addLeadingZero. Add zero's in front of the number. See addLeadingChar


addLeadingZero

public static java.lang.String addLeadingZero(float number,
                                              int lengthInt,
                                              int nrDec)
Method addLeadingZero. returns a String representation of the number. if nrDec > 0, the number will have exactly nrDec positions otherwice it will have no decimal positions at all. The integer part of the number will be at least lengthInt long.


format

public static java.lang.String format(java.util.Date date,
                                      java.lang.String format)
Deprecated. 

Formats the date using the "SimpleDateFormat"


format

public static java.lang.String format(java.util.Date date)
Deprecated. 

Method format. Formats the date using the "SimpleDateFormat" and the pattern "yyyyMMdd"


convertToBytesUSASCII

public static byte[] convertToBytesUSASCII(java.lang.String s)

convertLF2CRLF

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

convertByteArrayToString

public static java.lang.String convertByteArrayToString(byte[] ba)

removeLineBreaks

public static java.lang.String removeLineBreaks(java.lang.String txt)

Replace Line separators with a space.

A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.


removeNonAlphaNumericSpace

public static java.lang.String removeNonAlphaNumericSpace(java.lang.String input)

Removes everything that is not an alphabetic, numeric or space character from the input string.


wrap

public static java.lang.String wrap(java.lang.String txt,
                                    int size)

escapeHTML

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

Replaces characters that may be confused by a HTML parser with their equivalent character entity references.

Any data that will appear as text on a web page should be be escaped. This is especially important for data that comes from untrusted sources such as Internet users. A common mistake in CGI programming is to ask a user for data and then put that data on a web page. For example:

 
  
    
     
      
       
        
         Server: What is your name?
         User: <b>Joe<b>
         Server: Hello <b>Joe</b>, Welcome
        
       
      
     
   
  
 

If the name is put on the page without checking that it doesn't contain HTML code or without sanitizing that HTML code, the user could reformat the page, insert scripts, and control the the content on your web server.

This method will replace HTML characters such as > with their HTML entity reference (&gt;) so that the html parser will be sure to interpret them as plain text rather than HTML or script.

This method should be used for both data to be displayed in text in the html document, and data put in form elements. For example:
<html><body>This in not a &lt;tag&gt; in HTML</body></html>
and
<form><input type="hidden" name="date" value="This data could be &quot;malicious&quot;"></form>
In the second example, the form data would be properly be resubmitted to your cgi script in the URLEncoded format:
This data could be %22malicious%22

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

escapeAllHTML

public static java.lang.String escapeAllHTML(java.lang.String s)
Replaces characters that may be confused by a HTML parser with their equivalent character entity references.

Any data that will appear as text on a web page should be be escaped. This is especially important for data that comes from untrusted sources such as Internet users. A common mistake in CGI programming is to ask a user for data and then put that data on a web page. For example:

 
  
    
     
      
       
        
         Server: What is your name?
         User: <b>Joe<b>
         Server: Hello <b>Joe</b>, Welcome
        
       
      
     
   
  
 
If the name is put on the page without checking that it doesn't contain HTML code or without sanitizing that HTML code, the user could reformat the page, insert scripts, and control the the content on your web server.

This method will replace HTML characters such as > with their HTML entity reference (&gt;) so that the html parser will be sure to interpret them as plain text rather than HTML or script.

This method should be used for both data to be displayed in text in the html document, and data put in form elements. For example:
<html><body>This in not a &lt;tag&gt; in HTML</body></html>
and
<form><input type="hidden" name="date" value="This data could be &quot;malicious&quot;"></form>
In the second example, the form data would be properly be resubmitted to your cgi script in the URLEncoded format:
This data could be %22malicious%22

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

filterCharNum

public static java.lang.String filterCharNum(java.lang.String str)

prepad

public static java.lang.String prepad(java.lang.String originalString,
                                      char prepadChar,
                                      int targetLength)

split

public static java.util.Collection split(java.lang.String string,
                                         java.lang.String separator)

escapeConstructionHint

public static java.lang.String escapeConstructionHint(java.lang.String value)