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.action.RequestProcessor;
029: import org.apache.struts.config.ModuleConfig;
030:
031: /**
032: * <p>
033: * Provides hook methods for subclassing <code>RequestProcessor</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: * @author Phil Zoio
040: */
041: public class BaseRequestProcessor extends RequestProcessor {
042:
043: /**
044: * Creates hooks for extending <code>init()</code>
045: */
046: @Override
047: public void init(ActionServlet servlet, ModuleConfig config)
048: throws ServletException {
049: super .init(servlet, config);
050: postInit(servlet, config);
051: }
052:
053: protected void processCachedMessages(HttpServletRequest request,
054: HttpServletResponse response) {
055: preProcessCachedMessages(request);
056: super .processCachedMessages(request, response);
057: }
058:
059: /**
060: * Creates hooks for extending <code>processActionForm()</code>
061: */
062: protected ActionForm processActionForm(HttpServletRequest request,
063: HttpServletResponse response, ActionMapping mapping) {
064: ActionForm form = super .processActionForm(request, response,
065: mapping);
066: return postProcessActionForm(request, response, form);
067: }
068:
069: @Override
070: protected void processPopulate(HttpServletRequest request,
071: HttpServletResponse response, ActionForm form,
072: ActionMapping mapping) throws ServletException {
073: form = prePopulate(form, request);
074: super .processPopulate(request, response, form, mapping);
075: }
076:
077: /**
078: * Creates hooks for extending <code>processValidate()</code>
079: */
080: protected boolean processValidate(HttpServletRequest request,
081: HttpServletResponse response, ActionForm form,
082: ActionMapping mapping) throws IOException, ServletException {
083: form = preValidate(form, request);
084: boolean validate;
085: try {
086: validate = super .processValidate(request, response, form,
087: mapping);
088: } catch (IOException e) {
089: throw e;
090: } catch (ServletException e) {
091: throw e;
092: } catch (Exception e) {
093: //added to handle addition of InvalidCancelException in Struts 1.2.9
094: throw new ServletException(e);
095: }
096: postValidate(request, mapping, validate);
097: return validate;
098: }
099:
100: /**
101: * Creates hooks for extending <code>processActionCreate()</code>
102: */
103: protected Action processActionCreate(HttpServletRequest request,
104: HttpServletResponse response, ActionMapping actionMapping)
105: throws IOException {
106:
107: Action action = extendedProcessActionCreate(request, response,
108: actionMapping);
109: if (action != null)
110: return action;
111:
112: return super .processActionCreate(request, response,
113: actionMapping);
114: }
115:
116: /**
117: * Creates hooks for extending <code>processActionPerform()</code>
118: */
119: @Override
120: protected final ActionForward processActionPerform(
121: HttpServletRequest request, HttpServletResponse response,
122: Action action, ActionForm form, ActionMapping mapping)
123: throws IOException, ServletException {
124:
125: return extendedProcessActionPerform(request, response, action,
126: form, mapping);
127:
128: }
129:
130: /* ***************************** null op hook implementations **************************** */
131:
132: /**
133: * Hook method. Calls <code>super.processActionPerform()</code>
134: */
135: protected ActionForward extendedProcessActionPerform(
136: HttpServletRequest request, HttpServletResponse response,
137: Action action, ActionForm form, ActionMapping mapping)
138: throws IOException, ServletException {
139: return super .processActionPerform(request, response, action,
140: form, mapping);
141: }
142:
143: /**
144: * No op hook method implementation
145: */
146: protected void postInit(ActionServlet servlet, ModuleConfig config) {
147: }
148:
149: /**
150: * No op hook method implementation
151: */
152: protected void preProcessCachedMessages(HttpServletRequest request) {
153: }
154:
155: /**
156: * No op hook method implementation
157: */
158: protected ActionForm postProcessActionForm(
159: HttpServletRequest request, HttpServletResponse response,
160: ActionForm form) {
161: return form;
162: }
163:
164: /**
165: * No op hook method implementation
166: */
167: protected ActionForm prePopulate(ActionForm form,
168: HttpServletRequest request) {
169: return form;
170: }
171:
172: /**
173: * No op hook method implementation
174: */
175: protected void postValidate(HttpServletRequest request,
176: ActionMapping mapping, boolean validate) {
177: }
178:
179: /**
180: * No op hook method implementation
181: */
182: protected ActionForm preValidate(ActionForm form,
183: HttpServletRequest request) {
184: return null;
185: }
186:
187: /**
188: * No op hook method implementation. Returns null
189: */
190: protected Action extendedProcessActionCreate(
191: HttpServletRequest request, HttpServletResponse response,
192: ActionMapping actionMapping) throws IOException {
193: return null;
194: }
195:
196: }
|