IMC Epclient 5.0.3

at.spardat.enterprise.fmt
Class FmtFactory

java.lang.Object
  extended byat.spardat.enterprise.fmt.FmtFactory

public class FmtFactory
extends java.lang.Object

This class is a factory that allows to construct all the formatters/validators provided in this package by using a String-specification.

The specification starts with a component indicating the type, then follows a list of additional parameters needed for the particular type and usually ends with a combination of style-constants. All components are separated by comma. Example:

 n,13,2,m&t
 
denotes a numeric formatter (n) that accepts at most 13 digits in front of the comma, at most 2 digits after the comma and has two styles m and t, expressing that mandatory (m) input is required and (t) thousands-separation characters are used. Here are some more examples
 format         meaning
 s,35                  String which must not be longer than 35 digits.
 s,35,m                As above, but mandatory, i.e., must not be empty.
 sm,5,5,m              Exactly 5 characters.
 sr,0,35,a-c           String of length not more than 35 consisting only of characters { 'a', 'b', 'c' }.
 n,13,2,m&t            Numeric with at most 13 digits before and 2 after the dec-point, example:
                       -1.000.000,99 in the austrian locale
 n,-1,2,nn&m           10000000000000,99 in the austrian locale. Negative inputs are not allowed.
                       May consist of arbitrary long sequence of digits in front of dec-point.
 nr,-1,0,5,596         Integer number between 5 and 596.
 nr,13,0,inf,596       Integer number between -9999999999999 and 596.
 d                     Date using the format 24.04.2000 (this is Locale-dependent).
 d,m                   As above, but input is required.
 d,m&ful               Mandatory date using the format "Montag, 24. April 2000", although this is locale-dependent.
 dr,0,7,m              Mandatory date that must lie in the range [today ... today plus 7 days].
 dr,20000101,20101231  Date that must lie in the range [1.1.2000 ... 31.12.2010].
 dp,dd-MM-yyyy,m       Mandatory, non-localized date format, e.g., "24-04-2000".
 
