001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/controller/requestprocessor/AbstractPreProcessingFilter.java,v 1.1.1.1 2004/03/25 12:08:38 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:38 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.kernel.controller.requestprocessor;
042:
043: import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
044: import java.util.Map;
045: import javax.servlet.http.HttpServletRequest;
046: import javax.servlet.http.HttpServletResponse;
047: import org.apache.struts.action.Action;
048: import org.apache.struts.action.ActionForm;
049: import org.apache.struts.action.ActionForward;
050: import org.apache.struts.action.ActionMapping;
051:
052: /**
053: * This abstract class implements some of the common functionality to all
054: * PreProcessingFilters like chaining next filter or establishing its own
055: * configuration parameters.
056: *
057: * @author Daniel Fernandez
058: * @since 1.0
059: */
060: public abstract class AbstractPreProcessingFilter implements
061: PreProcessingFilter {
062:
063: /**
064: * The next filter in the chain
065: */
066: private PreProcessingFilter nextFilter;
067:
068: /**
069: * The configuration parameters for this filter
070: */
071: private Map configurationParameters;
072:
073: /**
074: * Sets the next filter in the filter chain
075: *
076: * @param filter the filter to be chained
077: */
078: public void setNextFilter(PreProcessingFilter filter) {
079: nextFilter = filter;
080: }
081:
082: /**
083: * Sets the configuration parameters for this filter
084: *
085: * @param configurationParameters a Map with its configuration parameters
086: */
087: public void setConfigurationParameters(Map configurationParameters) {
088: this .configurationParameters = configurationParameters;
089: }
090:
091: /**
092: * Executes this filter with doProcess and, depending on whether result of
093: * execution be correct or not, executes next filter or returns an
094: * error-handling ActionForward
095: *
096: * @param request the HttpServletRequest to be processed
097: * @param response the HttpServletResponse associated
098: * @param action the Struts' Action
099: * @param form the Struts' ActionForm
100: * @param mapping the Struts' ActionMapping
101: * @return a ActionForward with the result of the filter execution, null
102: * if filter processing did not raise any error.
103: * @throws InternalErrorException if a fatal error ocurrs.
104: */
105: public ActionForward process(HttpServletRequest request,
106: HttpServletResponse response, Action action,
107: ActionForm form, ActionMapping mapping)
108: throws InternalErrorException {
109:
110: ActionForward actionForward = doProcess(request, response,
111: action, form, mapping);
112: if ((actionForward == null) && (nextFilter != null)) {
113: return nextFilter.process(request, response, action, form,
114: mapping);
115: } else {
116: return actionForward;
117: }
118: }
119:
120: /**
121: * Returns the next filter in the chain
122: *
123: * @return a PreProcessingFilter with the next filter in the chain
124: */
125: protected PreProcessingFilter getNextFilter() {
126: return nextFilter;
127: }
128:
129: /**
130: * Returns this filter's configuration parameters
131: *
132: * @return a Map with the filter configuration parameters
133: */
134: protected Map getConfigurationParameters() {
135: return configurationParameters;
136: }
137:
138: /**
139: * Really applies the filter by processing the request te way it may need
140: *
141: * @param request the HttpServletRequest to be processed
142: * @param response the HttpServletResponse associated
143: * @param action the Struts' Action
144: * @param form the Struts' ActionForm
145: * @param mapping the Struts' ActionMapping
146: * @return a ActionForward with the result of the filter execution, null
147: * if filter processing did not raise any error.
148: * @throws InternalErrorException if a fatal error ocurrs.
149: */
150: protected abstract ActionForward doProcess(
151: HttpServletRequest request, HttpServletResponse response,
152: Action action, ActionForm form, ActionMapping mapping)
153: throws InternalErrorException;
154:
155: }
|