portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet ServletRequestImpl.java
Date Wed, 08 Sep 2004 20:46:45 GMT
weaver      2004/09/08 13:46:45

  Modified:    portal/src/java/org/apache/jetspeed/localization/impl
                        LocalizationValveImpl.java
               portal/src/java/org/apache/jetspeed/engine/servlet
                        ServletRequestImpl.java
  Log:
  Fix l10n issue whose syptoms were the JSTL fmt tag not picking up the correct locale and
whose cause was incorrect logic
  in ServletRequestImpl.getLocales() method
  
  Revision  Changes    Path
  1.6       +3 -2      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/localization/impl/LocalizationValveImpl.java
  
  Index: LocalizationValveImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/localization/impl/LocalizationValveImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LocalizationValveImpl.java	24 Aug 2004 14:24:56 -0000	1.5
  +++ LocalizationValveImpl.java	8 Sep 2004 20:46:45 -0000	1.6
  @@ -67,7 +67,8 @@
   
           request.setLocale(locale);
           request.getRequest().setAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY, locale);
  -
  +        request.getRequest().getSession().setAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY,
locale);
  +       
           // Pass control to the next Valve in the Pipeline
           context.invokeNext(request);
   
  
  
  
  1.28      +59 -22    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
  
  Index: ServletRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ServletRequestImpl.java	3 Sep 2004 19:45:32 -0000	1.27
  +++ ServletRequestImpl.java	8 Sep 2004 20:46:45 -0000	1.28
  @@ -25,25 +25,22 @@
   import java.util.Map;
   
   import javax.portlet.PortletRequest;
  -
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletRequestWrapper;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -
   import org.apache.jetspeed.container.url.PortalURL;
   import org.apache.jetspeed.request.JetspeedRequestContext;
   import org.apache.jetspeed.request.RequestContext;
  -
   import org.apache.pluto.om.common.SecurityRole;
   import org.apache.pluto.om.common.SecurityRoleRef;
   import org.apache.pluto.om.common.SecurityRoleRefSet;
   import org.apache.pluto.om.common.SecurityRoleSet;
  -import org.apache.pluto.om.portlet.PortletDefinition;
   import org.apache.pluto.om.entity.PortletApplicationEntity;
   import org.apache.pluto.om.entity.PortletEntity;
   import org.apache.pluto.om.portlet.PortletApplicationDefinition;
  +import org.apache.pluto.om.portlet.PortletDefinition;
   import org.apache.pluto.om.window.PortletWindow;
   import org.apache.pluto.util.Enumerator;
   import org.apache.pluto.util.NamespaceMapper;
  @@ -58,6 +55,7 @@
    */
   public class ServletRequestImpl extends HttpServletRequestWrapper
   {
  +    public static final String ACCEPT_LANGUAGE = "Accept_Language";
       /** Logger */
       private static final Log log = LogFactory.getLog(ServletRequestImpl.class);
   
  @@ -70,7 +68,7 @@
       {
           super(servletRequest);
           nameSpaceMapper = NamespaceMapperAccess.getNamespaceMapper();
  -        this.portletWindow = window;
  +        this.portletWindow = window;        
       }
   
       protected HttpServletRequest _getHttpServletRequest()
  @@ -266,7 +264,9 @@
        */
       public Locale getLocale()
       {
  -        Locale preferedLocale = (Locale) getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
  +        //Locale preferedLocale = (Locale) getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
  +        RequestContext requestContext = (RequestContext) _getHttpServletRequest().getAttribute(RequestContext.REQUEST_PORTALENV);
  +        Locale preferedLocale = requestContext.getLocale();
           if (preferedLocale != null)
           {
               return preferedLocale;
  @@ -280,31 +280,50 @@
        */
       public Enumeration getLocales()
       {
  -        Locale preferedLocale = (Locale) getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
  +        RequestContext requestContext = (RequestContext) _getHttpServletRequest().getAttribute(RequestContext.REQUEST_PORTALENV);
  +        Locale preferedLocale = requestContext.getLocale();
           if (preferedLocale != null)
           {
  -            ArrayList locales = new ArrayList();
  -            locales.add(preferedLocale);
  -            Enumeration enum = super.getLocales();
  -            while (enum.hasMoreElements())
  -            {
  -                locales.add(enum.nextElement());
  -            }
  -            Iterator i = locales.iterator();
  -            return new Enumerator(locales);
  +            return getLocaleEnum(preferedLocale);
           }
   
           return super.getLocales();
       }
   
       /**
  +     * <p>
  +     * getLocaleEnum
  +     * </p>
  +     *
  +     * @param preferedLocale
  +     * @return
  +     */
  +    protected Enumeration getLocaleEnum( Locale preferedLocale )
  +    {
  +        ArrayList locales = new ArrayList();
  +        locales.add(preferedLocale);
  +        Enumeration enum = super.getLocales();
  +        while (enum.hasMoreElements())
  +        {
  +            locales.add(enum.nextElement());
  +        }
  +        Iterator i = locales.iterator();
  +        return new Enumerator(locales);
  +    }
  +
  +    /**
        * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
        */
       public String getHeader( String name )
       {
  -        // TODO: replace accept-language header
  -
  -        return super.getHeader(name);
  +        if(name.equals(ACCEPT_LANGUAGE))
  +        {
  +            return getLocale().getLanguage();   
  +        }
  +        else
  +        {
  +            return super.getHeader(name);
  +        }
       }
   
       /**
  @@ -312,9 +331,15 @@
        */
       public Enumeration getHeaders( String name )
       {
  -        // TODO: replace accept-language header
  +        if(name.equals(ACCEPT_LANGUAGE))
  +        {      
  +            return getLocaleEnum(getLocale());         
  +        }
  +        else
  +        {
  +            return super.getHeaders(name);
  +        }        
   
  -        return super.getHeaders(name);
       }
   
       /**
  @@ -349,5 +374,17 @@
               }
           }
           super.setAttribute(name, value);
  +    }
  +    /**
  +     * <p>
  +     * getHeaderNames
  +     * </p>
  +     *
  +     * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
  +     * @return
  +     */
  +    public Enumeration getHeaderNames()
  +    {
  +        return super.getHeaderNames();
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message