Home » Struts-1.3.10 » org.apache.struts » chain » servlet » [javadoc | source]

    1   /*
    2    * Copyright 2003,2004 The Apache Software Foundation.
    3    * 
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    * 
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    * 
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.apache.struts.chain.servlet;
   18   
   19   
   20   import javax.servlet.RequestDispatcher;
   21   import javax.servlet.http.HttpServletRequest;
   22   import org.apache.commons.chain.Context;
   23   import org.apache.commons.chain.web.servlet.ServletWebContext;
   24   import org.apache.struts.chain.AbstractPerformForward;
   25   import org.apache.struts.config.ForwardConfig;
   26   import org.apache.struts.config.ModuleConfig;
   27   import org.apache.struts.upload.MultipartRequestWrapper;
   28   import org.apache.struts.util.RequestUtils;
   29   
   30   
   31   /**
   32    * <p>Perform forwarding or redirection based on the specified
   33    * <code>ForwardConfig</code> (if any).</p>
   34    *
   35    * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
   36    */
   37   
   38   public class PerformForward extends AbstractPerformForward {
   39   
   40   
   41       // ------------------------------------------------------- Protected Methods
   42   
   43   
   44       /**
   45        * <p>Perform the appropriate processing on the specified
   46        * <code>ForwardConfig</code>.</p>
   47        *
   48        * @param context The context for this request
   49        * @param forwardConfig The forward to be performed
   50        */
   51       protected void perform(Context context,ForwardConfig forwardConfig)
   52           throws Exception {
   53   
   54           ServletWebContext swcontext = (ServletWebContext) context;
   55           String forwardPath = forwardConfig.getPath();
   56           String uri = null;
   57   
   58           ModuleConfig moduleConfig  = (ModuleConfig) context.get(getModuleConfigKey());
   59           // Resolve module-relative paths
   60           if (forwardPath.startsWith("/")) {
   61               uri = RequestUtils.forwardURL(swcontext.getRequest(),
   62                                             forwardConfig,
   63                                             moduleConfig);
   64           } else {
   65               uri = forwardPath;
   66           }
   67   
   68           // Get the underlying request in the case of a multipart wrapper
   69           HttpServletRequest request = swcontext.getRequest();
   70           if (request instanceof MultipartRequestWrapper) {
   71               request = ((MultipartRequestWrapper) request).getRequest();
   72           }
   73   
   74           // Perform redirect or forward
   75           if (forwardConfig.getRedirect()) {
   76               if (uri.startsWith("/")) {
   77                   uri = request.getContextPath() + uri;
   78               }
   79               swcontext.getResponse().sendRedirect
   80                   (swcontext.getResponse().encodeRedirectURL(uri));
   81           } else {
   82               RequestDispatcher rd =
   83                   swcontext.getContext().getRequestDispatcher(uri);
   84               rd.forward(request, swcontext.getResponse());
   85           }
   86   
   87       }
   88   
   89   
   90   }

Home » Struts-1.3.10 » org.apache.struts » chain » servlet » [javadoc | source]