com.plumtree.portalpages.common.helpers
Class ModelHelper

java.lang.Object
  extended by com.plumtree.portalpages.common.helpers.ModelHelper
Direct Known Subclasses:
WSModelHelper

public class ModelHelper
extends java.lang.Object

Author:
adolfoc This class is for use in collecting and validating information sent to models. Although designed for Editor models, most of these methods will work with any model.

Constructor Summary
ModelHelper()
           
 
Method Summary
static boolean CheckIsURLString(java.lang.String strIn)
          Checks that a string starts with http:// or https://.
static boolean GetFormCheckboxBool(XPHashtable _htFormData, java.lang.String strFormElement)
          Gets a boolean Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.
static PTDuration GetFormElementDuration(XPHashtable _htFormData, java.lang.String strFormElementDurationInput, java.lang.String strFormElementDurationUnitsSelect, PTDuration ptdDefault)
          Gets a boolean Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.
static int GetFormElementInt(XPHashtable _htFormData, java.lang.String strFormElement, int nDefault)
          Gets an integer Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.
static long GetFormElementLong(XPHashtable _htFormData, java.lang.String strFormElement, long lDefault)
          Gets a long Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.
static java.lang.String GetFormElementString(XPHashtable _htFormData, java.lang.String strFormElement, java.lang.String strDefault)
          Gets a string Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.
static boolean HasTrailingSlash(java.lang.String strIn)
           
static boolean IsBlankString(java.lang.String sData)
          Checks to see if the string array passed in is null or of zero length
static boolean IsBlankStringArray(java.lang.String[] arsData)
          Checks to see if the string array passed in is null or of zero length OR the first element is a blank string.
static boolean IsEmptyStringArray(java.lang.String[] arsData)
          Checks to see if the string array passed in is null or of zero length
static XPArrayList ObjectArrayToXPArray(java.lang.Object[] arObj)
          Translates an Object array into an XPArrayList.
static boolean ObjectToBool(java.lang.Object objValue, boolean bDefault)
          Returns the value of objValue or bDefault if objValue is null or the conversion fails.
static int ObjectToInt(java.lang.Object objValue, int nDefault)
          Returns the value of objValue or nDefault if objValue is null or the conversion fails.
static boolean PBReadBool(IXPPropertyBag ptPropBag, java.lang.String sPropID, boolean bDefault)
          Reads a boolean value from a property bag.
static int PBReadInt(IXPPropertyBag ptPropBag, java.lang.String sPropID, int nDefault)
          Reads an int value from a property bag.
static java.lang.String PBReadString(IXPPropertyBag ptPropBag, java.lang.String sPropID, java.lang.String strDefault)
          Reads a String value from a property bag.
static void PBWrite(IXPPropertyBag ptPropBag, java.lang.String sPropID, boolean bValue)
          Writes a value to a property bag.
static void PBWrite(IXPPropertyBag ptPropBag, java.lang.String sPropID, int nValue)
          Writes a value to a property bag.
static void PBWrite(IXPPropertyBag ptPropBag, java.lang.String sPropID, long lValue)
          Writes a value to a property bag.
static void PBWrite(IXPPropertyBag ptPropBag, java.lang.String sPropID, java.lang.String strValue)
          Writes a value to a property bag.
static void PBWrite(IXPPropertyBag ptPropBag, java.lang.String sPropID, XPArrayList xpalValue)
          Writes a value to a property bag.
static XPArrayList StringArrayToXPArray(java.lang.String[] arsIn)
           
static java.lang.String TrimAllTrailingSlashes(java.lang.String strIn)
           
static java.lang.String TrimTrailingSlash(java.lang.String strIn)
           
static int ValidateBool(boolean bValid, AActivitySpace asOwner, java.lang.String strError, int nLastError)
          Validates an arbitrary boolean.
static int ValidateDurationRange(PTDuration ptdIn, AActivitySpace asOwner, java.lang.String strError, int nLastError, long lMinMilli, long lMaxMilli)
          Validates that a specified Duration falls within the specified duration range (specified in milliseconds).
static int ValidateInteger(java.lang.String integer, AActivitySpace asOwner, java.lang.String strError, int nLastError)
          Validates that the provided string is an integer, if not returns PAGE_STATUS_INVALID.
static int ValidateIntegerRange(int nIn, AActivitySpace asOwner, java.lang.String strError, int nLastError, int nMin, int nMax)
          Validates that an integer is within the specified range (nMin to nMax).
static int ValidateIsURLString(java.lang.String strIn, AActivitySpace asOwner, java.lang.String strError, int nLastError)
          Validates that a string starts with http:// or https://.
