001: /*
002: * Copyright 2005-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005: * in compliance with the License. You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software distributed under the License
010: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011: * or implied. See the License for the specific language governing permissions and limitations under
012: * the License.
013: */
014:
015: package org.strecks.controller;
016:
017: import java.io.IOException;
018:
019: import javax.servlet.ServletException;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import org.apache.struts.action.Action;
024: import org.apache.struts.action.ActionForm;
025: import org.apache.struts.action.ActionForward;
026: import org.apache.struts.action.ActionMapping;
027: import org.apache.struts.action.ActionServlet;
028: import org.apache.struts.config.ModuleConfig;
029: import org.apache.struts.tiles.TilesRequestProcessor;
030:
031: /**
032: * <p>
033: * Provides hook methods for subclassing <code>TilesRequestProcessor</code>. Actual behaviour
034: * identitical to request processor. Also allows any extended behaviour to be overridden to return
035: * to default behaviour. In other words, would be possible create subclass of
036: * <code>ControllerRequestProcessor</code> exhibiting same behaviour as
037: * <code>RequestProcessor</code>
038: * </p>
039: * <p><b>Note:</b> this class can be maintained by simply copying any updates from <code>BaseRequestProcessor</code>.
040: * The only difference is that it extends <code>TilesRequestProcessor</code>, not <code>RequestProcessor</code></p>
041: * @author Phil Zoio
042: */
043: public class BaseTilesRequestProcessor extends TilesRequestProcessor {
044:
045: /**
046: * Creates hooks for extending <code>init()</code>
047: */
048: @Override
049: public void init(ActionServlet servlet, ModuleConfig config)
050: throws ServletException {
051: super .init(servlet, config);
052: postInit(servlet, config);
053: }
054:
055: protected void processCachedMessages(HttpServletRequest request,
056: HttpServletResponse response) {
057: preProcessCachedMessages(request);
058: super .processCachedMessages(request, response);
059: }
060:
061: /**
062: * Creates hooks for extending <code>processActionForm()</code>
063: */
064: protected ActionForm processActionForm(HttpServletRequest request,
065: HttpServletResponse response, ActionMapping mapping) {
066: ActionForm form = super .processActionForm(request, response,
067: mapping);
068: return postProcessActionForm(request, response, form);
069: }
070:
071: @Override
072: protected void processPopulate(HttpServletRequest request,
073: HttpServletResponse response, ActionForm form,
074: ActionMapping mapping) throws ServletException {
075: form = prePopulate(form, request);
076: super .processPopulate(request, response, form, mapping);
077: }
078:
079: /**
080: * Creates hooks for extending <code>processValidate()</code>
081: */
082: protected boolean processValidate(HttpServletRequest request,
083: HttpServletResponse response, ActionForm form,
084: ActionMapping mapping) throws IOException, ServletException {
085: form = preValidate(form, request);
086: boolean validate;
087: try {
088: validate = super .processValidate(request, response, form,
089: mapping);
090: } catch (IOException e) {
091: throw e;
092: } catch (ServletException e) {
093: throw e;
094: } catch (Exception e) {
095: //added to handle addition of InvalidCancelException in Struts 1.2.9
096: throw new ServletException(e);
097: }
098: postValidate(request, mapping, validate);
099: return validate;
100: }
101:
102: /**
103: * Creates hooks for extending <code>processActionCreate()</code>
104: */
105: protected Action processActionCreate(HttpServletRequest request,
106: HttpServletResponse response, ActionMapping actionMapping)
107: throws IOException {
108:
109: Action action = extendedProcessActionCreate(request, response,
110: actionMapping);
111: if (action != null)
112: return action;
113:
114: return super .processActionCreate(request, response,
115: actionMapping);
116: }
117:
118: /**
119: * Creates hooks for extending <code>processActionPerform()</code>
120: */
121: @Override
122: protected final ActionForward processActionPerform(
123: HttpServletRequest request, HttpServletResponse response,
124: Action action, ActionForm form, ActionMapping mapping)
125: throws IOException, ServletException {
126:
127: return extendedProcessActionPerform(request, response, action,
128: form, mapping);
129:
130: }
131:
132: /* ***************************** null op hook implementations **************************** */
133:
134: /**
135: * Hook method. Calls <code>super.processActionPerform()</code>
136: */
137: protected ActionForward extendedProcessActionPerform(
138: HttpServletRequest request, HttpServletResponse response,
139: Action action, ActionForm form, ActionMapping mapping)
140: throws IOException, ServletException {
141: return super .processActionPerform(request, response, action,
142: form, mapping);
143: }
144:
145: /**
146: * No op hook method implementation
147: */
148: protected void postInit(ActionServlet servlet, ModuleConfig config) {
149: }
150:
151: /**
152: * No op hook method implementation
153: */
154: protected void preProcessCachedMessages(HttpServletRequest request) {
155: }
156:
157: /**
158: * No op hook method implementation
159: */
160: protected ActionForm postProcessActionForm(
161: HttpServletRequest request, HttpServletResponse response,
162: ActionForm form) {
163: return form;
164: }
165:
166: /**
167: * No op hook method implementation
168: */
169: protected ActionForm prePopulate(ActionForm form,
170: HttpServletRequest request) {
171: return form;
172: }
173:
174: /**
175: * No op hook method implementation
176: */
177: protected void postValidate(HttpServletRequest request,
178: ActionMapping mapping, boolean validate) {
179: }
180:
181: /**
182: * No op hook method implementation
183: */
184: protected ActionForm preValidate(ActionForm form,
185: HttpServletRequest request) {
186: return null;
187: }
188:
189: /**
190: * No op hook method implementation. Returns null
191: */
192: protected Action extendedProcessActionCreate(
193: HttpServletRequest request, HttpServletResponse response,
194: ActionMapping actionMapping) throws IOException {
195: return null;
196: }
197:
198: }
|