struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/action ActionServlet.java
Date Sat, 07 Oct 2000 20:57:42 GMT
craigmcc    00/10/07 13:57:42

  Modified:    src/share/org/apache/struts/action ActionServlet.java
  Log:
  When automatically setting the user session Locale if it is not already
  present, use the value returned from the servlet container (via the
  ServletRequest.getLocale() method) if there is one, before calculating
  our own.
  
  Revision  Changes    Path
  1.27      +21 -8     jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ActionServlet.java	2000/10/06 16:06:09	1.26
  +++ ActionServlet.java	2000/10/07 20:57:42	1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.26 2000/10/06 16:06:09 craigmcc Exp $
  - * $Revision: 1.26 $
  - * $Date: 2000/10/06 16:06:09 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.27 2000/10/07 20:57:42 craigmcc Exp $
  + * $Revision: 1.27 $
  + * $Date: 2000/10/07 20:57:42 $
    *
    * ====================================================================
    *
  @@ -172,9 +172,7 @@
    *     user session, identify and store an appropriate
    *     <code>java.util.Locale</code> object (under the standard key
    *     identified by <code>Action.LOCALE_KEY</code>) in the user's session
  - *     if there is not a Locale object there already.
  - *     The identified locale will be based on the HTTP headers included
  - *     in this request.  [true]</li>
  + *     if there is not a Locale object there already.</li>
    * <li><strong>mapping</strong> - The Java class name of the ActionMapping
    *     implementation to use [org.apache.struts.action.ActionMapping].
    *     Two convenient classes you may wish to use are:
  @@ -199,7 +197,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.26 $ $Date: 2000/10/06 16:06:09 $
  + * @version $Revision: 1.27 $ $Date: 2000/10/07 20:57:42 $
    */
   
   public class ActionServlet
  @@ -1177,6 +1175,20 @@
           if (session.getAttribute(Action.LOCALE_KEY) != null)
               return;             // Locale object is already present
   
  +        // Use the Locale returned by the servlet container (if any)
  +        Locale locale = null;
  +        try {
  +            locale = request.getLocale();
  +        } catch (Throwable t) {
  +            locale = null;      // Method not present in servlet 2.1
  +        }
  +        if (locale != null) {
  +            if (debug >= 1)
  +                log("Setting locale '" + locale + "'");
  +            session.setAttribute(Action.LOCALE_KEY, locale);
  +            return;
  +        }
  +
           // Calculate a Locale based on the HTTP headers with this request
           String value = request.getHeader("Accept-Language");
           if (value == null) {
  @@ -1201,8 +1213,9 @@
               language = value.substring(0, dash).trim();
               country = value.substring(dash + 1).trim();
           }
  +        locale = new Locale(language, country);
   
  -        Locale locale = new Locale(language, country);
  +        // Store the calculated Locale in the user's session
           if (debug >= 1)
               log("Setting locale '" + locale + "' for header '" +
                   request.getHeader("Accept-Language") + "'");
  
  
  

Mime
View raw message