weaver      2004/07/20 13:33:58

  Modified:    portal/src/java/org/apache/jetspeed/request
                        JetspeedRequestContext.java
               jetspeed-api/src/java/org/apache/jetspeed/request
                        RequestContext.java
  Log:
  RequestContext made into a Good Citizen.  Most getters raise IllegalStateExceptions 
if their
  associated property is null.
  
  Revision  Changes    Path
  1.23      +27 -17    
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
  
  Index: JetspeedRequestContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- JetspeedRequestContext.java       20 Jul 2004 18:53:03 -0000      1.22
  +++ JetspeedRequestContext.java       20 Jul 2004 20:33:58 -0000      1.23
  @@ -42,6 +42,7 @@
   import org.apache.jetspeed.profiler.ProfileLocator;
   import org.apache.jetspeed.services.factory.FactoryManager;
   import org.apache.jetspeed.userinfo.UserInfoManager;
  +import org.apache.jetspeed.util.ArgUtil;
   import org.apache.pluto.om.common.Language;
   import org.apache.pluto.om.common.LanguageSet;
   import org.apache.pluto.om.common.ObjectID;
  @@ -122,21 +123,25 @@
   
       public HttpServletRequest getRequest()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getRequest()", "request");
           return request;
       }
   
       public HttpServletResponse getResponse()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getResponse()", "response");
           return response;
       }
   
       public ServletConfig getConfig()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getConfig()", "config");
           return config;
       }
   
       public ProfileLocator getProfileLocator()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getProfileLocator()", 
"locator");
           return locator;
       }
   
  @@ -147,6 +152,7 @@
   
       public Page getPage()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getPage()", "page");
           return this.page;
       }
   
  @@ -157,6 +163,7 @@
   
       public PortletDefinition getPortletDefinition()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getPortletDefinition()", 
"portletDefinition");
           return portletDefinition;
       }
   
  @@ -167,6 +174,7 @@
   
       public ContentDispatcher getContentDispatcher()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getContentDispatcher()", 
"dispatcher");
           return dispatcher;
       }
   
  @@ -191,6 +199,7 @@
        */
       public CapabilityMap getCapabilityMap()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getCapabilityMap()", 
"capabilityMap");
           return this.capabilityMap;
       }
   
  @@ -210,6 +219,7 @@
        */
       public String getMimeType()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getMimeType()", "mimeType");
           return this.mimeType;
       }
   
  @@ -229,6 +239,7 @@
        */
       public String getMediaType()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getMediaType()", "mediaType");
           return this.mediaType;
       }
   
  @@ -264,6 +275,7 @@
        */
       public String getCharacterEncoding()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getMediaType()", 
