com.iphrase.runtime
Class Tools

java.lang.Object
  |
  +--com.iphrase.runtime.Tools

public class Tools
extends java.lang.Object

Static utility methods used throughout the API and available for clients.


Constructor Summary
Tools()
           
 
Method Summary
static java.lang.String cleanUrl(java.lang.String url)
          Clean up a URL as necessary.
static java.lang.String[] clone(java.lang.String[] source)
          Clone a source String array by returning either a 0-element String array, if the source array is null, otherwise the source array itself.
static java.lang.String[] copy(java.lang.String[] source)
          Copy a source String array by allocating a target array of the same length and doing a shallow copy of each source to target element.
static java.lang.String decode(java.lang.String s, java.lang.String enc)
          Decodes an application/x-www-form-urlencoded string using a specific encoding scheme.
static java.lang.String encode(java.lang.String s, java.lang.String enc)
          Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme.
static java.lang.String escape(java.lang.String s, java.lang.String delim)
          Escape any occurance of delim in the designated string by doubling it.
static java.lang.String escape(java.lang.String s, java.lang.String[] delims)
          Escape any occurance of all delimeters in the designated string by doubling them.
static java.lang.String escapeJS(java.lang.String s)
          Convert problem characters to JavaScript Escaped values.
static java.lang.String getDfltEncName()
           
static java.lang.String getVersion()
           
static boolean isTrue(java.lang.String s)
          Determine whether the designated string is one of the many representations of boolean true.
static java.lang.String join(java.lang.String[] array, java.lang.String delim)
          Opposite of split.
static java.util.Calendar newCalendar(int[] fields)
          Attempt to create a Calendar object from an iPhrase datetime field array.
static java.lang.String replaceAll(java.lang.String s, java.lang.String pattern, java.lang.String replacement)
          Replace all occurrances of pattern with replacement.
static void setDfltEncName(java.lang.String encoding)
           
static java.lang.String[] split(java.lang.String s, java.lang.String delim)
          Unlimited version of split(String s, String delim, int limit) (i.e.
static java.lang.String[] split(java.lang.String s, java.lang.String delim, int limit)
          Similar to JDK 1.4 public String[] split(String regex, int limit), except: delim is a simple string, not a regex any occurance of double delim is considered to be a single, escaped delim that does not split, but remains within the string limit == 0 does not remove trailing empty strings from the array. String.split doesn't appear until JDK 1.4: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String,%20int)
static java.lang.String unescape(java.lang.String s, java.lang.String delim)
          Unescape any occurance of double delim in the designated string by singling it.
static java.lang.String urlDecode(java.lang.String s)
          Uses dfltEncName encoding to convert a string that has been encoded for transmission in a URL into a decoded string.
static java.lang.String urlDecode(java.lang.String s, java.lang.String enc)
          Converts a string that has been encoded for transmission in a URL into a decoded string.
static java.lang.String urlEncode(java.lang.String s)
          Converts a URL string for reliable HTTP transmission from the Web server to a client.
static java.lang.String urlEncode(java.lang.String s, java.lang.String enc)
          Uses dfltEncName encoding to convert a URL string for reliable HTTP transmission from the Web server to a client.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools

public Tools()
Method Detail

setDfltEncName

public static void setDfltEncName(java.lang.String encoding)

getDfltEncName

public static java.lang.String getDfltEncName()

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String delim)
Unlimited version of split(String s, String delim, int limit) (i.e. limit == 0).
Parameters:
s - String to split
delim - String delimiter to split on
Returns:
String array of splits

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String delim,
                                       int limit)
Similar to JDK 1.4 public String[] split(String regex, int limit), except: String.split doesn't appear until JDK 1.4: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String,%20int)
Parameters:
s - String to split
delim - String delimiter to split on
limit - number of splits, or equal or less then 0 for unlimited
Returns:
String array of splits

join

public static java.lang.String join(java.lang.String[] array,
                                    java.lang.String delim)
Opposite of split. Any occurance of delim in a string will be escaped by doubling.
Parameters:
array - of String to join
delim - String delimiter to join with
Returns:
joined String, empty ("") string for 0-length array, or null for null array

escapeJS

public static java.lang.String escapeJS(java.lang.String s)
Convert problem characters to JavaScript Escaped values.
Parameters:
{@link - String} to be escaped
Returns:
the resulting escaped String

escape

public static java.lang.String escape(java.lang.String s,
                                      java.lang.String delim)
Escape any occurance of delim in the designated string by doubling it.
Parameters:
s - the String to be escaped
delim - the String to escape
Returns:
the resulting escaped String

escape

public static java.lang.String escape(java.lang.String s,
                                      java.lang.String[] delims)