static int ValidateLoginPassword(java.lang.String strLogin, java.lang.String strPassword, java.lang.String strNULLPASSWORD, AActivitySpace asOwner, java.lang.String strError, int nLastError)
          Validates that both a login and password were set.
static int ValidateNonEmptyString(java.lang.String strIn, AActivitySpace asOwner, java.lang.String strError, int nLastError)
          Validates that a string is non-empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelHelper

public ModelHelper()
Method Detail

GetFormCheckboxBool

public static boolean GetFormCheckboxBool(XPHashtable _htFormData,
                                          java.lang.String strFormElement)
Gets a boolean Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty. NOTE: This assumes that booleans are defined in forms as follows. "0" == false Any non-zero integer (e.g. "1") == true

Parameters:
_htFormData -
strFormElement -
Returns:
boolean

GetFormElementDuration

public static PTDuration GetFormElementDuration(XPHashtable _htFormData,
                                                java.lang.String strFormElementDurationInput,
                                                java.lang.String strFormElementDurationUnitsSelect,
                                                PTDuration ptdDefault)
Gets a boolean Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty. NOTE: Unlike the other GetForm... methods defined in this class, the default value cannot be null. ptdDefault is used to retrieve the default MASK value (among other things).

Parameters:
_htFormData -
strFormElementDurationInput -
strFormElementDurationUnitsSelect -
ptdDefault -
Returns:
PTDuration

IsEmptyStringArray

public static boolean IsEmptyStringArray(java.lang.String[] arsData)
Checks to see if the string array passed in is null or of zero length

Parameters:
data -
Returns:

IsBlankStringArray

public static boolean IsBlankStringArray(java.lang.String[] arsData)
Checks to see if the string array passed in is null or of zero length OR the first element is a blank string.

Parameters:
data -
Returns:

IsBlankString

public static boolean IsBlankString(java.lang.String sData)
Checks to see if the string array passed in is null or of zero length

Parameters:
data -
Returns:

GetFormElementInt

public static int GetFormElementInt(XPHashtable _htFormData,
                                    java.lang.String strFormElement,
                                    int nDefault)
Gets an integer Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.

Parameters:
_htFormData -
strFormElement -
nDefault -
Returns:
String

GetFormElementLong

public static long GetFormElementLong(XPHashtable _htFormData,
                                      java.lang.String strFormElement,
                                      long lDefault)
Gets a long Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.

Parameters:
_htFormData -
strFormElement -
lDefault -
Returns:
String

GetFormElementString

public static java.lang.String GetFormElementString(XPHashtable _htFormData,
                                                    java.lang.String strFormElement,
                                                    java.lang.String strDefault)
Gets a string Form Element from a hashtable of form data - returns the default value if the form element was not found or is empty.

Parameters:
_htFormData -
strFormElement -
strDefault -
Returns:
String

ObjectArrayToXPArray

public static XPArrayList ObjectArrayToXPArray(java.lang.Object[] arObj)
Translates an Object array into an XPArrayList. Returns an empty XPArrayList if arObj is null.

Parameters:
arObj -
Returns:
XPArrayList

ObjectToBool

public static boolean ObjectToBool(java.lang.Object objValue,
                                   boolean bDefault)
Returns the value of objValue or bDefault if objValue is null or the conversion fails.


ObjectToInt

public static int ObjectToInt(java.lang.Object objValue,
                              int nDefault)
Returns the value of objValue or nDefault if objValue is null or the conversion fails.


PBReadBool

public static boolean PBReadBool(IXPPropertyBag ptPropBag,
                                 java.lang.String sPropID,
                                 boolean bDefault)
Reads a boolean value from a property bag. Returns bDefault if the value was not found or an error occurred.

Parameters:
sPropID -
ptPropBag -
bDefault -
Returns:
boolean

PBReadInt

public static int PBReadInt(IXPPropertyBag ptPropBag,
                            java.lang.String sPropID,
                            int nDefault)
Reads an int value from a property bag. Returns nDefault if the value was not found or an error occurred.

Parameters:
sPropID -
ptPropBag -
nDefault -
Returns:
int

PBReadString

public static java.lang.String PBReadString(IXPPropertyBag ptPropBag,
                                            java.lang.String sPropID,
                                            java.lang.String strDefault)
Reads a String value from a property bag. Returns strDefault if the value was not found or an error occurred.

Parameters:
sPropID -
ptPropBag -
strDefault -
Returns:
String

PBWrite

public static void PBWrite(IXPPropertyBag ptPropBag,
                           java.lang.String sPropID,
                           java.lang.String strValue)
Writes a value to a property bag.

Parameters:
sPropID -
ptPropBag -
strValue -

PBWrite

public static void PBWrite(IXPPropertyBag ptPropBag,
                           java.lang.String sPropID,
                           int nValue)
