org.kuali.rice.krad.util
Class MessageMap

java.lang.Object
  extended by org.kuali.rice.krad.util.MessageMap
All Implemented Interfaces:
Serializable

public class MessageMap
extends Object
implements 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:
Serialized Form

Constructor Summary
MessageMap()
           
MessageMap(MessageMap messageMap)
           
 
Method Summary
 void addGrowlMessage(GrowlMessage growl)
          Add a growl to the message map
 void addGrowlMessage(String growlTitle, String messageKey, String... messageParameters)
          Adds a growl (using the default theme) to the message map with the given title and message
 void addToErrorPath(String parentName)
          Adds a string prefix to the error path.
 void clearErrorMessages()
           
 void clearErrorPath()
          Clears the errorPath.
 boolean containsKeyMatchingPattern(String pattern)
           
 boolean containsMessageKey(String messageKey)
           
 int countFieldMessages(String fieldName)
          Returns the number of messages for the given field
 boolean doesPropertyHaveError(String key)
           
 boolean equals(Object o)
           
 boolean fieldHasMessage(String fieldName, String errorKey)
          Returns true if the named field has a message with the given errorKey
 Set<Map.Entry<String,List<ErrorMessage>>> getAllPropertiesAndErrors()
           
 Set<String> getAllPropertiesWithErrors()
           
 Set<String> getAllPropertiesWithInfo()
           
 Set<String> getAllPropertiesWithWarnings()
           
 int getErrorCount()
          Counts the total number of error messages in the map
 Map<String,List<ErrorMessage>> getErrorMessages()
           
 List<ErrorMessage> getErrorMessagesForProperty(String propertyName)
           
 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).
 List<String> getErrorPath()
          This method returns the list that holds the error path values.
 List<GrowlMessage> getGrowlMessages()
          Returns the list of growl messages (@{link GrowlMessage}) that have been added to the message map
 int getInfoCount()
          Counts the total number of info messages in the map
 Map<String,List<ErrorMessage>> getInfoMessages()
           
 List<ErrorMessage> getInfoMessagesForProperty(String propertyName)
           
 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).
 String getKeyPath(String propertyName, boolean prependFullErrorPath)
          This is what's prepended to the beginning of the key.
 List<ErrorMessage> getMessages(String path)
           
 int getNumberOfPropertiesWithErrors()
           
 List<String> getPropertiesWithErrors()
           
 List<String> getPropertiesWithInfo()
           
 List<String> getPropertiesWithWarnings()
           
 int getWarningCount()
          Counts the total number of warning messages in the map
 Map<String,List<ErrorMessage>> getWarningMessages()
           
 List<ErrorMessage> getWarningMessagesForProperty(String propertyName)
           
 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).
 boolean hasErrors()
           
 int hashCode()
           
 boolean hasInfo()
           
 boolean hasMessages()
           
 boolean hasNoErrors()
           
 boolean hasNoInfo()
           
 boolean hasNoMessages()
           
 boolean hasNoWarnings()
           
 boolean hasWarnings()
           
 void merge(Map<String,List<ErrorMessage>> messagesFrom, Map<String,List<ErrorMessage>> messagesTo)
          Takes one message map and merges it into another.
 void merge(MessageMap messageMap)
           
 List<ErrorMessage> putError(String propertyName, ErrorMessage message)
           
 List<ErrorMessage> putError(String propertyName, String errorKey, String... errorParameters)
           
 List<ErrorMessage> putErrorForSectionId(String sectionId, ErrorMessage message)
           
 List<ErrorMessage> putErrorForSectionId(String sectionId, String errorKey, String... errorParameters)
           
 List<ErrorMessage> putErrorWithoutFullErrorPath(String propertyName, ErrorMessage message)
           
 List<ErrorMessage> putErrorWithoutFullErrorPath(String propertyName, String errorKey, String... errorParameters)
           
 List<ErrorMessage> putInfo(String propertyName, ErrorMessage message)
           
 List<ErrorMessage> putInfo(String propertyName, String messageKey, String... messageParameters)
           
 List<ErrorMessage> putInfoForSectionId(String sectionId, ErrorMessage message)
           
 List<ErrorMessage> putInfoForSectionId(String sectionId, String messageKey, String... messageParameters)
           
 List<ErrorMessage> putInfoWithoutFullErrorPath(String propertyName, ErrorMessage message)
           
 List<ErrorMessage> putInfoWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters)
           
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
 List<ErrorMessage> putWarning(String propertyName, ErrorMessage message)
           
 List<ErrorMessage> putWarning(String propertyName, String messageKey, String... messageParameters)
           
 List<ErrorMessage> putWarningForSectionId(String sectionId, ErrorMessage message)
           
 List<ErrorMessage> putWarningForSectionId(String sectionId, String messageKey, String... messageParameters)
           
 List<ErrorMessage> putWarningWithoutFullErrorPath(String propertyName, ErrorMessage message)
           
 List<ErrorMessage> putWarningWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters)
           
 List<ErrorMessage> removeAllErrorMessagesForProperty(String property)
           
 List<ErrorMessage> removeAllInfoMessagesForProperty(String property)
           
 List<ErrorMessage> removeAllWarningMessagesForProperty(String property)
           
 boolean removeFromErrorPath(String parentName)
          Removes a string prefix from the error path.
 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.
 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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageMap

public MessageMap()

MessageMap

public MessageMap(MessageMap messageMap)
Method Detail