"mediaType"); 
           return this.encoding;
       }
   
  @@ -290,9 +302,9 @@
       {
           ServletRequestFactory reqFac = (ServletRequestFactory) FactoryManager
                   .getFactory(javax.servlet.http.HttpServletRequest.class);
  -        HttpServletRequest requestWrapper = reqFac.getServletRequest(request, 
window);
  +        HttpServletRequest requestWrapper = reqFac.getServletRequest(getRequest(), 
window);
           
  -        if (getCharacterEncoding() != null)
  +        if (this.encoding != null)
           {
               try
               {
  @@ -318,7 +330,7 @@
       public HttpServletResponse getResponseForWindow( PortletWindow window )
       {
           ServletResponseFactory rspFac = (ServletResponseFactory) 
FactoryManager.getFactory(HttpServletResponse.class);
  -        HttpServletResponse wrappedResponse = rspFac.getServletResponse(response);
  +        HttpServletResponse wrappedResponse = 
rspFac.getServletResponse(getResponse());
           return wrappedResponse;
       }
   
  @@ -343,6 +355,7 @@
        */
       public Locale getLocale()
       {
  +        ArgUtil.assertPropertyNotNull(request, this, "getLocale()", "locale"); 
           return this.locale;
       }
   
  @@ -367,7 +380,7 @@
        */
       public String getRequestParameter( String key )
       {
  -        return request.getParameter(key);
  +        return getRequest().getParameter(key);
       }
   
       /**
  @@ -375,7 +388,7 @@
        */
       public Map getParameterMap()
       {
  -        return request.getParameterMap();
  +        return getRequest().getParameterMap();
       }
   
       /**
  @@ -383,7 +396,7 @@
        */
       public Object getRequestAttribute( String key )
       {
  -        return request.getAttribute(key);
  +        return getRequest().getAttribute(key);
       }
   
       /**
  @@ -391,7 +404,7 @@
        */
       public Object getSessionAttribute( String key )
       {
  -        return request.getSession().getAttribute(key);
  +        return getRequest().getSession().getAttribute(key);
       }
   
       /**
  @@ -400,7 +413,7 @@
        */
       public void setSessionAttribute( String key, Object value )
       {
  -        request.getSession().setAttribute(key, value);
  +        getRequest().getSession().setAttribute(key, value);
       }
   
       /**
  @@ -409,7 +422,7 @@
        */
       public void setAttribute( String key, Object value )
       {
  -        request.setAttribute(key, value);
  +        getRequest().setAttribute(key, value);
       }
   
       /**
  @@ -417,7 +430,7 @@
        */
       public Object getAttribute( String key )
       {
  -        return request.getAttribute(key);
  +        return getRequest().getAttribute(key);
       }
   
       /**
  @@ -429,7 +442,7 @@
           {
               return this.requestPath;
           }
  -        String pathInfo = request.getPathInfo();
  +        String pathInfo = getRequest().getPathInfo();
           if (pathInfo == null)
           {
               this.requestPath = null;
  @@ -443,7 +456,7 @@
           while (tokenizer.hasMoreTokens())
           {
               String token = tokenizer.nextToken();
  -            if (this.url.isNavigationalParameter(token))
  +            if (getPortalURL().isNavigationalParameter(token))
               {
                   break;
               }
  @@ -475,10 +488,7 @@
        */
       public PortalURL getPortalURL()
       {
  -        if(url == null)
  -        {
  -            throw new IllegalStateException("This RequestContext's portalUrl has 
not been and is null.");
  -        }
  +        ArgUtil.assertPropertyNotNull(request, this, "getPortalURL()", "url"); 
           return url;
       }
   
  @@ -502,7 +512,7 @@
        */
       public Language getPreferedLanguage( PortletDefinition portlet )
       {
  -        HttpSession session = request.getSession();
  +        HttpSession session = getRequest().getSession();
           Map languageMap = (Map) session.getAttribute(PREFERED_LANGUAGE_SESSION_KEY);
           Language language = (Language) languageMap.get(portlet);
           if(language != null)
  
  
  
  1.5       +49 -4     
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/request/RequestContext.java
  
  Index: RequestContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/request/RequestContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RequestContext.java       20 Jul 2004 18:53:03 -0000      1.4
  +++ RequestContext.java       20 Jul 2004 20:33:58 -0000      1.5
  @@ -50,6 +50,8 @@
        * being processed by the portlet container.
        *
        * @return HttpServletRequest
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       public HttpServletRequest getRequest();
   
  @@ -59,6 +61,8 @@
        * be wrapped using <code>getPortletResponseForWindow()</code> before
        * being processed by the portlet container.
        * @return HttpServletResponse
  +     * * @throws IllegalStateException if <code>response</code>
  +     * has not been set or is null.
        */
       public HttpServletResponse getResponse();
   
  @@ -66,6 +70,8 @@
        * Gets the HTTP Servlet Config
        *
        * @return ServletConfig
  +     * @throws IllegalStateException if <code>servletConfig</code>
  +     * has not been set or is null.
        */
       public ServletConfig getConfig();
   
  @@ -73,6 +79,8 @@
        * Gets the profile locator for this request
        *
        * @return Profile
  +     * @throws IllegalStateException if <code>Profile</code>
  +     * has not been set or is null.
        */
       public ProfileLocator getProfileLocator();
   
  @@ -87,6 +95,8 @@
        * Gets the target page for this request
        *
        * @return Page
  +     * @throws IllegalStateException if <code>Page</code>
  +     * has not been set or is null.
        */
       public Page getPage();
   
  @@ -101,6 +111,8 @@
        * Gets the content dispatcher for this request
        *
        * @return ContentDispatcher
  +     * @throws IllegalStateException if <code>ContentDispatcher</code>
  +     * has not been set or is null.
        */
       public ContentDispatcher getContentDispatcher();
   
  @@ -119,8 +131,14 @@
       public void setCapabilityMap(CapabilityMap map);
   
       /**
  -     * Get the Capability Map
  +     * 
  +     * <p>
  +     * getCapabilityMap
  +     * </p>
        *
  +     * @return CapabilityMap
  +     * @throws IllegalStateException if <code>CapabilityMap</code>
  +     * has not been set or is null.
        */
       public CapabilityMap getCapabilityMap();
   
  @@ -132,8 +150,14 @@
       public void setMimeType(String mimeType);
   
       /**
  -     * Get the mimeType for the request
  +     * 
  +     * <p>
  +     * getMimeType
  +     * </p>
        *
  +     * @return MimeType
  +     * @throws IllegalStateException if <code>MimeType</code>
  +     * has not been set or is null.
        */
       public String getMimeType();
   
  @@ -145,8 +169,14 @@
       public void setMediaType(String mediaType);
   
       /**
  -     * get the Media Type
  +     * 
  +     * <p>
  +     * getMediaType
  +     * </p>
        *
  +     * @return MediaType
  +     * @throws IllegalStateException if <code>MediaType</code>
  +     * has not been set or is null.
        */
       public String getMediaType();
   
  @@ -193,6 +223,9 @@
        * set character encoding
        *
        * @param enc
  +     * @return CharacterEncoding
  +     * @throws IllegalStateException if <code>CharacterEncoding</code>
  +     * has not been set or is null.
        */
       public void setCharacterEncoding(String enc);
   
  @@ -271,6 +304,8 @@
        *
        * @param key The parameter unique key
        * @return The object associated with the uniqu
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       String getRequestParameter(String key);
   
  @@ -281,6 +316,8 @@
        * in that case it simply passes through to the servlet request.
        *
        * @return
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       Map getParameterMap();
   
  @@ -293,6 +330,8 @@
        *
        * @param key The key of the attribute
        * @return The value of the attribute
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       Object getSessionAttribute(String key);
   
  @@ -304,6 +343,8 @@
        *
        * @param key The key of the session attribute
        * @param value The value of the session attribute
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       void setSessionAttribute(String key, Object value);
   
  @@ -312,6 +353,8 @@
        *
        * @param key The key of the request attribute
        * @return The value of the request attribute
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       Object getAttribute(String key);
   
  @@ -323,6 +366,8 @@
        *
        * @param key The key of the request attribute
        * @param value The value of the request attribute
  +     * @throws IllegalStateException if <code>request</code>
  +     * has not been set or is null.
        */
       void setAttribute(String key, Object value);
   
  
  
  

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

Reply via email to