org.locomotive.util
Class StringConstraint

java.lang.Object
  |
  +--org.locomotive.util.StringConstraint

Deprecated. in favor of org.locomotive.util.StringUtil.

public class StringConstraint
extends java.lang.Object

This is a general, powerful way to constrain String values and generate errors on specific criteria. Here's an example of usage:

     String username = (String) hd.form_hash.get("USERNAME");
     StringConstraint sc = new StringConstraint("USERNAME",
         "DEFINED TIDY NO_WHITESPACE ISALPHANUM " +
         "LENGTH_GREATERTHAN=1 MAXSIZE=" + MAX_USERNAME_LENGTH + 
         " WARNTRUNC");
     StringBuffer errors = new StringBuffer();

     // this will append some error messages to errors, and also return a
     // new String which is a cleaned-up verison of the username.
     username = sc.check(username, errors);
 
The constraints are performed or evaluated in order. Here are all the valid constraints, all specified as words within the String that is the second argument in the constructor:

Constraints which result in errors:

  1. DEFINED - hash variable with associated name must be defined, ie, the string is not set to null

  2. NO_WHITESPACE - requires string to be solid word

  3. NOTNULL - require that the string is not the null string (""), (must be defined in order for this check to be run)

  4. LENGTH_GREATERTHAN=## - requires size to be larger than the integer argument included

  5. WARNTRUNC - error if the MAXSIZE action resulted in resizing (chopping) the string

  6. ISINT - requires the string to contain the string value of an int

  7. ISDATE - requires the string to contain a date (MM-DD-YY) (use timestamp)

  8. ISTIMESTAMP - requires the string to contain valid Timestamp which may have any of the following four forms:

    (YY-MM-DD) (YY-MM-DD HH:MM:SS) (YYYY-MM-DD) (YYYY-MM-DD HH:MM:SS)

  9. ISALPHANUM - requires the string to contain alphanumerics only

  10. ISEMAIL - requires the string to contain an email address (user@domain.type)

    Constraints which modify the input string:

    Constraints which affect total processing behavior:

    Since:
    LAS 2.0
    Version:
    %I%, %G%

    Constructor Summary
    StringConstraint(java.lang.String name, java.lang.String cons_list_string)
              Deprecated. See the documentation at the top of this class for an example.
     
    Method Summary
     void add(java.lang.String newconstraint)
              Deprecated. add a new constraint.
     java.lang.String check(java.lang.String stocheck, java.lang.StringBuffer error_sb)
              Deprecated. Check a string with the present set of constraints.
    static java.lang.String checkHashWithConstraints(java.util.Hashtable check_hash, java.util.Hashtable constraints_hash)
              Deprecated. check all the values of a hash table against a hashtable containing a list of constraints.
     java.lang.String getProperName()
              Deprecated.  
     void overrideMessage(java.lang.String constraint, java.lang.String msg)
              Deprecated. Use the specified message instead of the default.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    StringConstraint

    public StringConstraint(java.lang.String name,
                            java.lang.String cons_list_string)
    Deprecated. 
    See the documentation at the top of this class for an example.
    Parameters:
    name - the name of this field, to be used in an error message.
    cons_list_string - a string containing all the constraints.
    Method Detail

    overrideMessage

    public void overrideMessage(java.lang.String constraint,
                                java.lang.String msg)
    Deprecated. 
    Use the specified message instead of the default.

    add

    public void add(java.lang.String newconstraint)
    Deprecated. 
    add a new constraint. See the constructor for the list of constraints

    checkHashWithConstraints

    public static java.lang.String checkHashWithConstraints(java.util.Hashtable check_hash,
                                                            java.util.Hashtable constraints_hash)
    Deprecated. 
    check all the values of a hash table against a hashtable containing a list of constraints.
    Parameters:
    check_hash - the hastable to check
    constraints_hash - a hastable containing StringConstraints, whose keys are the names of the keys in check_hash.

    check

    public java.lang.String check(java.lang.String stocheck,
                                  java.lang.StringBuffer error_sb)
    Deprecated. 
    Check a string with the present set of constraints. If there are errors, they will be appended to the StringBuffer.
    Returns:
    the string to be checked, which may have been modified by the constraints which were applied.

    getProperName

    public java.lang.String getProperName()
    Deprecated.