net.sf.gsaapi.util
Class Util

java.lang.Object
  extended bynet.sf.gsaapi.util.Util

public class Util
extends java.lang.Object

Utilities class. Mostly intended for internal use.

Author:
Amol S Deshmukh adeshmuk .at inxight .dot com

Constructor Summary
Util()
           
 
Method Summary
static void appendMappedQueryParams(java.lang.StringBuffer sbuf, java.lang.String param, java.util.Map fieldsMap, java.lang.String delimiter)
          For example, appends "¶m=key1:value1|key2:value2|key3:value3" to the specified StringBuffer.
static void appendQueryParam(java.lang.StringBuffer sbuf, java.lang.String param, java.lang.String value)
          For example, appends "¶m=value" to StringBuffer.
static void appendQueryParam(java.lang.StringBuffer sbuf, java.lang.String param, java.lang.String[] values)
          invokes appendQueryParam(StringBuffer, String, String) on each of the values.
static java.lang.String encode(java.lang.String value)
          url encodes but catches UnsupportedEncodingException (since we know that will never be thrown).
static java.lang.String escape(java.lang.String str, java.lang.String defolt)
          returns defolt if the URLEncoder.encode(str, "UTF-8") call fails.
static java.lang.String getString(java.lang.Object obj, java.lang.String defolt)
          calls the overloaded public method: getString(Object, String, boolean) with the value true for the boolean parameter
static java.lang.String getString(java.lang.Object obj, java.lang.String defolt, boolean nullstrict)
          Returns obj.toString() if obj is not null and if the expression !
static java.lang.String stringSeparated(java.util.List tokens, java.lang.String prefix, java.lang.String delim)
          Given a list of string tokens, returns the string <prefix><token1><delim><prefix><token2><delim><prefix><tokenN> .
static java.lang.String stringSeparated(java.lang.String[] tokens, java.lang.String prefix, java.lang.String delim)
          overloaded form of stringSeparated(List, String, String) that takes String[] instead of List
static java.lang.String toHtmlCode(char c)
          converts the character to HTML entity &#c; where c is the integer value of the character.
static long toJulian(java.util.Date date)
          Converts a java.util.Date instance to a long value representing the Julian Day Number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

getString

public static java.lang.String getString(java.lang.Object obj,
                                         java.lang.String defolt)
calls the overloaded public method: getString(Object, String, boolean) with the value true for the boolean parameter


getString

public static java.lang.String getString(java.lang.Object obj,
                                         java.lang.String defolt,
                                         boolean nullstrict)
Returns obj.toString() if obj is not null and if the expression !nullstrict || !"".equals(obj.toString()) evaluates to true. Otherwise returns the value specified by the defolt parameter.

Parameters:
obj - The object to be converted to String.
defolt - The String value to be returned if conversion fails.
nullstrict - Whether the result of obj#toString should be returned (rather than defolt) even if it is an empty string.
Returns:
Returns the result of toString invokation on the object if the object is non null and toString representation is not null or an empty string. Else returns the defolt value.

stringSeparated

public static final java.lang.String stringSeparated(java.util.List tokens,
                                                     java.lang.String prefix,
                                                     java.lang.String delim)
Given a list of string tokens, returns the string <prefix><token1><delim><prefix><token2><delim><prefix><tokenN> .

Parameters:
tokens - The list of String tokens.
prefix - The prefix to be used for each token.
delim - The delimiter that separates each token.
Returns:
returns a single string starting with the prefix and followed by tokens separated with the delim

stringSeparated

public static final java.lang.String stringSeparated(java.lang.String[] tokens,
                                                     java.lang.String prefix,
                                                     java.lang.String delim)
overloaded form of stringSeparated(List, String, String) that takes String[] instead of List

Parameters:
tokens -
prefix -
delim -
Returns:
returns a single string starting with the prefix and followed by tokens separated with the delim

appendQueryParam

public static final void appendQueryParam(java.lang.StringBuffer sbuf,
                                          java.lang.String param,
                                          java.lang.String value)
For example, appends "¶m=value" to StringBuffer. value is URLEncoded before appending.

Parameters:
sbuf -
param -
value -

appendQueryParam

public static final void appendQueryParam(java.lang.StringBuffer sbuf,
                                          java.lang.String param,
                                          java.lang.String[] values)
invokes appendQueryParam(StringBuffer, String, String) on each of the values.

Parameters:
sbuf -
param -
values -

appendMappedQueryParams

public static final void appendMappedQueryParams(java.lang.StringBuffer sbuf,
                                                 java.lang.String param,
                                                 java.util.Map fieldsMap,
                                                 java.lang.String delimiter)
For example, appends "¶m=key1:value1|key2:value2|key3:value3" to the specified StringBuffer.

Parameters:
sbuf - StringBuffer to which the query param string is appended.
param - name of the query parameter.
fieldsMap - the map of field names and values which together form the "value" of the query param.

encode

public static final java.lang.String encode(java.lang.String value)
url encodes but catches UnsupportedEncodingException (since we know that will never be thrown).

Parameters:
value - String to be url encoded.
Returns:
returns the UTF-8 url-encoded string or empty string if "UTF-8" encoding is not supported on the current platform.

toHtmlCode

public static java.lang.String toHtmlCode(char c)
converts the character to HTML entity &#c; where c is the integer value of the character.

Parameters:
c - the character to be encoded as HTML entity.
Returns:
returns the html entity reference string for the specified character.

escape

public static java.lang.String escape(java.lang.String str,
                                      java.lang.String defolt)
returns defolt if the URLEncoder.encode(str, "UTF-8") call fails. Else returns URLEncoder.encode(str, "UTF-8").

Parameters:
str - String to be url encoded.
defolt - Return value expected if conversion fails.
Returns:
the UTF-8 urlencoded string if encoding was successful else returns the value specified by the defolt parameter.

toJulian

public static long toJulian(java.util.Date date)
Converts a java.util.Date instance to a long value representing the Julian Day Number. The java.util.Date should represent a date later than "1 January 100 AD".
Note: The calculation done in this method is very simplistic and you should probably do some tests to verify that this works for your case. You may want to have a look at the unit tests for this method to see the range of dates for which this method has been tested.

Parameters:
date - The java.util.Date instance to be converted to its corresponding Julian Day Number representation.
Returns:
a long value representing the Julian Day Number.


© Copyright 2006 Inxight Software, Inc.