OBEROn SDK

com.oberon.util
Class StringUtils

java.lang.Object
  extended by com.oberon.util.StringUtils

public class StringUtils
extends java.lang.Object

Utilities for String manipulation

Version:
5.0

Field Summary
static java.lang.String UTF8
          UTF-8 constant
 
Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String addNewLines(java.lang.String text)
          Add new line after the period and colon characters
static java.lang.String arrayToString(java.lang.String[] array, java.lang.String delimiter)
          Append all string array elements (separated by the delimiter) to a single string
static byte[] base64Decode(java.lang.String text)
          Decode a base64 format to a binary array
static java.lang.String base64Encode(byte[] textbuffer)
          Encode to base64 format a binary array
static java.lang.String capitalize(java.lang.String text)
          Convert to upper case the first character of any words in a text
static boolean checkPattern(java.util.Vector<java.lang.String> patterns, java.lang.String text)
          Check if a text match one of given patterns
static boolean checkPatterns(java.util.Vector<java.lang.String> patterns, java.util.Vector<java.lang.String> elements)
          Check if one of the element of a Vector match one of given patterns
static java.lang.String escape(java.lang.String value)
          Escape single and double quotes inside a string
static java.lang.String escapeDB(java.lang.String value)
          Escape single quotes inside a string
static java.lang.String escapeNL(java.lang.String value)
          Replace new line character with carriage return
static java.lang.String escapePattern(java.lang.String value)
          Escape single and double quotes inside a pattern string
static java.lang.String formatValue(java.lang.String value, java.lang.String formatTags, java.util.Locale locale)
          Apply a format to a value according to the specific format tags and current locale
static java.lang.String generateSessionId(java.lang.String user, java.lang.String password)
          Use the user account to generate a session ID
static java.lang.String getStringPart(java.lang.String sourceText, int[] coords)
          Get sub-string included between two points
static java.lang.String getStringPart(java.lang.String sourceText, java.lang.String leftBound, java.lang.String rightBound)
          Get the first occurrence of sub-string included between two bound sub-strings (left and right)
static java.lang.String getTagValue(java.lang.String format, java.lang.String tag)
          Extract a tag value from a form-item format value
static java.lang.String hashPassword(java.lang.String password)
          Generate hashed password with 16 characters
static java.lang.String hashPassword(java.lang.String password, int numchars)
          Generate hashed password with the given length
static boolean isBlank(java.lang.String str)
          Check is a string is blank: is null, has length=0 or all character are white spaces
static boolean matchPattern(java.lang.String pattern, java.lang.String text)
          Check if a text match a given pattern
static int[] matchVectors(java.util.Vector<java.lang.String> v1, java.util.Vector<java.lang.String> v2, boolean checkRename)
          Search objects with same name, return a int array like: {-1 1 -1 -1 3 4 -1 5} where the numbers indicate the position of elements of vector v1 inside the vector v2
static void orderStringVector(java.util.Vector<?> vector, boolean increase)
          Sort a vector
static java.lang.String[] parseSessionId(java.lang.String sessionId)
          Extract the account info from a session ID
static java.lang.String patternVectorToString(java.util.Vector<java.lang.String> vector, java.lang.String delimiter)
          Append all pattern vector elements (separated by the delimiter) to a single string
static java.lang.String removeQuotes(java.lang.String sSource)
          Remove the quotes at the start and the end of a string
static java.lang.String replaceString(java.lang.String source, java.lang.String replace, java.lang.String substitute)
          Replace all occurrences of a sub-string into a given string with another substitute sub-string
static java.lang.String[] StringTokensToArray(java.lang.String stringToTokenize, java.lang.String delimiter)
          Split a string by the delimiter and add the tokens to a String array
static java.util.Vector<java.lang.String> StringTokensToVector(java.lang.String stringToTokenize, java.lang.String delimiter)
          Split a string by the delimiter and add the tokens to a Vector
static java.lang.String toAlphaNumeric(java.lang.String text)
          Convert accented characters to the similar alphabetical character
static java.lang.String unescape(java.lang.String value)
          Remove the escape character for single and double quotes
static java.lang.String unformatValue(java.lang.String value, java.lang.String formatTags, java.util.Locale locale)
          Remove the format from a value according to the specific format tags and current locale
static java.lang.String vectorToString(java.util.Vector<?> vector, java.lang.String delimiter)
          Append all vector elements (separated by the delimiter) to a single string
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8

public static final java.lang.String UTF8
UTF-8 constant

See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

escapeDB

public static java.lang.String escapeDB(java.lang.String value)
Escape single quotes inside a string


escape

public static java.lang.String escape(java.lang.String value)
Escape single and double quotes inside a string


escapeNL

public static java.lang.String escapeNL(java.lang.String value)
Replace new line character with carriage return


escapePattern

public static java.lang.String escapePattern(java.lang.String value)
Escape single and double quotes inside a pattern string


unescape

public static java.lang.String unescape(java.lang.String value)
Remove the escape character for single and double quotes


removeQuotes

public static java.lang.String removeQuotes(java.lang.String sSource)
Remove the quotes at the start and the end of a string


capitalize

public static java.lang.String capitalize(java.lang.String text)
Convert to upper case the first character of any words in a text


addNewLines

public static java.lang.String addNewLines(java.lang.String text)
Add new line after the period and colon characters


toAlphaNumeric

public static java.lang.String toAlphaNumeric(java.lang.String text)
Convert accented characters to the similar alphabetical character


hashPassword

public static java.lang.String hashPassword(java.lang.String password)
Generate hashed password with 16 characters


