Servoy 5.x Public API

com.servoy.j2db.util
Class Utils

java.lang.Object
  extended by com.servoy.j2db.util.Utils

public class Utils
extends Object

Utility methods Normal Use: static methods


Field Summary
static double DEFAULT_EQUALS_PRECISION
           
static int PLATFORM_LINUX
           
static int PLATFORM_MAC
           
static int PLATFORM_OTHER
           
static int PLATFORM_WINDOWS
           
static float PPI
           
 
Method Summary
static void applyMaxTime(Calendar cal)
          Set Calendar time part to 23:59:59:999
static void applyMinTime(Calendar cal)
          Set Calendar time part to 00:00:00:000
static
<T> T[]
arrayAdd(T[] array, T element, boolean append)
          Add an element to an array.
static
<T> T[]
arrayInsert(T[] src, Object[] toAdd, int position, int n)
          Insert an array into another array at a certain position.
static
<T> T[]
arrayJoin(T[] array1, Object[] array2)
          Join 2 arrays into 1.
static
<T> T[]
arrayMerge(T[] upperAarray, T[] lowerAarray)
          Merge two arrays in 1, the upperArray will be overlaid onto the lowerArray.
static
<T> T[]
arraySub(T[] array, int beginIndex, int endIndex)
          Get a sub-array.
static
<T> T[]
asArray(Iterator<? extends T> it, Class<T> clazz)
           
static
<T> List<T>
asList(Iterator<? extends T> it)
           
static String calculateMD5Hash(String input)
          Deprecated. 
static String calculateMD5HashBase16(String input)
           
static String calculateMD5HashBase64(String password)
           
static String changeClassNameToFileName(String name)
          Change the passed class name to its corresponding file name.
static String changeFileNameToClassName(String name)
          Change the passed file name to its corresponding class name.
static Connection closeConnection(Connection connection)
           
static InputStream closeInputStream(InputStream is)
           
static OutputStream closeOutputStream(OutputStream os)
           
static Reader closeReader(Reader r)
           
static ResultSet closeResultSet(ResultSet resultSet)
           
static PreparedStatement closeStatement(PreparedStatement statement)
           
static Statement closeStatement(Statement statement)
           
static Writer closeWriter(Writer w)
           
static int compare(double d1, double d2)
           
static double convertPageFormatUnit(int oldUnit, int newUnit, double value)
           
static String convertToString(Object o)
          Convert to string representation, remove trailing '.0' for numbers.
static int countNumbers(String s)
          count the numbers in a string
static PageFormat createPageFormat(double width, double height, double lm, double rm, double tm, double bm, int orientation, int units)
          Create a PageFormat object from the dimensions and margins.
static byte[] decodeBASE64(String data)
           
static String encodeBASE64(byte[] data)
           
static boolean equalObjects(Object oldObj, Object obj)
           
static boolean equalObjects(Object oldObj, Object obj, boolean ignoreCase)
           
static boolean equalObjects(Object oldObj, Object obj, double equalsPrecision)
           
static boolean equalObjects(Object oldObj, Object obj, double equalsPrecision, boolean ignoreCase)
           
static CharSequence escapeMarkup(String s)
          Deprecated. 
static CharSequence escapeMarkup(String s, boolean escapeSpaces)
          Deprecated. 
static CharSequence escapeMarkup(String s, boolean escapeSpaces, boolean convertToHtmlUnicodeEscapes)
          Deprecated. 
static
<T> T[]
filterArrayClass(Object[] array, Class<T> clazz)
          Filter an array for the items that are assignable from the given class.
static String findLastNumber(String s)
          hardcore try to find the last number in a string
static String findNumber(String s)
          hardcore try to find a number in a string
static String formatNumber(Locale locale, double param, int digits)
          Format a given number (Visitor (locale) specific)
static String formatNumber(Locale locale, double param, String digits)
          Format a given number (Visitor (locale) specific)
static String formatNumber(Locale locale, Object param, String digits)
          Format a given number (Visitor (locale) specific)
static String formatNumber(Locale locale, String param, String digits)
          Format a given number (Visitor (locale) specific)
static String formatTime(int msec, String format)
          Format a given number of miliseconds in a formatted time Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone)
static String formatTime(long msec, String format)
          Format a given number of miliseconds in a formatted time Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone)
