org.kuali.rice.krad.util
Class KRADUtils

java.lang.Object
  extended by org.kuali.rice.krad.util.KRADUtils

public final class KRADUtils
extends Object

Miscellaneous Utility Methods

Author:
Kuali Rice Team (rice.collab@kuali.org)

Method Summary
static String buildMapParameterString(Map<String,String> map)
          Builds a string from the given map by joining each entry with a comma and each key/value pair with a colon
static boolean containsSensitiveDataPatternMatch(String fieldValue)
          Check if data might be sensitive
static String convertDecimalIntoInteger(KualiDecimal decimalNumber)
          Convert the given money amount into an integer string.
static Properties convertMapToProperties(Map<String,String> parameters)
          Utility method to convert a Map to a Properties object
static Properties convertRequestMapToProperties(Map<String,String[]> requestParameters)
          Utility method to convert a Request Parameters Map to a Properties object
static List<String> convertStringParameterToList(String parameter)
          Parses a string that is in list format (commas separating list entries) to a new List instance
static Map<String,String> convertStringParameterToMap(String parameter)
          Parses a string that is in map format (commas separating map entries, colon separates map key/value) to a new map instance
static Object createObject(Class<?> clazz, Class<?>[] argumentClasses, Object[] argumentValues)
           
static String getBusinessTitleForClass(Class<? extends Object> clazz)
          Retrieve the title for a business object class
static List<String> getFileNameFromPath(List<String> fullFileNames)
          Picks off the filename from the full path
static Integer getIntegerValue(String numberStr)
          Return the integer value of a string
static Map<String,String> getMapFromParameterString(String parameterString)
          Parses the given string into a Map by splitting on the comma to get the map entries and within each entry splitting by colon to get the key/value pairs
static String getMessageText(ErrorMessage errorMessage, boolean processPrefixSuffix)
          Gets the message associated with ErrorMessage object passed in, using message service.
static Map<String,String> getNamespaceAndActionClass(Class<? extends Object> clazz)
           
static Map<String,String> getNamespaceAndComponentFullName(Class<? extends Object> clazz)
           
static Map<String,String> getNamespaceAndComponentSimpleName(Class<? extends Object> clazz)
           
static String getNamespaceCode(Class<? extends Object> clazz)
          TODO this method will probably need to be exposed in a public KRADUtils class as it is used by several different modules.
static Map<String,String> getParametersFromRequest(List<String> parameterNames, Class<?> parentObjectClass, Map<String,String> requestParameters)
          Retrieves parameter values from the request that match the requested names.
static Map<String,String> getPropertyKeyValuesFromDataObject(List<String> propertyNames, Object dataObject)
          Builds a Map containing a key/value pair for each property given in the property names list, general security is checked to determine if the value needs to be encrypted along with applying formatting to the value
static Boolean getRequestParameterAsBoolean(javax.servlet.ServletRequest request, String parameterName)
          Retrieves value for the given parameter name in the request and attempts to convert to a Boolean using the BooleanFormatter
static UserSession getUserSessionFromRequest(javax.servlet.http.HttpServletRequest request)
          Gets the UserSession object from the HttpServletRequest object's associated session.
static Object hydrateAttributeValue(Class<?> propertyType, String attributeValue)
          Attempt to coerce a String attribute value to the given propertyType.
static boolean isProductionEnvironment()
          Check if current deployment is the production environment
static String joinWithQuotes(List<String> list)
          Creates a comma separated String representation of the given list.
static Map<String,String> translateRequestParameterMap(Map<String,String[]> requestParameters)
          Translates the given Map of String keys and String array values to a Map of String key and values.
static String translateToMapSafeKey(String key)
          Translates characters in the given string like brackets that will cause problems with binding to characters that do not affect the binding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBusinessTitleForClass

public static final String getBusinessTitleForClass(Class<? extends Object> clazz)
Retrieve the title for a business object class

The title is a nicely formatted version of the simple class name.

Parameters:
clazz - business object class
Returns:
title of the business object class

getFileNameFromPath

public static final List<String> getFileNameFromPath(List<String> fullFileNames)
Picks off the filename from the full path

The different OS path separators are being taken into consideration.

Parameters:
fullFileNames - file name with path
Returns:
file name

convertDecimalIntoInteger

public static final String convertDecimalIntoInteger(KualiDecimal decimalNumber)
Convert the given money amount into an integer string.

Since the return string cannot have decimal point, multiplies the amount by 100 so the decimal places are not lost, for example, 320.15 is converted into 32015.

Parameters:
decimalNumber - decimal number to be converted
Returns:
an integer string of the given money amount through multiplying by 100 and removing the fraction portion.

getIntegerValue

public static Integer getIntegerValue(String numberStr)
Return the integer value of a string

If the string contains a decimal value everything after the decimal point is dropped.

Parameters:
numberStr - string
Returns:
integer representation of the given string

hydrateAttributeValue

public static Object hydrateAttributeValue(Class<?> propertyType,
                                           String attributeValue)
Attempt to coerce a String attribute value to the given propertyType. If the transformation can't be made, either because the propertyType is null or because the transformation required exceeds this method's very small bag of tricks, then null is returned.

Parameters:
propertyType - the Class to coerce the attributeValue to
attributeValue - the String value to coerce
Returns:
an instance of the propertyType class, or null the transformation can't be made.

createObject

public static Object createObject(Class<?> clazz,
                                  Class<?>[] argumentClasses,
                                  Object[] argumentValues)

joinWithQuotes

public static String joinWithQuotes(List<String> list)
Creates a comma separated String representation of the given list.

For example 'a','b',c'.

Parameters:
list -
Returns:
the joined String, empty if the list is null or has no elements

