1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
18 /// Base class for filters which dispatches to virtual methods
19 /// based on the <see cref="ExecuteEnum"/> value.
21 public abstract class Filter
: IFilter
24 /// Implementors should perform they filter logic and
25 /// return <c>true</c> if the action should be processed.
27 /// <param name="exec">When this filter is being invoked</param>
28 /// <param name="context">Current context</param>
29 /// <param name="controller">The controller instance</param>
30 /// <param name="controllerContext">The controller context.</param>
32 /// <c>true</c> if the action
33 /// should be invoked, otherwise <c>false</c>
35 public bool Perform(ExecuteEnum exec
, IEngineContext context
, IController controller
, IControllerContext controllerContext
)
37 if (exec
== ExecuteEnum
.AfterAction
)
39 OnAfterAction(context
, controller
, controllerContext
);
42 else if (exec
== ExecuteEnum
.AfterRendering
)
44 OnAfterRendering(context
, controller
, controllerContext
);
47 else // if (exec == ExecuteEnum.BeforeAction)
49 return OnBeforeAction(context
, controller
, controllerContext
);
54 /// Override this method if the filter was set to
55 /// handle <see cref="ExecuteEnum.AfterAction"/>
57 /// <param name="context">The MonoRail request context</param>
58 /// <param name="controller">The controller instance</param>
59 /// <param name="controllerContext">The controller context.</param>
60 protected virtual void OnAfterAction(IEngineContext context
, IController controller
, IControllerContext controllerContext
)
65 /// Override this method if the filter was set to
66 /// handle <see cref="ExecuteEnum.AfterRendering"/>
68 /// <param name="context">The MonoRail request context</param>
69 /// <param name="controller">The controller instance</param>
70 /// <param name="controllerContext">The controller context.</param>
71 protected virtual void OnAfterRendering(IEngineContext context
, IController controller
, IControllerContext controllerContext
)
76 /// Override this method if the filter was set to
77 /// handle <see cref="ExecuteEnum.BeforeAction"/>
79 /// <param name="context">The MonoRail request context</param>
80 /// <param name="controller">The controller instance</param>
81 /// <param name="controllerContext">The controller context.</param>
83 /// <c>true</c> if the request should proceed, otherwise <c>false</c>
85 protected virtual bool OnBeforeAction(IEngineContext context
, IController controller
, IControllerContext controllerContext
)