Package org.kuali.rice.krad.util
Class MessageMap
java.lang.Object
org.kuali.rice.krad.util.MessageMap
- All Implemented Interfaces:
Serializable
Holds errors due to validation
Keys of map represent property paths, and value is a AutoPopulatingList that contains resource string keys (to retrieve the error message).
Note, prior to rice 0.9.4, this class implemented Map. The implements has been removed as of
rice 0.9.4
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGrowlMessage(String growlTitle, String messageKey, String... messageParameters) Adds a growl (using the default theme) to the message map with the given title and messagevoidaddGrowlMessage(GrowlMessage growl) Add a growl to the message mapvoidaddToErrorPath(String parentName) Adds a string prefix to the error path.voidvoidClears the errorPath.booleancontainsKeyMatchingPattern(String pattern) booleancontainsMessageKey(String messageKey) intcountFieldMessages(String fieldName) Returns the number of messages for the given fieldbooleanbooleanbooleanfieldHasMessage(String fieldName, String errorKey) Returns true if the named field has a message with the given errorKeyintCounts the total number of error messages in the mapgetErrorMessagesForProperty(String propertyName) getErrorMessagesForProperty(String propertyName, boolean allowWildcard) Gets a list of lists that represent errors that matched by the propertyName passed in (multiple lists because the wildcard can match multiple keys).This method returns the list that holds the error path values.Returns the list of growl messages (@{link GrowlMessage}) that have been added to the message mapintCounts the total number of info messages in the mapgetInfoMessagesForProperty(String propertyName) getInfoMessagesForProperty(String propertyName, boolean allowWildcard) Gets a list of lists that represent info messages that matched by the propertyName passed in (multiple lists because the wildcard can match multiple keys).getKeyPath(String propertyName, boolean prependFullErrorPath) This is what's prepended to the beginning of the key.getMessages(String path) intintCounts the total number of warning messages in the mapgetWarningMessagesForProperty(String propertyName) getWarningMessagesForProperty(String propertyName, boolean allowWildcard) Gets a list of lists that represent warnings that matched by the propertyName passed in (multiple lists because the wildcard can match multiple keys).booleaninthashCode()booleanhasInfo()booleanbooleanbooleanbooleanbooleanbooleanvoidmerge(Map<String, List<ErrorMessage>> messagesFrom, Map<String, List<ErrorMessage>> messagesTo) Takes one message map and merges it into another.voidmerge(MessageMap messageMap) putError(String propertyName, String errorKey, Boolean escapeHtmlMessageParameters, String... errorParameters) Creates error message given the error key and parameters and adds it to the message map.putError(String propertyName, ErrorMessage message) putErrorForSectionId(String sectionId, String errorKey, String... errorParameters) putErrorForSectionId(String sectionId, ErrorMessage message) putErrorWithoutFullErrorPath(String propertyName, String errorKey, String... errorParameters) putErrorWithoutFullErrorPath(String propertyName, ErrorMessage message) putInfo(String propertyName, String messageKey, Boolean escapeHtmlMessageParameters, String... messageParameters) Creates error message given the message key and parameters and adds it to the info message map.putInfo(String propertyName, ErrorMessage message) putInfoForSectionId(String sectionId, String messageKey, String... messageParameters) putInfoForSectionId(String sectionId, ErrorMessage message) putInfoWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters) putInfoWithoutFullErrorPath(String propertyName, ErrorMessage message) protected List<ErrorMessage> putMessageInMap(Map<String, List<ErrorMessage>> messagesMap, String propertyName, ErrorMessage errorMessage, boolean prependFullErrorPath, boolean escapeHtmlMessageParameters) Adds an error message to the given message map, adjusting the error path and message parameters if necessaryputWarning(String propertyName, String messageKey, Boolean escapeHtmlMessageParameters, String... messageParameters) Creates error message given the message key and parameters and adds it to the warning message map.putWarning(String propertyName, String messageKey, String... messageParameters) putWarning(String propertyName, ErrorMessage message) putWarningForSectionId(String sectionId, String messageKey, String... messageParameters) putWarningForSectionId(String sectionId, ErrorMessage message) putWarningWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters) putWarningWithoutFullErrorPath(String propertyName, ErrorMessage message) removeAllErrorMessagesForProperty(String property) removeAllInfoMessagesForProperty(String property) removeAllWarningMessagesForProperty(String property) booleanremoveFromErrorPath(String parentName) Removes a string prefix from the error path.booleanreplaceError(String propertyName, String targetKey, String replaceKey, String... replaceParameters) If any error messages with the key targetKey exist in this ErrorMap for the named property, those ErrorMessages will be replaced with a new ErrorMessage with the given replaceKey and replaceParameters.booleanreplaceErrorWithoutFullErrorPath(String propertyName, String targetKey, String replaceKey, String... replaceParameters) If any error messages with the key targetKey exist in this ErrorMap for the named property, those ErrorMessages will be replaced with a new ErrorMessage with the given replaceKey and replaceParameters.toString()
-
Constructor Details
-
MessageMap
public MessageMap() -
MessageMap
-
-
Method Details
-
merge
-
merge
public void merge(Map<String, List<ErrorMessage>> messagesFrom, Map<String, List<ErrorMessage>> messagesTo) Takes one message map and merges it into another. Makes sure there are no duplicates.- Parameters:
messagesFrom-messagesTo- TODO: This method is not thread-safe and should be private.
-
putError
-
putWarning
public List<ErrorMessage> putWarning(String propertyName, String messageKey, String... messageParameters) -
putInfo
public List<ErrorMessage> putInfo(String propertyName, String messageKey, String... messageParameters) -
putError
-
putWarning
-
putInfo
-
putErrorWithoutFullErrorPath
public List<ErrorMessage> putErrorWithoutFullErrorPath(String propertyName, String errorKey, String... errorParameters) -
putWarningWithoutFullErrorPath
public List<ErrorMessage> putWarningWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters) -
putInfoWithoutFullErrorPath
public List<ErrorMessage> putInfoWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters) -
putErrorWithoutFullErrorPath
-
putWarningWithoutFullErrorPath
-
putInfoWithoutFullErrorPath
-
putErrorForSectionId
public List<ErrorMessage> putErrorForSectionId(String sectionId, String errorKey, String... errorParameters) -
putWarningForSectionId
public List<ErrorMessage> putWarningForSectionId(String sectionId, String messageKey, String... messageParameters) -
putInfoForSectionId
public List<ErrorMessage> putInfoForSectionId(String sectionId, String messageKey, String... messageParameters) -
putErrorForSectionId
-
putWarningForSectionId
-
putInfoForSectionId
-
putError
public List<ErrorMessage> putError(String propertyName, String errorKey, Boolean escapeHtmlMessageParameters, String... errorParameters) Creates error message given the error key and parameters and adds it to the message map.- Parameters:
propertyName- name of the property associated with the errorerrorKey- message key for the errorescapeHtmlMessageParameters- whether to escape HTML characters in the message parameterserrorParameters- zero or more parameters for the message text- Returns:
- TypeArrayList
-
putWarning
public List<ErrorMessage> putWarning(String propertyName, String messageKey, Boolean escapeHtmlMessageParameters, String... messageParameters) Creates error message given the message key and parameters and adds it to the warning message map.- Parameters:
propertyName- name of the property associated with the warningmessageKey- message key for the errorescapeHtmlMessageParameters- whether to escape HTML characters in the message parametersmessageParameters- zero or more parameters for the message text- Returns:
- TypeArrayList
-
putInfo
public List<ErrorMessage> putInfo(String propertyName, String messageKey, Boolean escapeHtmlMessageParameters, String... messageParameters) Creates error message given the message key and parameters and adds it to the info message map.- Parameters:
propertyName- name of the property associated with the infomessageKey- message key for the infoescapeHtmlMessageParameters- whether to escape HTML characters in the message parametersmessageParameters- zero or more parameters for the message text- Returns:
- TypeArrayList
-
addGrowlMessage
Adds a growl (using the default theme) to the message map with the given title and message- Parameters:
growlTitle- - title for the growlmessageKey- - key for the message in resourcesmessageParameters- - parameters for the message
-
addGrowlMessage
Add a growl to the message map- Parameters:
growl- - growl instance to add
-
putMessageInMap
protected List<ErrorMessage> putMessageInMap(Map<String, List<ErrorMessage>> messagesMap, String propertyName, ErrorMessage errorMessage, boolean prependFullErrorPath, boolean escapeHtmlMessageParameters) Adds an error message to the given message map, adjusting the error path and message parameters if necessary- Parameters:
messagesMap-propertyName- name of the property to add error undererrorMessage-prependFullErrorPath- true if you want the whole parent error path prepended, false otherwiseescapeHtmlMessageParameters- whether to escape HTML characters in the message parameters, provides protection against XSS attacks- Returns:
- TypeArrayList
-
replaceError
public boolean replaceError(String propertyName, String targetKey, String replaceKey, String... replaceParameters) If any error messages with the key targetKey exist in this ErrorMap for the named property, those ErrorMessages will be replaced with a new ErrorMessage with the given replaceKey and replaceParameters.- Parameters:
propertyName- name of the property where existing error will be replacedtargetKey- error key of message to be replacedreplaceParameters- zero or more string parameters for the replacement error message- Returns:
- true if the replacement occurred
-
replaceErrorWithoutFullErrorPath
public boolean replaceErrorWithoutFullErrorPath(String propertyName, String targetKey, String replaceKey, String... replaceParameters) If any error messages with the key targetKey exist in this ErrorMap for the named property, those ErrorMessages will be replaced with a new ErrorMessage with the given replaceKey and replaceParameters. The targetKey and replaceKey will be prepended with the current errorPath, if any.- Parameters:
propertyName- name of the property where existing error will be replacedtargetKey- error key of message to be replacedreplaceParameters- zero or more string parameters for the replacement error message- Returns:
- true if the replacement occurred
-
fieldHasMessage
Returns true if the named field has a message with the given errorKey- Parameters:
fieldName-errorKey-- Returns:
- boolean
-
countFieldMessages
Returns the number of messages for the given field- Parameters:
fieldName-- Returns:
- int
-
containsMessageKey
- Returns:
- true if the given messageKey is associated with some property in this ErrorMap
-
getErrorCount
public int getErrorCount()Counts the total number of error messages in the map- Returns:
- returns an int for the total number of errors
-
getWarningCount
public int getWarningCount()Counts the total number of warning messages in the map- Returns:
- returns an int for the total number of warnings
-
getInfoCount
public int getInfoCount()Counts the total number of info messages in the map- Returns:
- returns an int for the total number of info
-
getMessages
- Parameters:
path-- Returns:
- Returns a List of ErrorMessages for the given path
-
addToErrorPath
Adds a string prefix to the error path.- Parameters:
parentName-
-
getErrorPath
This method returns the list that holds the error path values.- Returns:
- List
-
removeFromErrorPath
Removes a string prefix from the error path.- Parameters:
parentName-- Returns:
- boolean Returns true if the parentName existed, false otherwise.
-
clearErrorPath
public void clearErrorPath()Clears the errorPath. -
getKeyPath
This is what's prepended to the beginning of the key. This is built by iterating over all of the entries in the errorPath list and concatenating them together with a "."- Parameters:
propertyName-prependFullErrorPath-- Returns:
- String Returns the keyPath.
-
getPropertiesWithErrors
- Returns:
- List of the property names that have errors.
-
getPropertiesWithWarnings
- Returns:
- List of the property names that have warnings.
-
getPropertiesWithInfo
- Returns:
- List of the property names that have info.
-
clearErrorMessages
public void clearErrorMessages() -
doesPropertyHaveError
-
containsKeyMatchingPattern
- Parameters:
pattern- comma separated list of keys, optionally ending with * wildcard
-
getAllPropertiesAndErrors
-
getErrorMessagesForProperty
-
getWarningMessagesForProperty
-
getInfoMessagesForProperty
-
getErrorMessagesForProperty
public List<List<ErrorMessage>> getErrorMessagesForProperty(String propertyName, boolean allowWildcard) Gets a list of lists that represent errors that matched by the propertyName passed in (multiple lists because the wildcard can match multiple keys). If wildcard is true, the propertyName ends with a wildcard character. Otherwise, it will only match on the single key and return a list with one list- Parameters:
propertyName-allowWildcard-- Returns:
-
getWarningMessagesForProperty
public List<List<ErrorMessage>> getWarningMessagesForProperty(String propertyName, boolean allowWildcard) Gets a list of lists that represent warnings that matched by the propertyName passed in (multiple lists because the wildcard can match multiple keys). If wildcard is true, the propertyName ends with a wildcard character. Otherwise, it will only match on the single key and return a list with one list.- Parameters:
propertyName-allowWildcard-- Returns:
-
getInfoMessagesForProperty
public List<List<ErrorMessage>> getInfoMessagesForProperty(String propertyName, boolean allowWildcard) Gets a list of lists that represent info messages that matched by the propertyName passed in (multiple lists because the wildcard can match multiple keys). If wildcard is true, the propertyName ends with a wildcard character. If it is false, it will only match on the single key and return a list with one list.- Parameters:
propertyName-allowWildcard-- Returns:
-
hasErrors
public boolean hasErrors() -
hasNoErrors
public boolean hasNoErrors() -
hasWarnings
public boolean hasWarnings() -
hasNoWarnings
public boolean hasNoWarnings() -
hasInfo
public boolean hasInfo() -
hasNoInfo
public boolean hasNoInfo() -
hasMessages
public boolean hasMessages() -
hasNoMessages
public boolean hasNoMessages() -
getAllPropertiesWithErrors
-
getAllPropertiesWithWarnings
-
getAllPropertiesWithInfo
-
removeAllErrorMessagesForProperty
-
removeAllWarningMessagesForProperty
-
removeAllInfoMessagesForProperty
-
getNumberOfPropertiesWithErrors
public int getNumberOfPropertiesWithErrors() -
getErrorMessages
-
getWarningMessages
-
getInfoMessages
-
getGrowlMessages
Returns the list of growl messages (@{link GrowlMessage}) that have been added to the message map- Returns:
- List<GrowlMessage>
-
equals
-
hashCode
public int hashCode() -
toString
-