Writes a value to a property bag.

Parameters:
sPropID -
ptPropBag -
nValue -

PBWrite

public static void PBWrite(IXPPropertyBag ptPropBag,
                           java.lang.String sPropID,
                           long lValue)
Writes a value to a property bag.

Parameters:
sPropID -
ptPropBag -
lValue -

PBWrite

public static void PBWrite(IXPPropertyBag ptPropBag,
                           java.lang.String sPropID,
                           boolean bValue)
Writes a value to a property bag.

Parameters:
sPropID -
ptPropBag -
bValue -

PBWrite

public static void PBWrite(IXPPropertyBag ptPropBag,
                           java.lang.String sPropID,
                           XPArrayList xpalValue)
Writes a value to a property bag.

Parameters:
sPropID -
ptPropBag -
bValue -

ValidateDurationRange

public static int ValidateDurationRange(PTDuration ptdIn,
                                        AActivitySpace asOwner,
                                        java.lang.String strError,
                                        int nLastError,
                                        long lMinMilli,
                                        long lMaxMilli)
Validates that a specified Duration falls within the specified duration range (specified in milliseconds).

Parameters:
ptdIn -
asOwner -
strError -
nLastError -
lMinMilli -
lMaxMilli -
Returns:
int

ValidateBool

public static int ValidateBool(boolean bValid,
                               AActivitySpace asOwner,
                               java.lang.String strError,
                               int nLastError)
Validates an arbitrary boolean. If bError is true it errors, else it does not.

Parameters:
ptdIn -
asOwner -
strError -
nLastError -
lMinMilli -
lMaxMilli -
Returns:
int

ValidateInteger

public static int ValidateInteger(java.lang.String integer,
                                  AActivitySpace asOwner,
                                  java.lang.String strError,
                                  int nLastError)
Validates that the provided string is an integer, if not returns PAGE_STATUS_INVALID. Returns nLastError otherwise.

Parameters:
nIn -
asOwner -
strError -
nLastError -
Returns:
int

ValidateIntegerRange

public static int ValidateIntegerRange(int nIn,
                                       AActivitySpace asOwner,
                                       java.lang.String strError,
                                       int nLastError,
                                       int nMin,
                                       int nMax)
Validates that an integer is within the specified range (nMin to nMax). Raises a UIError with descriptiong strError if the integer is invalid (and returns PAGE_STATUS_INVALID). Returns nLastError otherwise. Note: If nMax is less than nMin, this function only validates that nIn is greater than nMin (nMax is ignored). Note: If nMax == nMin, then this function validates that nIn == nMax == nMin.

Parameters:
nIn -
asOwner -
strError -
nLastError -
nMin -
nMax -
Returns:
int

CheckIsURLString

public static boolean CheckIsURLString(java.lang.String strIn)
Checks that a string starts with http:// or https://.

Parameters:
strIn -
Returns:
boolean

ValidateIsURLString

public static int ValidateIsURLString(java.lang.String strIn,
                                      AActivitySpace asOwner,
                                      java.lang.String strError,
                                      int nLastError)
Validates that a string starts with http:// or https://. Raises a UIError with descriptiong strError if the string is invalid (and returns PAGE_STATUS_INVALID). Returns nLastError otherwise.

Parameters:
strIn -
asOwner -
strError -
nLastError -
Returns:
int

HasTrailingSlash

public static boolean HasTrailingSlash(java.lang.String strIn)

TrimTrailingSlash

public static java.lang.String TrimTrailingSlash(java.lang.String strIn)

TrimAllTrailingSlashes

public static java.lang.String TrimAllTrailingSlashes(java.lang.String strIn)

ValidateNonEmptyString

public static int ValidateNonEmptyString(java.lang.String strIn,
                                         AActivitySpace asOwner,
                                         java.lang.String strError,
                                         int nLastError)
Validates that a string is non-empty. Raises a UIError with descriptiong strError if the string is empty or null (and returns PAGE_STATUS_INVALID). Returns nLastError otherwise.

Parameters:
strIn -
asOwner -
strError -
nLastError -
Returns:
int

ValidateLoginPassword

public static int ValidateLoginPassword(java.lang.String strLogin,
                                        java.lang.String strPassword,
                                        java.lang.String strNULLPASSWORD,
                                        AActivitySpace asOwner,
                                        java.lang.String strError,
                                        int nLastError)
Validates that both a login and password were set.

Parameters:
strLogin -
strPassword -
strNULLPASSWORD -
asOwner -
strError -
nLastError -
Returns:
int

StringArrayToXPArray

public static XPArrayList StringArrayToXPArray(java.lang.String[] arsIn)



Copyright © 2002,2003,2004,2005 Plumtree Software, Inc., All Rights Reserved.