Escape any occurance of all delimeters in the designated string by doubling them.
Parameters:
s - the String to be escaped
delims - the list of delimeters to escape
Returns:
the resulting escaped String

unescape

public static java.lang.String unescape(java.lang.String s,
                                        java.lang.String delim)
Unescape any occurance of double delim in the designated string by singling it.
Parameters:
s - the String to be unescaped
delim - the String to unescape
Returns:
the resulting unescaped String

replaceAll

public static java.lang.String replaceAll(java.lang.String s,
                                          java.lang.String pattern,
                                          java.lang.String replacement)
Replace all occurrances of pattern with replacement. Unlike the JDK 1.4 String.replaceAll method, pattern is NOT a regex.
Parameters:
s - String in which pattern is replaced
pattern - String pattern to be replaced (NOT a regex)
replacement - String that replaces patterm
Returns:
replaced String

clone

public static java.lang.String[] clone(java.lang.String[] source)
Clone a source String array by returning either a 0-element String array, if the source array is null, otherwise the source array itself.
Parameters:
source - String array
Returns:
target String array

copy

public static java.lang.String[] copy(java.lang.String[] source)
Copy a source String array by allocating a target array of the same length and doing a shallow copy of each source to target element. If the source array is null, allocate and return a 0-element String array.
Parameters:
source - String array
Returns:
target String array

isTrue

public static boolean isTrue(java.lang.String s)
Determine whether the designated string is one of the many representations of boolean true.
Parameters:
s - the designated String
Returns:
true if the string indicates truth, else false

newCalendar

public static java.util.Calendar newCalendar(int[] fields)
                                      throws ArgumentError
Attempt to create a Calendar object from an iPhrase datetime field array.
Parameters:
fields - array of 1 to 6 integer datetime components, integer values for [year, month, day, hour, minute, second]
Returns:
new Calendar
Throws:
ArgumentError -  

cleanUrl

public static java.lang.String cleanUrl(java.lang.String url)
Clean up a URL as necessary. For instance, replace Windows drive syntax "file://X:" with "file:///X|". If url is either null or empty, it will be returned as is.
Parameters:
url - String URL
Returns:
String cleaned up URL

urlEncode

public static java.lang.String urlEncode(java.lang.String s)
Converts a URL string for reliable HTTP transmission from the Web server to a client. Also makes string safe for JavaScript by hex-encoding single-quotes and possibly other chars as well.
Parameters:
s - String to URL-encode
Returns:
URL-encoded String
See Also:
getDfltEncName(), setDfltEncName(java.lang.String)

urlDecode

public static java.lang.String urlDecode(java.lang.String s,
                                         java.lang.String enc)
Converts a string that has been encoded for transmission in a URL into a decoded string.
Parameters:
s - String to URL-decode
enc - The name of a supported character encoding.
Returns:
URL-decoded String
See Also:
getDfltEncName(), setDfltEncName(java.lang.String)

urlEncode

public static java.lang.String urlEncode(java.lang.String s,
                                         java.lang.String enc)
Uses dfltEncName encoding to convert a URL string for reliable HTTP transmission from the Web server to a client. Also makes string safe for JavaScript by hex-encoding single-quotes and possibly other chars as well.
Parameters:
s - String to URL-encode
enc - The name of a supported character encoding.
Returns:
URL-encoded String
See Also:
getDfltEncName(), setDfltEncName(java.lang.String)

urlDecode

public static java.lang.String urlDecode(java.lang.String s)
Uses dfltEncName encoding to convert a string that has been encoded for transmission in a URL into a decoded string.
Parameters:
s - String to URL-decode
Returns:
URL-decoded String
See Also:
getDfltEncName(), setDfltEncName(java.lang.String)

getVersion

public static java.lang.String getVersion()
Returns:
Implementation-Version manifest package attribute

decode

public static java.lang.String decode(java.lang.String s,
                                      java.lang.String enc)
                               throws java.io.UnsupportedEncodingException,
                                      ArgumentError
Decodes an application/x-www-form-urlencoded string using a specific encoding scheme.
Parameters:
s - the String to decode
enc - The name of a supported character encoding.
Returns:
the newly decoded String
Throws:
java.io.UnsupportedEncodingException - - If the named encoding is not supported

encode

public static java.lang.String encode(java.lang.String s,
                                      java.lang.String enc)
                               throws java.io.UnsupportedEncodingException
Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.

Parameters:
s - String to be translated.
enc - The name of a supported character encoding.
Returns:
the translated String.
Throws:
java.io.UnsupportedEncodingException - If the named encoding is not supported
Since:
1.4

© Copyright 2005, 2006. IBM Corporation. All rights reserved.