Class HttpLocaleHandler


  • public class HttpLocaleHandler
    extends java.lang.Object
    A class used to determine the appropriate locale/language to use for generating a HTTP response. Uses the HTTP request "Accept-Language" header, locale cookie or default locale. Also caches a structure of all available locale combinations in the execution environment.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  HttpLocaleHandler.HttpLocale
      HTTP locale object with information about the best matched locale based on Accept-Language header, cookie usage and the NAS language object.
      static class  HttpLocaleHandler.Language
      Object constructed from language configuration in the settings xml file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.LinkedHashMap<java.lang.String,​HttpLocaleHandler.Language> languageLHM
      Structure including the
      java.util.Map<java.lang.String,​java.util.Locale> localeMap
      Map of all Locale objects registered by the execution environment.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected HttpLocaleHandler()
      Constructor should only be used locally or in unit test.
    • Field Detail

      • localeMap

        public final java.util.Map<java.lang.String,​java.util.Locale> localeMap
        Map of all Locale objects registered by the execution environment.
    • Constructor Detail

      • HttpLocaleHandler

        protected HttpLocaleHandler()
        Constructor should only be used locally or in unit test.
    • Method Detail

      • getInstance

        public static HttpLocaleHandler getInstance()
        Construct a HTTP locale handler. Reads all available locates in the execution environment and in the NAS settings XML.
        Returns:
        initialised HTTP locale handler
      • localeGetSet

        public HttpLocaleHandler.HttpLocale localeGetSet​(javax.servlet.http.HttpServletRequest req,
                                                         javax.servlet.http.HttpServletResponse resp)
        Determine the closest locale that matches the information in the HTTP request. Depending on usage it manages a cookie. If no cookie exists reads/parses the HTTP request "Accept-Language" header.
        Parameters:
        req - HTTP request object
        resp - HTTP response object
        Returns:
        HttpLocale object determined to be the closest match to what the request wants