hashPassword

public static java.lang.String hashPassword(java.lang.String password,
                                            int numchars)
Generate hashed password with the given length


base64Encode

public static java.lang.String base64Encode(byte[] textbuffer)
Encode to base64 format a binary array


base64Decode

public static byte[] base64Decode(java.lang.String text)
                           throws java.lang.Exception
Decode a base64 format to a binary array

Throws:
java.lang.Exception

generateSessionId

public static java.lang.String generateSessionId(java.lang.String user,
                                                 java.lang.String password)
                                          throws java.lang.Exception
Use the user account to generate a session ID

Parameters:
user - the user name
password - the account password
Throws:
java.lang.Exception

parseSessionId

public static java.lang.String[] parseSessionId(java.lang.String sessionId)
                                         throws java.lang.Exception
Extract the account info from a session ID

Throws:
java.lang.Exception

vectorToString

public static java.lang.String vectorToString(java.util.Vector<?> vector,
                                              java.lang.String delimiter)
Append all vector elements (separated by the delimiter) to a single string


patternVectorToString

public static java.lang.String patternVectorToString(java.util.Vector<java.lang.String> vector,
                                                     java.lang.String delimiter)
Append all pattern vector elements (separated by the delimiter) to a single string


arrayToString

public static java.lang.String arrayToString(java.lang.String[] array,
                                             java.lang.String delimiter)
Append all string array elements (separated by the delimiter) to a single string


StringTokensToVector

public static java.util.Vector<java.lang.String> StringTokensToVector(java.lang.String stringToTokenize,
                                                                      java.lang.String delimiter)
Split a string by the delimiter and add the tokens to a Vector


StringTokensToArray

public static java.lang.String[] StringTokensToArray(java.lang.String stringToTokenize,
                                                     java.lang.String delimiter)
Split a string by the delimiter and add the tokens to a String array


isBlank

public static boolean isBlank(java.lang.String str)
Check is a string is blank: is null, has length=0 or all character are white spaces


getStringPart

public static java.lang.String getStringPart(java.lang.String sourceText,
                                             java.lang.String leftBound,
                                             java.lang.String rightBound)
Get the first occurrence of sub-string included between two bound sub-strings (left and right)

Parameters:
sourceText - the source string
leftBound - the left side sub-string
rightBound - the right side sub-string Example: getStringPart("user[MyName]","user[","]") return "MyName"

getStringPart

public static java.lang.String getStringPart(java.lang.String sourceText,
                                             int[] coords)
Get sub-string included between two points

Parameters:
sourceText - the source string
coords - points coordinates: int[4] { row0 , col0 , row1 , col1 }

getTagValue

public static java.lang.String getTagValue(java.lang.String format,
                                           java.lang.String tag)
Extract a tag value from a form-item format value

Parameters:
format - the format string
tag - the tag name

replaceString

public static java.lang.String replaceString(java.lang.String source,
                                             java.lang.String replace,
                                             java.lang.String substitute)
Replace all occurrences of a sub-string into a given string with another substitute sub-string

Parameters:
source - the source string
replace - the sub-string to replace
substitute - the substitute sub-string Example: replaceString("My source string"," s"," S") return "My Source String"

orderStringVector

public static void orderStringVector(java.util.Vector<?> vector,
                                     boolean increase)
Sort a vector

Parameters:
vector - the vector to sort
increase - if true order from less values to high values

matchVectors

public static int[] matchVectors(java.util.Vector<java.lang.String> v1,
                                 java.util.Vector<java.lang.String> v2,
                                 boolean checkRename)
Search objects with same name, return a int array like: {-1 1 -1 -1 3 4 -1 5} where the numbers indicate the position of elements of vector v1 inside the vector v2

Parameters:
checkRename - if true, try to map not found elements even if they don't match

matchPattern

public static boolean matchPattern(java.lang.String pattern,
                                   java.lang.String text)
Check if a text match a given pattern

Parameters:
pattern - the pattern (use wildcards "*" match 0/n chars and "?" match a single char)
text - the text to verify Example: matchPattern("*Nam?","MyName") return true matchPattern("*Nam?","MyNames") return false

checkPattern

public static boolean checkPattern(java.util.Vector<java.lang.String> patterns,
                                   java.lang.String text)
Check if a text match one of given patterns

Parameters:
patterns - Vector of the pattern (use wildcards "*" match 0/n chars and "?" match a single char)
text - the text to verify

checkPatterns

public static boolean checkPatterns(java.util.Vector<java.lang.String> patterns,
                                    java.util.Vector<java.lang.String> elements)
Check if one of the element of a Vector match one of given patterns

Parameters:
patterns - Vector of the pattern (use wildcards "*" match 0/n chars and "?" match a single char)
elements - list of elements to verify

formatValue

public static java.lang.String formatValue(java.lang.String value,
                                           java.lang.String formatTags,
                                           java.util.Locale locale)
Apply a format to a value according to the specific format tags and current locale

Parameters:
value - the value to format
formatTags - the format string including the value format tag
locale - current locale
Returns:
formatted value

unformatValue

public static java.lang.String unformatValue(java.lang.String value,
                                             java.lang.String formatTags,
                                             java.util.Locale locale)
                                      throws java.lang.Exception
Remove the format from a value according to the specific format tags and current locale

Parameters:
value - the value to format
formatTags - the format string including the value format tag
locale - current locale
Returns:
the unformatted value
Throws:
java.lang.Exception

OBEROn SDK

Copyright © 2008-2014 Mirko Solazzi. All Rights Reserved.