View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.surf.site;
20  
21  import java.io.IOException;
22  
23  import javax.servlet.RequestDispatcher;
24  import javax.servlet.ServletContext;
25  import javax.servlet.ServletException;
26  import javax.servlet.ServletRequest;
27  import javax.servlet.ServletResponse;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  /**
32   * Utility class for constructing and binding RequestContext objects.
33   * 
34   * @author muzquiano
35   * @author kevinr
36   */
37  public class RequestUtil
38  {
39      /**
40       * Performs a servlet include.  This is the principal means
41       * for handling any kind of JSP include that occurs within the framework.
42       * 
43       * With this method, all dispatch path referencing is relative 
44       * to the request.
45       * 
46       * @param request
47       * @param response
48       * @param dispatchPath
49       * @throws ServletException
50       */
51      public static void include(HttpServletRequest request,
52              HttpServletResponse response, String dispatchPath)
53              throws ServletException, IOException
54      {
55          request.getRequestDispatcher(dispatchPath).include(request, response);
56      }
57  
58      /**
59       * Performs a servlet include.  This is the principal means
60       * for handling any kind of JSP include that occurs within the framework.
61       * 
62       * With this method, all dispatch path referencing is relative 
63       * to the servlet context.
64       * 
65       * @param request
66       * @param response
67       * @param dispatchPath
68       * @throws ServletException
69       */    
70      public static void include(ServletContext context, ServletRequest request,
71              ServletResponse response, String dispatchPath)
72              throws ServletException, IOException
73      {
74          RequestDispatcher disp = context.getRequestDispatcher(dispatchPath);
75          disp.include(request, response);
76      }
77  
78      /**
79       * Performs a servlet forward.  This is the principal means
80       * for handling any kind of JSP include that occurs within the framework.
81       * 
82       * With this method, all dispatch path referencing is relative 
83       * to the request.
84       * 
85       * @param request
86       * @param response
87       * @param dispatchPath
88       * @throws ServletException
89       */    
90      public static void forward(HttpServletRequest request,
91              HttpServletResponse response, String dispatchPath)
92              throws ServletException
93      {
94          try
95          {
96              request.getRequestDispatcher(dispatchPath).forward(request, response);
97          }
98          catch (Exception ex)
99          {
100             throw new ServletException(ex);
101         }
102     }
103 
104     /**
105      * Performs a servlet forward.  This is the principal means
106      * for handling any kind of JSP include that occurs within the framework.
107      * 
108      * With this method, all dispatch path referencing is relative 
109      * to the servlet context.
110      * 
111      * @param request
112      * @param response
113      * @param dispatchPath
114      * @throws ServletException
115      */    
116     public static void forward(ServletContext context, ServletRequest request,
117             ServletResponse response, String dispatchPath)
118             throws ServletException
119     {
120         try
121         {
122             RequestDispatcher disp = context.getRequestDispatcher(dispatchPath);
123             disp.forward(request, response);
124         }
125         catch (Exception ex)
126         {
127             throw new ServletException(ex);
128         }
129     }
130 }