weaver      2004/08/24 07:23:52

  Modified:    portal/src/java/org/apache/jetspeed/engine/servlet
                        ServletRequestImpl.java
  Log:
  implemented the setAttribute interface to automatically namespace encode jetspeed 
attributes, prefixed with "org.apache.jetspeed"
  so they are accessible from portlets.  Accessing these attributes obiviously makes 
these portlets non-portable, however it makes
  creating admin and jetspeed-specific portlets much easier.  For example,  
LocaleSelectorPortlet now sets the  prefered language for
  the entire portal (only for the current user session) by accessing the the 
org.apache.jetspeed.request.RequestContext attribute.
  
  Revision  Changes    Path
  1.22      +36 -4     
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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ServletRequestImpl.java   11 Aug 2004 21:21:41 -0000      1.21
  +++ ServletRequestImpl.java   24 Aug 2004 14:23:52 -0000      1.22
  @@ -36,6 +36,7 @@
   
   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;
  @@ -238,7 +239,7 @@
           Object value = super.getAttribute(name);        
           if (name.equals(PortletRequest.USER_INFO))
           {
  -            JetspeedRequestContext context = (JetspeedRequestContext) 
getAttribute("org.apache.jetspeed.request.RequestContext");
  +            JetspeedRequestContext context = (JetspeedRequestContext) 
getAttribute(RequestContext.REQUEST_PORTALENV);
               if (null != context)
               {
                   String entityID = "--NULL--";
  @@ -285,7 +286,7 @@
        */
       public Locale getLocale()
       {
  -        Locale preferedLocale = (Locale) 
getSession().getAttribute(JetspeedRequestContext.PREFERED_LOCALE_SESSION_KEY);
  +        Locale preferedLocale = (Locale) 
getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
           if (preferedLocale != null)
           {
               return preferedLocale;
  @@ -299,7 +300,7 @@
        */
       public Enumeration getLocales()
       {
  -        Locale preferedLocale = (Locale) 
getSession().getAttribute(JetspeedRequestContext.PREFERED_LOCALE_SESSION_KEY);
  +        Locale preferedLocale = (Locale) 
getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
           if (preferedLocale != null)
           {
               ArrayList locales = new ArrayList();
  @@ -336,4 +337,35 @@
           return super.getHeaders(name);
       }
   
  +    /**
  +     * <p>
  +     * setAttribute
  +     * </p>
  +     *
  +     * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, 
java.lang.Object)
  +     * @param arg0
  +     * @param arg1
  +     */
  +    public void setAttribute( String name, Object value )
  +    {
  +        // This allows us to make jetpseed objects avaiable to portlets
  +        // This makes the portlet non-portable but is a must admin portlets
  +        if(name.startsWith("org.apache.jetspeed"))
  +        {
  +            if (name == null)
  +            {
  +                throw new IllegalArgumentException("Attribute name == null");
  +            }
  +
  +            if ( value == null)
  +            {
  +                this.removeAttribute(name);
  +            }
  +            else
  +            {
  +                
this._getHttpServletRequest().setAttribute(NamespaceMapperAccess.getNamespaceMapper().encode(portletWindow.getId(),name),
 value);
  +            }
  +        }
  +        super.setAttribute(name, value);
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to