static String generateNormalizedName(String plainSQLName)
           
static boolean getAsBoolean(Object o)
          Try to parse the given object as a boolean
static boolean getAsBoolean(String s)
          Try to parse the given string as a boolean
static double getAsDouble(Object o)
          Try to parse the given object as a double
static double getAsDouble(Object o, boolean throwOnFail)
          Try to parse the given object as a double
static double getAsDouble(String s)
          Try to parse the given string as a double
static double getAsDouble(String s, boolean throwOnFail)
          Try to parse the given string as a double
static float getAsFloat(Object o)
          Try to parse the given object as a float
static float getAsFloat(Object o, boolean throwOnException)
          Try to parse the given object as a float
static float getAsFloat(String s)
          Try to parse the given string as a float
static float getAsFloat(String s, boolean throwOnException)
          Try to parse the given string as a float
static int getAsInteger(Object o)
          Try to parse the given object as an integer
static int getAsInteger(Object o, boolean throwOnException)
          Try to parse the given object as an integer
static int getAsInteger(String s)
          Try to parse the given string as an integer
static int getAsInteger(String s, boolean throwOnException)
          Try to parse the given string as an integer
static long getAsLong(Object o)
          Try to parse the given object as a long
static long getAsLong(Object o, boolean throwOnException)
          Try to parse the given object as a long
static long getAsLong(String s)
          Try to parse the given string as a long
static long getAsLong(String s, boolean throwOnException)
          Try to parse the given string as a long
static com.servoy.j2db.util.UUID getAsUUID(Object o, boolean throwOnException)
          Try to parse the given object as a UUID
static Rectangle getBounds(Iterator<?> elements)
          Get the rectangle that surrounds all elements
static CharSequence getDotQualitfied(Object... tokens)
           
static byte[] getFileContent(File f)
           
static int getPlatform()
           
static int getPlatform(String osname)
           
static String getTXTFileContent(File f)
           
static String getTXTFileContent(File f, Charset charset)
           
static String getTXTFileContent(InputStream f, Charset charset)
           
static byte[] getURLContent(String url)
           
static InputStream getUTF8EncodedStream(String out)
           
static void invokeLater(com.servoy.j2db.IEventDelegator delegator, List<Runnable> runnables)
           
static boolean isAppleMacOS()
           
static String longToHexString(long n, int digits)
           
static Object mapToNullIfUnmanageble(Object value)
           
static Timestamp parseDate(String datetime, String format)
          Create a Date (time) from a String, returns null on failure
Example: Timestamp t = Utils.parseDate("23-06-1975 6:08 AM", "dd-MM-yyyy hh:mm a");
static Object parseJSExpression(String s)
          Parse a javascript string into a java string, example parseJSString('Hello world') returns Hello World
static Object[] parseJSExpressions(List<Object> exprs)
           
static int readerWriterCopy(Reader is, Writer os)
           
static byte[] readFile(File f, long size)
           
static void releaseConnection(Connection connection)
           
static void rollback(Connection connection)
           
static BigDecimal roundNumber(Object number, int precision, boolean throwOnFail)
           
static int streamCopy(InputStream is, OutputStream os)
           
static int streamCopy(InputStream is, OutputStream os, ActionListener l, int actionSize)
           
static boolean stringContainsIgnoreCase(CharSequence source, String contains)
           
static int stringIndexOf(String string, int ch, int escape)
           
static int stringIndexOf(String string, int ch, int escape, int beginIndex)
           
static String stringInitCap(Object text)
           
static boolean stringIsEmpty(CharSequence str)
          Checks whether the string is considered empty.
static String stringJoin(Iterator iterator, char separator)
           Joins the elements of the provided Iterator into a single String containing the provided elements.
static String stringJoin(Object[] array, char separator)
           
static CharSequence stringLimitLenght(CharSequence str, int length)
           
static String stringRemoveTags(String str)
          Removes all substrings between '<' and corresponding '>'.
static String stringReplace(String org, String source, String destination)
          Method for replacing part of a string with a string
static String stringReplace(String org, String source, String destination, int replaceOccurence)
           
static String stringReplace(String org, String source, String destination, int replaceOccurence, boolean mustExact, boolean caseInsensitiveSearch)
           
