Class ErrorCodeTranslator


  • public final class ErrorCodeTranslator
    extends java.lang.Object

    The ErrorCodeTranslator class provides methods to parse and localize script error codes in JSON format.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 translate
        language - value object representing a language to translate to
        Returns:
        For JSON errorMessages - a localized string representation of it. Original errorMessage otherwise.