View Javadoc

1   /*
2    * $Id: TilesAction.java 421151 2006-07-12 06:07:14Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
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.apache.struts.tiles.actions;
20  
21  import javax.servlet.ServletException;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import org.apache.struts.action.Action;
26  import org.apache.struts.action.ActionForm;
27  import org.apache.struts.action.ActionForward;
28  import org.apache.struts.action.ActionMapping;
29  import org.apache.struts.tiles.ComponentContext;
30  
31  /***
32   * Base class for Tiles Actions.
33   * This class has the same role as Struts Action. It provides a method execute(...)
34   * called when action is invoked. The difference is, that the execute() method takes
35   * an additional parameter : tile context.
36   * This class extends Struts Action. Subclasses should override
37   * execute(ComponentContext ...) method instead of Struts
38   * execute(ActionMapping ...) method.
39   * @version $Rev: 421151 $ $Date: 2006-07-11 23:07:14 -0700 (Tue, 11 Jul 2006) $
40   */
41  public abstract class TilesAction extends Action {
42  
43      /***
44       * Original Struts Action's method.
45       * Retrieve current Tile context and call TilesAction execute method.
46       * Do not overload this method!
47       *
48       * @param mapping The ActionMapping used to select this instance.
49       * @param form The optional ActionForm bean for this request (if any).
50       * @param request The HTTP request we are processing.
51       * @param response The HTTP response we are creating.
52       *
53       * @exception Exception if the application business logic throws
54       *  an exception
55       * @since Struts 1.1
56       */
57      public ActionForward execute(
58          ActionMapping mapping,
59          ActionForm form,
60          HttpServletRequest request,
61          HttpServletResponse response)
62          throws Exception {
63  
64          // Try to retrieve tile context
65          ComponentContext context = ComponentContext.getContext(request);
66          if (context == null) {
67              throw new ServletException(
68                  "Can't find Tile context for '"
69                      + this.getClass().getName()
70                      + "'. TilesAction subclasses must be called from a Tile");
71          }
72  
73          return this.execute(context, mapping, form, request, response);
74      }
75  
76      /***
77       * Process the specified HTTP request and create the corresponding HTTP
78       * response (or forward to another web component that will create it),
79       * with provision for handling exceptions thrown by the business logic.
80       * <br>
81       * Override this method to provide functionality.
82       *
83       * @param context The current Tile context, containing Tile attributes.
84       * @param mapping The ActionMapping used to select this instance.
85       * @param form The optional ActionForm bean for this request (if any).
86       * @param request The HTTP request we are processing.
87       * @param response The HTTP response we are creating.
88       *
89       * @exception Exception if the application business logic throws
90       *  an exception
91       * @since Struts 1.1
92       */
93      public ActionForward execute(
94          ComponentContext context,
95          ActionMapping mapping,
96          ActionForm form,
97          HttpServletRequest request,
98          HttpServletResponse response)
99          throws Exception {
100 
101         return null;
102     }
103 
104 }