static String stringReplaceCaseInsensitiveSearch(String org, String source, String destination)
           
static String stringReplaceExact(String org, String source, String destination)
           
static String stringReplaceRecursive(String org, String source, String destination)
           
static boolean stringSafeEquals(String left, String right)
          Compares two strings no matter if they are null
static String[] stringSplit(String string, int separator, int escape)
           
static String[] stringSplit(String s, String split)
           
static String toEnglishLocaleLowerCase(String text)
           
static CharSequence toMultilineMarkup(CharSequence s)
          Converts a String to multiline HTML markup by replacing newlines with line break entities (<br/>) and multiple occurrences of newline with paragraph break entities (<p>).
static String unescape(String string, int escape)
           
static boolean writeTXTFile(File file, String content)
           
static boolean writeTXTFile(File f, String content, Charset charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EQUALS_PRECISION

public static final double DEFAULT_EQUALS_PRECISION
See Also:
Constant Field Values

PLATFORM_LINUX

public static final int PLATFORM_LINUX
See Also:
Constant Field Values

PLATFORM_MAC

public static final int PLATFORM_MAC
See Also:
Constant Field Values

PLATFORM_OTHER

public static final int PLATFORM_OTHER
See Also:
Constant Field Values

PLATFORM_WINDOWS

public static final int PLATFORM_WINDOWS
See Also:
Constant Field Values

PPI

public static final float PPI
See Also:
Constant Field Values
Method Detail

applyMaxTime

public static void applyMaxTime(Calendar cal)
Set Calendar time part to 23:59:59:999

Parameters:
cal -

applyMinTime

public static void applyMinTime(Calendar cal)
Set Calendar time part to 00:00:00:000

Parameters:
cal -

arrayAdd

public static <T> T[] arrayAdd(T[] array,
                               T element,
                               boolean append)
Add an element to an array. Element type will be preserved.

Parameters:
array -
element -
append -
Returns:
the resulting array

arrayInsert

public static <T> T[] arrayInsert(T[] src,
                                  Object[] toAdd,
                                  int position,
                                  int n)
Insert an array into another array at a certain position. Both arrays may be null, resulting array will be extended to fit. Element type will be preserved.

Parameters:
src -
toAdd -
position -
n -
Returns:
the resulting array

arrayJoin

public static <T> T[] arrayJoin(T[] array1,
                                Object[] array2)
Join 2 arrays into 1. Element type will be preserved.

Parameters:
array1 -
array2 -
Returns:
the resulting array

arrayMerge

public static <T> T[] arrayMerge(T[] upperAarray,
                                 T[] lowerAarray)
Merge two arrays in 1, the upperArray will be overlaid onto the lowerArray.

For example:
upper = [x, y] lower = [a,b,c] => overlaid = [x, y, c]
upper = [a, b c] lower = [x, y] => overlaid = [a, b, c]

Parameters:
upperAarray -
lowerAarray -

arraySub

public static <T> T[] arraySub(T[] array,
                               int beginIndex,
                               int endIndex)
Get a sub-array. Element type will be preserved.

Parameters:
array -
beginIndex -
endIndex -
Returns:
the resulting array

asArray

public static <T> T[] asArray(Iterator<? extends T> it,
                              Class<T> clazz)

asList

public static <T> List<T> asList(Iterator<? extends T> it)

calculateMD5Hash

@Deprecated
public static String calculateMD5Hash(String input)
Deprecated. 


calculateMD5HashBase16

public static String calculateMD5HashBase16(String input)

calculateMD5HashBase64

public static String calculateMD5HashBase64(String password)

changeClassNameToFileName

public static String changeClassNameToFileName(String name)
Change the passed class name to its corresponding file name. E.G. change "Utilities" to "Utilities.class".

Parameters:
name - Class name to be changed.
Throws:
IllegalArgumentException - If a null name passed.

changeFileNameToClassName

public static String changeFileNameToClassName(String name)
Change the passed file name to its corresponding class name. E.G. change "Utilities.class" to "Utilities".

Parameters:
name - Class name to be changed. If this does not represent a Java class then null is returned.
Throws:
IllegalArgumentException - If a null name passed.

closeConnection

public static Connection closeConnection(Connection connection)

closeInputStream

public static InputStream closeInputStream(InputStream is)

closeOutputStream

public static OutputStream closeOutputStream(OutputStream os)

closeReader

public static Reader closeReader(Reader r)

closeResultSet

public static ResultSet closeResultSet(ResultSet resultSet)

closeStatement

public static PreparedStatement closeStatement(PreparedStatement statement)

closeStatement

public static Statement closeStatement(Statement statement)

closeWriter

public static Writer closeWriter(Writer w)

compare

public static int compare(double d1,
                          double d2)

convertPageFormatUnit

public static double convertPageFormatUnit(int oldUnit,
                                           int newUnit,
                                           double value)

convertToString

public static String convertToString(Object o)
Convert to string representation, remove trailing '.0' for numbers.

Returns:
the result string

countNumbers

public static int countNumbers(String s)
count the numbers in a string

Parameters:
s - the string with the numbers
Returns:
the count

createPageFormat

public static PageFormat createPageFormat(double width,
                                          double height,
                                          double lm,
                                          double rm,
                                          double tm,
                                          double bm,
                                          int orientation,
                                          int units)
Create a PageFormat object from the dimensions and margins.

Parameters:
width - the actual paper width - ignoring orientation. It is the width of the paper as seen by the printer.
height - the actual paper height - ignoring orientation. It is the height of the paper as seen by the printer.
lm - left margin of the page, not paper. So this is the left margin affected by orientation, as used in application.
rm - right margin of the page, not paper. So this is the right margin affected by orientation, as used in application.
tm - top margin of the page, not paper. So this is the top margin affected by orientation, as used in application.
bm - bottom margin of the page, not paper. So this is the bottom margin affected by orientation, as used in application.
orientation - the orientation of the page. Establishes a relation between page and paper coordinates.
units - INCHES or MM.
Returns:
the required PageFormat object.

decodeBASE64

public static byte[] decodeBASE64(String data)

encodeBASE64

public static String encodeBASE64(byte[] data)

equalObjects

public static final boolean equalObjects(Object oldObj,
                                         Object obj)

equalObjects

public static final boolean equalObjects(Object oldObj,
                                         Object obj,
                                         boolean ignoreCase)

equalObjects

public static final boolean equalObjects(Object oldObj,
                                         Object obj,
                                         double equalsPrecision)

equalObjects

public static final boolean equalObjects(Object oldObj,
                                         Object obj,
                                         double equalsPrecision,
                                         boolean ignoreCase)

escapeMarkup

@Deprecated
public static CharSequence escapeMarkup(String s)
Deprecated. 

Converts a Java String to an HTML markup string, but does not convert normal spaces to non-breaking space entities (<nbsp>).

Parameters:
s - The string to be escaped
Returns:
The escaped string
See Also:
escapeMarkup(String, boolean)

escapeMarkup

@Deprecated
public static CharSequence escapeMarkup(String s,
                                                   boolean escapeSpaces)
Deprecated. 

Converts a Java String to an HTML markup String by replacing illegal characters with HTML entities where appropriate. Spaces are converted to non-breaking spaces (<nbsp>) if escapeSpaces is true, tabs are converted to four non-breaking spaces, less than signs are converted to &lt; entities and greater than signs to &gt; entities.

Parameters:
s - The string to escape
escapeSpaces - True to replace ' ' with nonbreaking space
Returns:
The escaped string

escapeMarkup

@Deprecated
public static CharSequence escapeMarkup(String s,
                                                   boolean escapeSpaces,
                                                   boolean convertToHtmlUnicodeEscapes)
Deprecated. 

Converts a Java String to an HTML markup String by replacing illegal characters with HTML entities where appropriate. Spaces are converted to non-breaking spaces (<nbsp>) if escapeSpaces is true, tabs are converted to four non-breaking spaces, less-than signs are converted to &lt; entities and greater-than signs to &gt; entities.

Parameters:
s - The string to escape
escapeSpaces - True to replace ' ' with nonbreaking space
convertToHtmlUnicodeEscapes - True to convert non-7 bit characters to unicode HTML (&#...)
Returns:
The escaped string

filterArrayClass

public static <T> T[] filterArrayClass(Object[] array,
                                       Class<T> clazz)
Filter an array for the items that are assignable from the given class.

Parameters:
array -
clazz -
Returns:
array of type clazz[]

findLastNumber

public static String findLastNumber(String s)
hardcore try to find the last number in a string

Parameters:
s - the string with the number
Returns:
only the digits

findNumber

public static String findNumber(String s)
hardcore try to find a number in a string

Parameters:
s - the string with the number
Returns:
only the digits

formatNumber

public static String formatNumber(Locale locale,
                                  double param,
                                  int digits)
Format a given number (Visitor (locale) specific)

Parameters:
param - the input number
digits - number of digits
Returns:
the formatted number

formatNumber

public static String formatNumber(Locale locale,
                                  double param,
                                  String digits)
Format a given number (Visitor (locale) specific)

Parameters:
param - the input number
digits - number of digits
Returns:
the formatted number

formatNumber

public static String formatNumber(Locale locale,
                                  Object param,
                                  String digits)
Format a given number (Visitor (locale) specific)

Parameters:
param - the input number
digits - number of digits
Returns:
the formatted number

formatNumber

public static String formatNumber(Locale locale,
                                  String param,
                                  String digits)
Format a given number (Visitor (locale) specific)

Parameters:
param - the input number
digits - number of digits
Returns:
the formatted number

formatTime

public static String formatTime(int msec,
                                String format)
Format a given number of miliseconds in a formatted time Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone)

Parameters:
msec - the miliseconds (current time can be get by 'new java.util.Date().getTime()')
format - the display format (format used from java.text.SimpleDateFormat!)
Returns:
the formatted time
See Also:
SimpleDateFormat

formatTime

public static String formatTime(long msec,
                                String format)
Format a given number of miliseconds in a formatted time Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone)