Here is the more formal definitions of the format specifications:
 s,maxLen(,style)
     String with arbitrary characters of max length maxLen. -1 for maxLen
     means unrestricted maximum length. With an optional third component, a style { m,uc,lc}
     may be specified.
     create may be used without a Locale.

 sm,minLen,maxLen(,style)
     Like the last, with the exception that an accepted string must have at least
     a length of minLen. The empty string is accepted unless style m
     is specified.

 sr,minLen,maxLen,range(,style)
     String of maximum length maxLen and minimum len minLen. Both minLen
     and maxLen may be empty of inf to denote "unrestrictedness".
     The character set is restricted to
     a range specification range, e.g., a-z denotes for example all unicode characters
     greater equal to a and less equal to z. For a detailed description see
     class AStringFmtRange.
     With the last optional parameter style, the styles {m,uc,lc} may be specified.
     create may be used without a Locale.

 sre,(minLen),(maxLen),(range),(m&ul&lc),bundleKey,resBundle,regex
     The values in brackets can be empty strings, all commas are mandatory.
     String of maximum length maxLen and minimum len minLen. Both minLen
     and maxLen may be empty of inf to denote "unrestrictedness".
     The character set is restricted to
     a range specification by the optional string range, e.g., a-z denotes for example all unicode characters
     greater equal to a and less equal to z. For a detailed description see
     class AStringFmtRange.
     The optional parameter style, the styles {m,uc,lc} may be specified.
     create may be used without a Locale.
     For the error message shown in the case of a negative evaluation of the regular expression
     a bundleKey identifying the error message and a resBundle (without locale)
     from which the error message is taken have to be specified.
     regex states the regular expression which validates the input.
     The regular expression interpretation/validation is done by the java.util.regex classes,
     see there for the proper regular expression usage.

 n,beforeC,afterC(,style)
     Numeric value with at most beforeC digits before and afterC digits
     after the decimal point. Both may be -1 or empty, indicating unlimited length.
     An optional last parameter style that may adopt values out of { m, t, nn }
     may be specified.
     create requires a Locale.
     Example: "n,13,2,nn&t" specifies a numeric value with 13 digits before and 2
              after the comma. It is displayed with thousands separation chars
              and does not accept negative values when entered.

 nr,beforeC,afterC,min,max(,style)
     Behaves like the last one, additionally lower and upper bounds concerning the legal
     input values, that is the parameters min and max are specified. Both,
     min and max expect a string encoding of a double as is accepted by
     the method Double.parseDouble. If you want to let one of either min
     or max unrestricted, specify inf which denotes infinity.
     FmtFactory.create requires a Locale.

 np,pattern,beforeC,afterC(,style)
     Specifies a numeric format by using a java.text.DecimalFormat-pattern.
     The style parameter may adopt values out of { m, nn }. Please note that
     the number of decimal places in the pattern must match afterC. Also note
     that java.text.DecimalFormat internally uses doubles and therefore
     the maximum number of digits that may be represented without loss of precision
     is 15.
     FmtFactory.create requires a Locale.

 d(,style)
     Specifies a date format. If a style is specified, it must be one of { sho, med, lon, ful }
     optionally combined with { m }. If no style is specified, med is default.
     FmtFactory.create requires a Locale.

 dr,min,max(,style)
     Same as the last one, with the extension that lower- and/or upper-bounds for
     permissible dates are specified. Both min and max can be an absolute
     dates in the format yyyyMMdd or day-offsets relative to today,
     i.e., -1 stands for yesterday, 0 for today, 1 for tomorrow.
     inf stands for infinity and may be used if one of the two
     bounds is to be unspecified. The same is achieved if min or max
     is empty. Example:
     "dr,0,inf,m" or "dr,0,,m" specifies that a date must be entered (mandatory) and that is must
     not lie in the past (lower bound is today).
     "dr,,7" specifies that permissible dates are the ones in the past up to
     today plus one week.
     "dr,19000101,," specifies that the entered date must be 1.1.1900 or later.
     FmtFactory.create requires a Locale.

 dp,pattern(,style)
     Specifies a date format by using a java.text.SimpleDateFormat-pattern.
     For the last optional style-parameter, m (mandatory) may be used.
     FmtFactory.create may be used without Locale.
     Please note that this pattern does not work with internationalization since
     you are specifying the pattern directly. In international applications, use
     d(,style) instead.

 ts(,dateStyle(,timeStyle))
     Specifies a timestamp format. Styles may be specified for both the date-component
     and the time-component (or only the date-component) that are values out of { sho, med, lon, ful }.
     If input should be mandatory, m-style may be combined with either style.
     FmtFactory.create requires a Locale.

 tsp,pattern(,style)
     Specifies a timestamp format by using a java.util.SimpleDateFormat-pattern.
     style is optional and may be m.
     FmtFactory.create requires a Locale.
     Please note that this pattern does not work with internationalization since
     you are specifying the pattern yourself. In international applications, use
     ts(,...) instead.

 
The following list defines the style-strings supported:
 styles     description
 m                 mandatory; non-empty input must be provided
 t                 used with numeric types and indicates that thousands separation characters
                   should be used.
 nn                used with numeric types and indicates that just positive numbers including
                   zero may be entered (i.e., no negative numbers).
 sz                suppressZero; used with numeric types to display zero as empty string and,
                   vice versa, an empty UI-string becomes zero.
 sho               denotes a short date/time format, e.g., 24.04.00
 med               denotes medium data/time format, e.g., 24.04.2000
 lon               denotes long date/time format, e.g., 24. April 2000
 ful               denotes full date/time format, e.g., Montag, 24. April 2000
 uc                uppercase; input is converted to uppercase; used with strings
 lc                lowercase; input is converted to lowercase; used with strings
 
Wherever style-components are requested, you may enter a combination of styles appending them with the &sign. For example, m&nn describes a number where input must be entered and the provided input must not be negative.

Comma is used as delimiter to separate the components. What if one component itself needs to have a comma? Then you must use a percent-character as escape-character. For example, suppose you need a dp-spec where the SimpleDateFormat-pattern is EEE, dd.MM. Then the dp-spec must look like

 dp,EEE%, dd.MM
 
If the component should contain a percent itself, you must use a double-percent instead.

Author:
YSD