merge

public void merge(MessageMap messageMap)

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

public List<ErrorMessage> putError(String propertyName,
                                   String errorKey,
                                   String... errorParameters)

putWarning

public List<ErrorMessage> putWarning(String propertyName,
                                     String messageKey,
                                     String... messageParameters)

putInfo

public List<ErrorMessage> putInfo(String propertyName,
                                  String messageKey,
                                  String... messageParameters)

putError

public List<ErrorMessage> putError(String propertyName,
                                   ErrorMessage message)

putWarning

public List<ErrorMessage> putWarning(String propertyName,
                                     ErrorMessage message)

putInfo

public List<ErrorMessage> putInfo(String propertyName,
                                  ErrorMessage message)

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

public List<ErrorMessage> putErrorWithoutFullErrorPath(String propertyName,
                                                       ErrorMessage message)

putWarningWithoutFullErrorPath

public List<ErrorMessage> putWarningWithoutFullErrorPath(String propertyName,
                                                         ErrorMessage message)

putInfoWithoutFullErrorPath

public List<ErrorMessage> putInfoWithoutFullErrorPath(String propertyName,
                                                      ErrorMessage message)

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

public List<ErrorMessage> putErrorForSectionId(String sectionId,
                                               ErrorMessage message)

putWarningForSectionId

public List<ErrorMessage> putWarningForSectionId(String sectionId,
                                                 ErrorMessage message)

putInfoForSectionId

public List<ErrorMessage> putInfoForSectionId(String sectionId,
                                              ErrorMessage message)

addGrowlMessage

public void addGrowlMessage(String growlTitle,
                            String messageKey,
                            String... messageParameters)
Adds a growl (using the default theme) to the message map with the given title and message

Parameters:
growlTitle - - title for the growl
messageKey - - key for the message in resources
messageParameters - - parameters for the message

addGrowlMessage

public void addGrowlMessage(GrowlMessage growl)
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 under
errorMessage -
prependFullErrorPath - true if you want the whole parent error path prepended, false otherwise
escapeHtmlMessageParameters - 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 replaced
targetKey - error key of message to be replaced
replaceParameters - 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 replaced
targetKey - error key of message to be replaced
replaceParameters - zero or more string parameters for the replacement error message
Returns:
true if the replacement occurred

fieldHasMessage

public boolean fieldHasMessage(String fieldName,
                               String errorKey)
Returns true if the named field has a message with the given errorKey

Parameters:
errorKey -
fieldName -
Returns:
boolean

countFieldMessages

public int countFieldMessages(String fieldName)
Returns the number of messages for the given field

Parameters:
fieldName -
Returns:
int

containsMessageKey

public boolean containsMessageKey(String messageKey)
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

public List<ErrorMessage> getMessages(String path)
Parameters:
path -
Returns:
Returns a List of ErrorMessages for the given path

addToErrorPath

public void addToErrorPath(String parentName)
Adds a string prefix to the error path.

Parameters:
parentName -

getErrorPath

public List<String> getErrorPath()
This method returns the list that holds the error path values.

Returns:
List

removeFromErrorPath

public boolean removeFromErrorPath(String parentName)
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

public String getKeyPath(String propertyName,
                         boolean prependFullErrorPath)
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

public List<String> getPropertiesWithErrors()
Returns:
List of the property names that have errors.

getPropertiesWithWarnings

public List<String> getPropertiesWithWarnings()
Returns:
List of the property names that have warnings.

getPropertiesWithInfo

public List<String> getPropertiesWithInfo()
Returns:
List of the property names that have info.

clearErrorMessages

public void clearErrorMessages()

doesPropertyHaveError

public boolean doesPropertyHaveError(String key)

containsKeyMatchingPattern

public boolean containsKeyMatchingPattern(String pattern)
Parameters:
pattern - comma separated list of keys, optionally ending with * wildcard

getAllPropertiesAndErrors

public Set<Map.Entry<String,List<ErrorMessage>>> getAllPropertiesAndErrors()

getErrorMessagesForProperty

public List<ErrorMessage> getErrorMessagesForProperty(String propertyName)

getWarningMessagesForProperty

public List<ErrorMessage> getWarningMessagesForProperty(String propertyName)

getInfoMessagesForProperty

public List<ErrorMessage> getInfoMessagesForProperty(String propertyName)

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

public Set<String> getAllPropertiesWithErrors()

getAllPropertiesWithWarnings

public Set<String> getAllPropertiesWithWarnings()

getAllPropertiesWithInfo

public Set<String> getAllPropertiesWithInfo()

removeAllErrorMessagesForProperty

public List<ErrorMessage> removeAllErrorMessagesForProperty(String property)

removeAllWarningMessagesForProperty

public List<ErrorMessage> removeAllWarningMessagesForProperty(String property)

removeAllInfoMessagesForProperty

public List<ErrorMessage> removeAllInfoMessagesForProperty(String property)

getNumberOfPropertiesWithErrors

public int getNumberOfPropertiesWithErrors()

getErrorMessages

public Map<String,List<ErrorMessage>> getErrorMessages()

getWarningMessages

public Map<String,List<ErrorMessage>> getWarningMessages()

getInfoMessages

public Map<String,List<ErrorMessage>> getInfoMessages()

getGrowlMessages

public List<GrowlMessage> getGrowlMessages()
Returns the list of growl messages (@{link GrowlMessage}) that have been added to the message map

Returns:
List

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.