/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.strecks.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.tiles.TilesRequestProcessor;
/**
* <p>
* Provides hook methods for subclassing <code>TilesRequestProcessor</code>. Actual behaviour
* identitical to request processor. Also allows any extended behaviour to be overridden to return
* to default behaviour. In other words, would be possible create subclass of
* <code>ControllerRequestProcessor</code> exhibiting same behaviour as
* <code>RequestProcessor</code>
* </p>
* <p><b>Note:</b> this class can be maintained by simply copying any updates from <code>BaseRequestProcessor</code>.
* The only difference is that it extends <code>TilesRequestProcessor</code>, not <code>RequestProcessor</code></p>
* @author Phil Zoio
*/
public class BaseTilesRequestProcessor extends TilesRequestProcessor
{
/**
* Creates hooks for extending <code>init()</code>
*/
@Override
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException
{
super.init(servlet, config);
postInit(servlet, config);
}
protected void processCachedMessages(HttpServletRequest request, HttpServletResponse response)
{
preProcessCachedMessages(request);
super.processCachedMessages(request, response);
}
/**
* Creates hooks for extending <code>processActionForm()</code>
*/
protected ActionForm processActionForm(HttpServletRequest request, HttpServletResponse response,
ActionMapping mapping)
{
ActionForm form = super.processActionForm(request, response, mapping);
return postProcessActionForm(request, response, form);
}
@Override
protected void processPopulate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws ServletException
{
form = prePopulate(form, request);
super.processPopulate(request, response, form, mapping);
}
/**
* Creates hooks for extending <code>processValidate()</code>
*/
protected boolean processValidate(HttpServletRequest request, HttpServletResponse response, ActionForm form,
ActionMapping mapping) throws IOException, ServletException
{
form = preValidate(form, request);
boolean validate;
try
{
validate = super.processValidate(request, response, form, mapping);
}
catch (IOException e)
{
throw e;
}
catch (ServletException e)
{
throw e;
}
catch (Exception e)
{
//added to handle addition of InvalidCancelException in Struts 1.2.9
throw new ServletException(e);
}
postValidate(request, mapping, validate);
return validate;
}
/**
* Creates hooks for extending <code>processActionCreate()</code>
*/
protected Action processActionCreate(HttpServletRequest request, HttpServletResponse response,
ActionMapping actionMapping) throws IOException
{
Action action = extendedProcessActionCreate(request, response, actionMapping);
if (action != null)
return action;
return super.processActionCreate(request, response, actionMapping);
}
/**
* Creates hooks for extending <code>processActionPerform()</code>
*/
@Override
protected final ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response,
Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException
{
return extendedProcessActionPerform(request, response, action, form, mapping);
}
/* ***************************** null op hook implementations **************************** */
/**
* Hook method. Calls <code>super.processActionPerform()</code>
*/
protected ActionForward extendedProcessActionPerform(HttpServletRequest request, HttpServletResponse response,
Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException
{
return super.processActionPerform(request, response, action, form, mapping);
}
/**
* No op hook method implementation
*/
protected void postInit(ActionServlet servlet, ModuleConfig config)
{
}
/**
* No op hook method implementation
*/
protected void preProcessCachedMessages(HttpServletRequest request)
{
}
/**
* No op hook method implementation
*/
protected ActionForm postProcessActionForm(HttpServletRequest request, HttpServletResponse response, ActionForm form)
{
return form;
}
/**
* No op hook method implementation
*/
protected ActionForm prePopulate(ActionForm form, HttpServletRequest request)
{
return form;
}
/**
* No op hook method implementation
*/
protected void postValidate(HttpServletRequest request, ActionMapping mapping, boolean validate)
{
}
/**
* No op hook method implementation
*/
protected ActionForm preValidate(ActionForm form, HttpServletRequest request)
{
return null;
}
/**
* No op hook method implementation. Returns null
*/
protected Action extendedProcessActionCreate(HttpServletRequest request, HttpServletResponse response,
ActionMapping actionMapping) throws IOException
{
return null;
}
}