SilverStream
Application Server 3.5

com.sssw.rt.util
Class AgParse

java.lang.Object
 |
 +--com.sssw.rt.util.AgParse

public final class AgParse
extends Object

The AgParse class provides static methods to perform parsing of the strings representing long, double, date, time and timestamp objects. It tries to "intelligently" parse the string - if the specified style or pattern doesn't work, it tries a list of common styles and patterns.

For a listing of formatting patterns and styles, see Formatting Patterns and Styles. Also, see the JDK documentation on NumberFormat, DateFormat, DecimalFormat, SimpleDateFormat, and Locale.

Note that when parsing a date string, the return value will be a java.sql.Date, not a java.util.Date. Note also that expontial notation, percent, and per mille are not currently supported for BigDecimals.

This class provides the constants listed in the table below. These are used with the parse type parameter. The AgParse.parse() methods can also be specifed as parse functions in the SilverStream Expression Builder. The Expression Builder functions have the type parameter built in. For example, the Expression Builder parseDate function is equivalant to AgParse.parse(AgParse.TYPE_DATE).

Class Constant

Expression Builder function

  • TYPE_LONG
  • parseLong

  • TYPE_DOUBLE
  • parseDouble

  • TYPE_DATE
  • parseDate

  • TYPE_TIME
  • parseTime

  • TYPE_TIMESTAMP
  • parseTimeStamp

    See Also:
    AgFormat

    Field Summary
    static int TYPE_INT
              Passthrough to DatatypeCodes constants.
     
    Method Summary
    static int get2DigitYearWindow()
              This method returns the 2-digit year "sliding window" value, which determines how 2-digit years are parsed.
    static Object parse(int type, String parseStr, String pattern)
              Parse a string and return the resulting object.
    static Object parse(int type, String parseStr, String pattern, int style)
              Parse a string and return the resulting object.
    static Object parse(int type, String parseStr, String pattern, int timeStyle, int dateStyle)
              Parse a string and return the resulting object.
    static Object parse(int type, String parseStr, String pattern, int style1, int style2, Locale locale, String zoneStr)
              Parse a string and return the resulting object.
    static Object parse(int type, String parseStr, String pattern, int style1, int style2, String lang, String country, String variant, String zoneStr)
              Parse a string and return the resulting object.
    static void set2DigitYearWindow(int value)
              This method sets the 2-digit year "sliding window" value, which determines how 2-digit years are parsed.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    TYPE_INT

    public static final int TYPE_INT
    Passthrough to DatatypeCodes constants.
    Method Detail

    parse

    public static Object parse(int type,
                               String parseStr,
                               String pattern)
                        throws IllegalArgumentException
    Parse a string and return the resulting object.
    Parameters:
    type - DatatypeCodes mapping of the datatype.
    parseStr - the string to parse
    pattern - string, overrides default pattern. See Formatting Patterns and Styles
    Returns:
    object or IllegalArgumentException
    Usage:

    This is the most commonly used method in the class. The pattern is often null. If it is null, then a list of common patterns and styles is used to try to parse the string.

    If it is not null, then the specified pattern is tried first. If that pattern fails, then the list of common patterns and styles is used.

    Example:

    This code parses a String into a Double:

     	Double d;
     	d = (Double)AgParse.parse(AgParse.TYPE_DOUBLE, "3.33", null)
     
    This code parses a String into a Timestamp:
     	java.sql.Timestamp ts;
     	ts = (java.sql.Timestamp)AgParse.parse(AgParse.TYPE_TIMESTAMP,
     					"1992-10-10 20:20:20", null)
     

    parse

    public static Object parse(int type,
                               String parseStr,
                               String pattern,
                               int style)
                        throws IllegalArgumentException
    Parse a string and return the resulting object.
    Parameters:
    type - DatatypeCodes mapping of the datatype (Date, Time).
    parseStr - the string to parse
    pattern - string, overrides default pattern
    style - int, overrides default style See Formatting Patterns and Styles
    Returns:
    object or IllegalArgumentException
    Usage:

    The pattern parameter overrides the style parameter. If the pattern parameter is null, then the style parameter is used.


    parse

    public static Object parse(int type,
                               String parseStr,
                               String pattern,
                               int timeStyle,
                               int dateStyle)
                        throws IllegalArgumentException
    Parse a string and return the resulting object.
    Parameters:
    type - DatatypeCodes mapping of the datatype (Date, Time).
    parseStr - the string to parse.
    pattern - string, overrides default pattern.
    timeStyle - int, overrides default style for time.
    dateStyle - int, overrides default style for date. See Formatting Patterns and Styles
    Returns:
    object or IllegalArgumentException
    Usage:

    The pattern parameter overrides the style parameter. If the pattern parameter is null, then the style parameters are used.


    parse

    public static Object parse(int type,
                               String parseStr,
                               String pattern,
                               int style1,
                               int style2,
                               String lang,
                               String country,
                               String variant,
                               String zoneStr)
                        throws IllegalArgumentException
    Parse a string and return the resulting object.
    Parameters:
    type - DatatypeCodes mapping of the datatype.
    parseStr - the string to parse.
    pattern - string, overrides default pattern. See Formatting Patterns and Styles.
    lang - specifies the language of the desired Locale. This is the lower-case two-letter codes as defined by ISO-639. These codes should only be used programmatically. You can find a full list of these codes at a number of sites, such as: http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
    country - specifies the country of the desired Locale. This is the upper-case two-letter codes defined by ISO-3166. These codes should only be used programmatically. You can find a full list of these codes at a number of sites, such as: http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
    variant - specifies the variant of the desired Locale. Defaults to your machine. Variant codes are vendor and browser-specific. For example, the variant code for a Macintosh PC is MAC; for a POSIX machine, the code is POSIX. Enter a null string for this attribute for default behavior.
    zoneStr - specifies the timezone. This parameter overrides the default timezone. This parameter applies only to the Timestamp data types. Specify an empty String for any other data type.
    Returns:
    object or IllegalArgumentException
    Usage:

    The pattern parameter overrides the style parameter. If the pattern parameter is null, then the style parameters are used.


    parse

    public static Object parse(int type,
                               String parseStr,
                               String pattern,
                               int style1,
                               int style2,
                               Locale locale,
                               String zoneStr)
                        throws IllegalArgumentException
    Parse a string and return the resulting object.
    Parameters:
    type - DatatypeCodes mapping of the datatype.
    parseStr - the string to parse.
    pattern - string, overrides default pattern.
    timeStyle - int, overrides default style for time.
    dateStyle - int, overrides default style for date. See Formatting Patterns and Styles.
    locale - java.util.Locale, overrides default locale.
    zoneStr - string, overrides default time zone. This parameter applies only to the Timestamp data type. Specify an empty String for any other data type. Specify an empty String for any other data type.
    Returns:
    object or IllegalArgumentException
    Usage:

    The pattern parameter overrides the style parameter. If the pattern parameter is null, then the style parameters are used.


    set2DigitYearWindow

    public static void set2DigitYearWindow(int value)
    This method sets the 2-digit year "sliding window" value, which determines how 2-digit years are parsed. Numbers below this value are interpreted as 21st-century dates; numbers equal to or above this value are interpreted as 20th-century dates.
    Parameters:
    value - the year
    Usage:

    For example, if the window value is 50 (the default), then

    • "00" becomes 2000
    • "49" becomes 2049
    • "50" becomes 1950
    • "99" becomes 1999

    To turn windowing off, so that all 2-digit years are interpreted as 20th-century dates, set this value to zero.

    Note that if the user enters a 4-digit year, this window value is ignored, and the year is always parsed correctly.


    get2DigitYearWindow

    public static int get2DigitYearWindow()
    This method returns the 2-digit year "sliding window" value, which determines how 2-digit years are parsed.
    See Also:
    AgParse.set2DigitYearWindow(int)

    SilverStream
    Application Server 3.5