Class ErrorCodeTranslator

java.lang.Object
com.priint.pubserver.errorcode.ErrorCodeTranslator

public final class ErrorCodeTranslator extends Object

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

  • Method Details

    • localizeErrorMessage

      public static String localizeErrorMessage(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.