Parameters:
msec - the miliseconds (current time can be get by 'new java.util.Date().getTime()')
format - the display format
Returns:
the formatted time
See Also:
SimpleDateFormat

generateNormalizedName

public static String generateNormalizedName(String plainSQLName)

getAsBoolean

public static boolean getAsBoolean(Object o)
Try to parse the given object as a boolean

Parameters:
o - the object (Boolean, Number, String, ...) to parse
Returns:
the boolean (false if the parse doesn't succeed)

getAsBoolean

public static boolean getAsBoolean(String s)
Try to parse the given string as a boolean

Parameters:
s - the string to parse
Returns:
the boolean (false if the parse doesn't succeed)

getAsDouble

public static double getAsDouble(Object o)
Try to parse the given object as a double

Parameters:
o - the object (Number, String, ...) to parse
Returns:
the parsed double - or 0 (zero) if the parse doesn't succeed

getAsDouble

public static double getAsDouble(Object o,
                                 boolean throwOnFail)
Try to parse the given object as a double

Parameters:
o - the object (Number, String, ...) to parse
throwOnFail - whether or not to throw a RuntimeException on failure
Returns:
the parsed double - or 0 (zero) if the parse doesn't succeed and throwOnFail is false

getAsDouble

public static double getAsDouble(String s)
Try to parse the given string as a double

Parameters:
s - the string to parse
Returns:
the parsed double - or 0 (zero) if the parse doesn't succeed

getAsDouble

public static double getAsDouble(String s,
                                 boolean throwOnFail)
Try to parse the given string as a double

Parameters:
s - the string to parse
throwOnFail - whether or not to throw a RuntimeException on failure
Returns:
the parsed double - or 0 (zero) if the parse doesn't succeed and throwOnFail is false

getAsFloat

public static float getAsFloat(Object o)
Try to parse the given object as a float

Parameters:
o - the object (Number, String, ...) to parse
Returns:
the parsed float or 0 (zero) if the parse doesn't succeed

getAsFloat

public static float getAsFloat(Object o,
                               boolean throwOnException)
Try to parse the given object as a float

Parameters:
o - the object (Number, String, ...) to parse
throwOnException - whether or not to throw a RuntimeException on failure
Returns:
the parsed float - or 0 (zero) if the parse doesn't succeed and throwOnException is false

getAsFloat

public static float getAsFloat(String s)
Try to parse the given string as a float

Parameters:
s - the string to parse
Returns:
the float - or 0 (zero) if the parse doesn't succeed

getAsFloat

public static float getAsFloat(String s,
                               boolean throwOnException)
Try to parse the given string as a float

Parameters:
s - the string to parse
throwOnException - whether or not to throw a RuntimeException on failure
Returns:
the float - or 0 (zero) if the parse doesn't succeed if throwOnException is false

getAsInteger

public static int getAsInteger(Object o)
Try to parse the given object as an integer

Parameters:
o - the object (Number, String, ...) to parse
Returns:
the parsed integer - or 0 (zero) if the parse doesn't succeed

getAsInteger

public static int getAsInteger(Object o,
                               boolean throwOnException)
Try to parse the given object as an integer

Parameters:
o - the object (Number, String, ...) to parse
throwOnException - whether to throw an exception if parsing failed
Returns:
the parsed integer - or 0 (zero) if the parse doesn't succeed and throwOnException is false

getAsInteger

public static int getAsInteger(String s)
Try to parse the given string as an integer

Parameters:
s - the string to parse
Returns:
the parsed integer - or 0 (zero) if the parse doesn't succeed

getAsInteger

public static int getAsInteger(String s,
                               boolean throwOnException)
Try to parse the given string as an integer

Parameters:
s - the string to parse
throwOnException - whether or not to throw a RuntimeException on failure
Returns:
the parsed integer - or 0 (zero) if the parse doesn't succeed and throwOnException is false
Throws:
RuntimeException - in case of trouble when throwOnException is true

getAsLong

public static long getAsLong(Object o)
Try to parse the given object as a long

Parameters:
o - the object (String, Number, ...) to parse
Returns:
the parsed long - or 0 (zero) if the parse doesn't succeed

getAsLong

public static long getAsLong(Object o,
                             boolean throwOnException)
Try to parse the given object as a long

Parameters:
o - the Object (Number, String, ...) to parse
throwOnException - whether or not to throw a RuntimeException on failure
Returns:
the parsed long - or 0 (zero) if the parse doesn't succeed and throwOnException is false

getAsLong

public static long getAsLong(String s)
Try to parse the given string as a long

Parameters:
s - the string to parse
Returns:
the parsed long - or 0 (zero) if the parse doesn't succeed

getAsLong

public static long getAsLong(String s,
                             boolean throwOnException)
Try to parse the given string as a long

Parameters:
s - the string to parse
throwOnException - whether or not to throw a RuntimeException on failure
Returns:
the parsed long - or 0 (zero) if the parse doesn't succeed and throwOnException is false

getAsUUID

public static com.servoy.j2db.util.UUID getAsUUID(Object o,
                                                  boolean throwOnException)
Try to parse the given object as a UUID

Parameters:
o - the object to try
throwOnException - whether or not to throw a RuntimeException on failure
Returns:
UUID or null if o is not recognized

getBounds

public static Rectangle getBounds(Iterator<?> elements)
Get the rectangle that surrounds all elements

Parameters:
elements -
Returns:

getDotQualitfied

public static CharSequence getDotQualitfied(Object... tokens)

getFileContent

public static byte[] getFileContent(File f)

getPlatform

public static int getPlatform()

getPlatform

public static int getPlatform(String osname)

getTXTFileContent

public static String getTXTFileContent(File f)

getTXTFileContent

public static String getTXTFileContent(File f,
                                       Charset charset)

getTXTFileContent

public static String getTXTFileContent(InputStream f,
                                       Charset charset)

getURLContent

public static byte[] getURLContent(String url)

getUTF8EncodedStream

public static InputStream getUTF8EncodedStream(String out)

invokeLater

public static void invokeLater(com.servoy.j2db.IEventDelegator delegator,
                               List<Runnable> runnables)

isAppleMacOS

public static boolean isAppleMacOS()

longToHexString

public static String longToHexString(long n,
                                     int digits)

mapToNullIfUnmanageble

public static Object mapToNullIfUnmanageble(Object value)

parseDate

public static Timestamp parseDate(String datetime,
                                  String format)
Create a Date (time) from a String, returns null on failure
Example: Timestamp t = Utils.parseDate("23-06-1975 6:08 AM", "dd-MM-yyyy hh:mm a");

Parameters:
datetime - the date as formatted string
format - the format to be used
Returns:
the Timestamp object
See Also:
SimpleDateFormat

parseJSExpression

public static Object parseJSExpression(String s)
Parse a javascript string into a java string, example parseJSString('Hello world') returns Hello World

Parameters:
s -
Returns:
the result string

parseJSExpressions

public static Object[] parseJSExpressions(List<Object> exprs)

readerWriterCopy

public static int readerWriterCopy(Reader is,
                                   Writer os)
                            throws IOException
Throws:
IOException

readFile

public static byte[] readFile(File f,
                              long size)

releaseConnection

public static void releaseConnection(Connection connection)

rollback

public static void rollback(Connection connection)

roundNumber

public static BigDecimal roundNumber(Object number,
                                     int precision,
                                     boolean throwOnFail)

streamCopy

public static int streamCopy(InputStream is,
                             OutputStream os)
                      throws IOException
Throws:
IOException

streamCopy

public static int streamCopy(InputStream is,
                             OutputStream os,
                             ActionListener l,
                             int actionSize)
                      throws IOException
Throws:
IOException

stringContainsIgnoreCase

public static boolean stringContainsIgnoreCase(CharSequence source,
                                               String contains)

stringIndexOf

public static int stringIndexOf(String string,
                                int ch,
                                int escape)

stringIndexOf

public static int stringIndexOf(String string,
                                int ch,
                                int escape,
                                int beginIndex)

stringInitCap

public static String stringInitCap(Object text)

stringIsEmpty

public static boolean stringIsEmpty(CharSequence str)
Checks whether the string is considered empty. Empty means that the string may contain whitespace, but no visible characters. "\n\t " is considered empty, while " a" is not.

Parameters:
str - the string
Returns:
true if the string is null or ""

stringJoin

public static String stringJoin(Iterator iterator,
                                char separator)

Joins the elements of the provided Iterator into a single String containing the provided elements.

No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.

Parameters:
iterator - the Iterator of values to join together, may be null
separator - the separator character to use
Returns:
the joined String, null if null iterator input

stringJoin

public static String stringJoin(Object[] array,
                                char separator)

stringLimitLenght

public static CharSequence stringLimitLenght(CharSequence str,
                                             int length)

stringRemoveTags

public static String stringRemoveTags(String str)
Removes all substrings between '<' and corresponding '>'. If the number of '<' characters differs from the number of '>' characters, the behavior is undetermined.

Parameters:
str - the initial string.
Returns:
a string equal to the given string from which all substrings between '<' and corresponding '>' were removed.

stringReplace

public static String stringReplace(String org,
                                   String source,
                                   String destination)
Method for replacing part of a string with a string

Parameters:
org - the orginal string
source - the string to search
destination - the string to replace
Returns:
the result

stringReplace

public static String stringReplace(String org,
                                   String source,
                                   String destination,
                                   int replaceOccurence)

stringReplace

public static String stringReplace(String org,
                                   String source,
                                   String destination,
                                   int replaceOccurence,
                                   boolean mustExact,
                                   boolean caseInsensitiveSearch)

stringReplaceCaseInsensitiveSearch

public static String stringReplaceCaseInsensitiveSearch(String org,
                                                        String source,
                                                        String destination)

stringReplaceExact

public static String stringReplaceExact(String org,
                                        String source,
                                        String destination)

stringReplaceRecursive

public static String stringReplaceRecursive(String org,
                                            String source,
                                            String destination)

stringSafeEquals

public static boolean stringSafeEquals(String left,
                                       String right)
Compares two strings no matter if they are null

Parameters:
left - string
right - string
Returns:
true if they are the same

stringSplit

public static String[] stringSplit(String string,
                                   int separator,
                                   int escape)

stringSplit

public static String[] stringSplit(String s,
                                   String split)

toEnglishLocaleLowerCase

public static String toEnglishLocaleLowerCase(String text)

toMultilineMarkup

public static CharSequence toMultilineMarkup(CharSequence s)
Converts a String to multiline HTML markup by replacing newlines with line break entities (<br/>) and multiple occurrences of newline with paragraph break entities (<p>).

Parameters:
s - String to transform
Returns:
String with all single occurrences of newline replaced with <br/> and all multiple occurrences of newline replaced with <p>.

unescape

public static String unescape(String string,
                              int escape)

writeTXTFile

public static boolean writeTXTFile(File file,
                                   String content)

writeTXTFile

public static boolean writeTXTFile(File f,
                                   String content,
                                   Charset charset)

Copyright © 2010 Servoy B.V.