Constructor Summary
FmtFactory()
           
 
Method Summary
static IFmt create(java.lang.String spec)
          Creates a formatter according to a provided specification that must follow the rules defined above.
static IFmt create(java.lang.String spec, java.util.Locale l)
          Creates a formatter according to a provided specification that must follow the rules defined above.
protected  IFmt createImpl(java.lang.String spec, java.util.Locale l)
          This method actually does the work and is responsible to create an IFmt.
protected  double getDoubleToken(StringSplitter ss, java.lang.String expected)
          Helper method that extracts the next token that must be a double as required by Double.parseDouble and throws an Exception if there are no more tokens.
protected  int getIntToken(StringSplitter ss, java.lang.String expected)
          Helper method that extracts the next token that must be an integer and throws an exception if there is no more token.
protected  int getIntToken2(StringSplitter ss, java.lang.String expected)
          Same as getIntToken, except that if the token is inf or empty, then -1 is returned.
protected  int getStyle(StringSplitter ss)
          Extracts the next token from ss, expects a list of style-strings that are separated by ampersands.
protected  int getStylePart(java.lang.String style)
          Looks up the hashmap of predefined styles and returns the integer-value or throws a RuntimeException if the style is not in the hashmap.
protected  java.lang.String getToken(StringSplitter ss, java.lang.String expected)
          Helper method to extract the next token or to throw an exception if there is no more token.
static void setFactory(FmtFactory fac)
          Enables an application to change the used factory-implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FmtFactory

public FmtFactory()
Method Detail

create

public static IFmt create(java.lang.String spec)
Creates a formatter according to a provided specification that must follow the rules defined above. This method does not require a Locale, therefore should only be used with formats that are not localizable (see above). But if some particular format needs a Locale and this method is called, Locale.getDefault is used instead.

Parameters:
spec - the specification
Returns:
newly created formatter

create

public static IFmt create(java.lang.String spec,
                          java.util.Locale l)
Creates a formatter according to a provided specification that must follow the rules defined above.

Parameters:
spec - the specification
l - the locale required for formatter-classes that are locale-dependent.
Returns:
newly created formatter

setFactory

public static void setFactory(FmtFactory fac)
Enables an application to change the used factory-implementation. The provided object must be a subclass of this class.


createImpl

protected IFmt createImpl(java.lang.String spec,
                          java.util.Locale l)
This method actually does the work and is responsible to create an IFmt.

Parameters:
spec - specification
l - Locale
Returns:
formatter
Throws:
java.lang.RuntimeException - on illegal inputs

getToken

protected java.lang.String getToken(StringSplitter ss,
                                    java.lang.String expected)
Helper method to extract the next token or to throw an exception if there is no more token.


getIntToken

protected int getIntToken(StringSplitter ss,
                          java.lang.String expected)
Helper method that extracts the next token that must be an integer and throws an exception if there is no more token.

Parameters:
ss - the input stream where the next token has to be extracted
expected - text to be used in error messages
Returns:
an parsed integer; the integer is Integer.MAX_VALUE if the token is inf (infinity). the integer is Integer.MIN_VALUE if the token is empty.

getIntToken2

protected int getIntToken2(StringSplitter ss,
                           java.lang.String expected)
Same as getIntToken, except that if the token is inf or empty, then -1 is returned.


getDoubleToken

protected double getDoubleToken(StringSplitter ss,
                                java.lang.String expected)
Helper method that extracts the next token that must be a double as required by Double.parseDouble and throws an Exception if there are no more tokens.

Parameters:
ss - the input stream
expected - text to be used in error messages
Returns:
a parsed double; the returned value is Double.POSITIVE_INFINITY if the token is inf.

getStyle

protected int getStyle(StringSplitter ss)
Extracts the next token from ss, expects a list of style-strings that are separated by ampersands. If there is no more token in ss, zero is returned.

Parameters:
ss - the input StringSplitter whose next token is optionally extracted.
Returns:
bit-or combination of styles.

getStylePart

protected int getStylePart(java.lang.String style)
Looks up the hashmap of predefined styles and returns the integer-value or throws a RuntimeException if the style is not in the hashmap.


IMC Epclient 5.0.3