Class ErrorCodeTranslator
- java.lang.Object
-
- com.priint.pubserver.errorcode.ErrorCodeTranslator
-
public final class ErrorCodeTranslator extends java.lang.ObjectThe ErrorCodeTranslator class provides methods to parse and localize script error codes in JSON format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classErrorCodeTranslator.ErrorMessage
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringlocalizeErrorMessage(java.lang.String errorMessage, Language language)If an error message is not a JSON this method returns the originalerrorMessage.
-
-
-
Method Detail
-
localizeErrorMessage
public static java.lang.String localizeErrorMessage(java.lang.String errorMessage, Language language)If an error message is not a JSON this method returns the original
errorMessage. However, if it is a JSON, it constructs a localized String representation of an error.Example valid JSON:
{ "messageKey": "NoPlanningsFound", "messageParameters": [ {"parameterKey":"document","parameterValue":"00013"}, {"parameterKey":"user", "parameterValue":"gabi"} ] }String values associated with keys messageKey and parameterValue are first compared with the localization dictionary and replaced with translated versions if any are found. At this point, string value associated with the messageKey is checked for placeholders matching the parameter keys. If those placeholder occurrences are found, they are replaced with proper values from messageParameters map.
If the NoPlanningsFound value in the example JSON gets translated into "No plannings found while rendering document _document_ started by _user_", the resulting localized error message will read: "No plannings found while rendering document 00013 started by gabi".
- Parameters:
errorMessage- a JSON or any string message one attempts to translatelanguage- value object representing a language to translate to- Returns:
- For JSON errorMessages - a localized string representation of it. Original
errorMessageotherwise.
-
-