001: /*
002: * $Id: TilesAction.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.tiles.actions;
023:
024: import javax.servlet.ServletException;
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.struts.action.Action;
029: import org.apache.struts.action.ActionForm;
030: import org.apache.struts.action.ActionForward;
031: import org.apache.struts.action.ActionMapping;
032: import org.apache.struts.tiles.ComponentContext;
033:
034: /**
035: * Base class for Tiles Actions.
036: * This class has the same role as Struts Action. It provides a method execute(...)
037: * called when action is invoked. The difference is, that the execute() method takes
038: * an additional parameter : tile context.
039: * This class extends Struts Action. Subclasses should override
040: * execute(ComponentContext ...) method instead of Struts
041: * execute(ActionMapping ...) method.
042: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
043: */
044: public abstract class TilesAction extends Action {
045:
046: /**
047: * Original Struts Action's method.
048: * Retrieve current Tile context and call TilesAction execute method.
049: * Do not overload this method!
050: *
051: * @param mapping The ActionMapping used to select this instance.
052: * @param form The optional ActionForm bean for this request (if any).
053: * @param request The HTTP request we are processing.
054: * @param response The HTTP response we are creating.
055: *
056: * @exception Exception if the application business logic throws
057: * an exception
058: * @since Struts 1.1
059: */
060: public ActionForward execute(ActionMapping mapping,
061: ActionForm form, HttpServletRequest request,
062: HttpServletResponse response) throws Exception {
063:
064: // Try to retrieve tile context
065: ComponentContext context = ComponentContext.getContext(request);
066: if (context == null) {
067: throw new ServletException(
068: "Can't find Tile context for '"
069: + this .getClass().getName()
070: + "'. TilesAction subclasses must be called from a Tile");
071: }
072:
073: return this .execute(context, mapping, form, request, response);
074: }
075:
076: /**
077: * Process the specified HTTP request and create the corresponding HTTP
078: * response (or forward to another web component that will create it),
079: * with provision for handling exceptions thrown by the business logic.
080: * <br>
081: * Override this method to provide functionality.
082: *
083: * @param context The current Tile context, containing Tile attributes.
084: * @param mapping The ActionMapping used to select this instance.
085: * @param form The optional ActionForm bean for this request (if any).
086: * @param request The HTTP request we are processing.
087: * @param response The HTTP response we are creating.
088: *
089: * @exception Exception if the application business logic throws
090: * an exception
091: * @since Struts 1.1
092: */
093: public ActionForward execute(ComponentContext context,
094: ActionMapping mapping, ActionForm form,
095: HttpServletRequest request, HttpServletResponse response)
096: throws Exception {
097:
098: return null;
099: }
100:
101: }
|