kpiroumian    2002/07/09 14:12:58

  Modified:    src/java/org/apache/cocoon/acting LocaleAction.java
  Log:
  Cleanup inspired by Michael Enke ([EMAIL PROTECTED])
  PR: 10559
  
  Revision  Changes    Path
  1.10      +22 -31    xml-cocoon2/src/java/org/apache/cocoon/acting/LocaleAction.java
  
  Index: LocaleAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/LocaleAction.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LocaleAction.java 27 Apr 2002 09:36:22 -0000      1.9
  +++ LocaleAction.java 9 Jul 2002 21:12:58 -0000       1.10
  @@ -272,17 +272,12 @@
           Parameters par
       ) throws Exception {
   
  -        // obtain locale information (note, Locale.get* do not return null)
  -        String lc = getLocaleAttribute(objectModel, localeAttr);
  -        Locale locale = I18nUtils.parseLocale(lc);
  -        String l = locale.getLanguage();
  -        String c = locale.getCountry();
  -        String v = locale.getVariant();
  -
  -        debug("obtained locale information, locale = " + lc);
  -        debug("language = " + l + ", country = " + c + ", variant = " + v);
  +        // obtain locale information from params, session or cookies
  +        Locale locale = getLocaleAttribute(objectModel, localeAttr);
  +        String lc = locale.toString();
   
           if (getLogger().isDebugEnabled()) {
  +            debug("obtained locale information, locale = " + lc);
               checkParams(par);
           }
   
  @@ -312,58 +307,54 @@
               debug("created cookies");
           }
   
  -        // set up a map for XPath Substituion
  +        // set up a map for sitemap parameters
           Map map = new HashMap();
  -        map.put(langAttr, l);
  -        map.put(countryAttr, c);
  -        map.put(variantAttr, v);
  +        map.put(langAttr, locale.getLanguage());
  +        map.put(countryAttr, locale.getCountry());
  +        map.put(variantAttr, locale.getVariant());
           map.put(localeAttr, lc);
   
  -        debug("returning map for XPath substitutions");
  -
           return map;
       }
   
       /**
  -     * Helper method to access Locale sub component values.
  +     * Helper method to retreive the attribute value containing locale
  +     * information. See class documentation for locale determination algorythm.
        *
        * @param objectModel requesting object's environment
  -     * @return locale value
  -     * @throws Exception should some error occur
  +     * @return locale value or <code>null</null> if no locale was found
        */
  -    public static String getLocaleAttribute(Map objectModel, String localeAttrName) 
throws Exception {
  +    public static Locale getLocaleAttribute(Map objectModel,
  +        String localeAttrName) {
   
           String ret_val;
   
  -        // 1. Request CGI parameter 'locale'
           Request request = ObjectModelHelper.getRequest(objectModel);
   
  +        // 1. Request CGI parameter 'locale'
           if ((ret_val = request.getParameter(localeAttrName)) != null)
  -            return ret_val;
  +            return I18nUtils.parseLocale(ret_val);
   
           // 2. Session attribute 'locale'
           Session session = request.getSession(false);
           if (session != null &&
  -                ((ret_val = (String) session.getAttribute(localeAttrName)) != null)
  -           )
  -            return ret_val;
  +            ((ret_val = (String) session.getAttribute(localeAttrName)) != null))
  +            return I18nUtils.parseLocale(ret_val);
   
           // 3. First matching cookie parameter 'locale' within each cookie sent
           Cookie[] cookies = request.getCookies();
  -
           if (cookies != null) {
               for (int i = 0; i < cookies.length; ++i) {
                   Cookie cookie = cookies[i];
                   if (cookie.getName().equals(localeAttrName))
  -                    return cookie.getValue();
  +                    return I18nUtils.parseLocale(cookie.getValue());
               }
           }
   
           // 4. Locale setting of the requesting object/server
  -        return request.getLocale().toString();
  +        return request.getLocale();
       }
   
  -
       /**
        * Method to check <map:act type="locale"/> invocations for local
        * customisation.
  @@ -401,12 +392,12 @@
       }
   
       /**
  -     * Helper debug method, prefixes all debug messages with the classes name
  +     * Helper debug method
        *
        * @param msg debugging message
        */
       private void debug(String msg) {
  -        getLogger().debug(getClass().getName() + ": " + msg);
  +        getLogger().debug(msg);
       }
   
       // Store the lang in request. Default is not to do this.
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to