getNamespaceCode

public static String getNamespaceCode(Class<? extends Object> clazz)
TODO this method will probably need to be exposed in a public KRADUtils class as it is used by several different modules. That will have to wait until ModuleService and KualiModuleService are moved to core though.


getNamespaceAndComponentSimpleName

public static Map<String,String> getNamespaceAndComponentSimpleName(Class<? extends Object> clazz)

getNamespaceAndComponentFullName

public static Map<String,String> getNamespaceAndComponentFullName(Class<? extends Object> clazz)

getNamespaceAndActionClass

public static Map<String,String> getNamespaceAndActionClass(Class<? extends Object> clazz)

convertStringParameterToMap

public static Map<String,String> convertStringParameterToMap(String parameter)
Parses a string that is in map format (commas separating map entries, colon separates map key/value) to a new map instance

Parameters:
parameter - - string parameter to parse
Returns:
Map instance populated from string parameter

convertStringParameterToList

public static List<String> convertStringParameterToList(String parameter)
Parses a string that is in list format (commas separating list entries) to a new List instance

Parameters:
parameter - - string parameter to parse
Returns:
List instance populated from string parameter

translateToMapSafeKey

public static String translateToMapSafeKey(String key)
Translates characters in the given string like brackets that will cause problems with binding to characters that do not affect the binding

Parameters:
key - - string to translate
Returns:
String translated string

buildMapParameterString

public static String buildMapParameterString(Map<String,String> map)
Builds a string from the given map by joining each entry with a comma and each key/value pair with a colon

Parameters:
map - - map instance to build string for
Returns:
String of map entries

getMapFromParameterString

public static Map<String,String> getMapFromParameterString(String parameterString)
Parses the given string into a Map by splitting on the comma to get the map entries and within each entry splitting by colon to get the key/value pairs

Parameters:
parameterString - - string to parse into map
Returns:
Map map from string

getRequestParameterAsBoolean

public static Boolean getRequestParameterAsBoolean(javax.servlet.ServletRequest request,
                                                   String parameterName)
Retrieves value for the given parameter name in the request and attempts to convert to a Boolean using the BooleanFormatter

Parameters:
request - - servlet request containing parameters
parameterName - - name of parameter to retrieve value for
Returns:
Boolean set to value of parameter, or null if parameter was not found in request

translateRequestParameterMap

public static Map<String,String> translateRequestParameterMap(Map<String,String[]> requestParameters)
Translates the given Map of String keys and String array values to a Map of String key and values. If the String array contains more than one value, the single string is built by joining the values with the vertical bar character

Parameters:
requestParameters - - Map of request parameters to translate
Returns:
Map translated Map

getParametersFromRequest

public static Map<String,String> getParametersFromRequest(List<String> parameterNames,
                                                          Class<?> parentObjectClass,
                                                          Map<String,String> requestParameters)
Retrieves parameter values from the request that match the requested names. In addition, based on the object class an authorization check is performed to determine if the values are secure and should be decrypted. If true, the value is decrypted before returning

Parameters:
parameterNames - - names of the parameters whose values should be retrieved from the request
parentObjectClass - - object class that contains the parameter names as properties and should be consulted for security checks
requestParameters - - all request parameters to pull from
Returns:
Map populated with parameter name/value pairs pulled from the request

getPropertyKeyValuesFromDataObject

public static Map<String,String> getPropertyKeyValuesFromDataObject(List<String> propertyNames,
                                                                    Object dataObject)
Builds a Map containing a key/value pair for each property given in the property names list, general security is checked to determine if the value needs to be encrypted along with applying formatting to the value

Parameters:
propertyNames - - list of property names to get key/value pairs for
dataObject - - object instance containing the properties for which the values will be pulled
Returns:
Map containing entry for each property name with the property name as the map key and the property value as the value

convertMapToProperties

public static Properties convertMapToProperties(Map<String,String> parameters)
Utility method to convert a Map to a Properties object

Parameters:
parameters - - map to convert
Returns:
Properties object containing all the map entries

convertRequestMapToProperties

public static Properties convertRequestMapToProperties(Map<String,String[]> requestParameters)
Utility method to convert a Request Parameters Map to a Properties object

Multiple values for a parameter are joined together with comma delimiter

Parameters:
requestParameters - - map to convert
Returns:
Properties object containing all the map entries

containsSensitiveDataPatternMatch

public static boolean containsSensitiveDataPatternMatch(String fieldValue)
Check if data might be sensitive

The sensitivity of the data is checked by matching it against the sensitive data patterns that are specified in the system parameter table.

Parameters:
fieldValue - data to be checked for sensitivity
Returns:
true if the data matches the sensitive data pattern, false otherwise

getUserSessionFromRequest

public static final UserSession getUserSessionFromRequest(javax.servlet.http.HttpServletRequest request)
Gets the UserSession object from the HttpServletRequest object's associated session.

In some cases (different threads) the UserSession cannot be retrieved from GlobalVariables but can still be accessed via the session object


isProductionEnvironment

public static boolean isProductionEnvironment()
Check if current deployment is the production environment

Returns:
true if the deploy environment is production, false otherwise

getMessageText

public static String getMessageText(ErrorMessage errorMessage,
                                    boolean processPrefixSuffix)
Gets the message associated with ErrorMessage object passed in, using message service. The prefix and suffix will be appended to the retrieved message if processPrefixSuffix is true and if those settings are set on the ErrorMessage passed in.

Parameters:
errorMessage - the ErrorMessage object containing the message key(s)
processPrefixSuffix - if true appends the prefix and suffix to the message if they exist on ErrorMessage
Returns:
the converted/retrieved message


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.