- Fixed MR-84
[castle.git] / MonoRail / Castle.MonoRail.Framework / Filter.cs
blob135402ea3e5c105a10d67addc58fb2a635019174
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 /// <summary>
18 /// Base class for filters which dispatches to virtual methods
19 /// based on the <see cref="ExecuteEnum"/> value.
20 /// </summary>
21 public abstract class Filter : IFilter
23 /// <summary>
24 /// Implementors should perform they filter logic and
25 /// return <c>true</c> if the action should be processed.
26 /// </summary>
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 /// <returns><c>true</c> if the action
31 /// should be invoked, otherwise <c>false</c></returns>
32 public bool Perform(ExecuteEnum exec, IRailsEngineContext context, IController controller)
34 if (exec == ExecuteEnum.AfterAction)
36 OnAfterAction(context, controller);
37 return true;
39 else if (exec == ExecuteEnum.AfterRendering)
41 OnAfterRendering(context, controller);
42 return true;
44 else if (exec == ExecuteEnum.BeforeAction)
46 return OnBeforeAction(context, controller);
48 else // if (exec == ExecuteEnum.StartRequest)
50 return OnStartRequest(context, controller);
54 /// <summary>
55 /// Override this method if the filter was set to
56 /// handle <see cref="ExecuteEnum.AfterAction"/>
57 /// </summary>
58 /// <param name="context">The MonoRail request context</param>
59 /// <param name="controller">The controller instance</param>
60 protected virtual void OnAfterAction(IRailsEngineContext context, IController controller)
64 /// <summary>
65 /// Override this method if the filter was set to
66 /// handle <see cref="ExecuteEnum.AfterRendering"/>
67 /// </summary>
68 /// <param name="context">The MonoRail request context</param>
69 /// <param name="controller">The controller instance</param>
70 protected virtual void OnAfterRendering(IRailsEngineContext context, IController controller)
74 /// <summary>
75 /// Override this method if the filter was set to
76 /// handle <see cref="ExecuteEnum.BeforeAction"/>
77 /// </summary>
78 /// <param name="context">The MonoRail request context</param>
79 /// <param name="controller">The controller instance</param>
80 /// <returns><c>true</c> if the request should proceed, otherwise <c>false</c></returns>
81 protected virtual bool OnBeforeAction(IRailsEngineContext context, IController controller)
83 return true;
86 /// <summary>
87 /// Override this method if the filter was set to
88 /// handle <see cref="ExecuteEnum.StartRequest"/>
89 /// </summary>
90 /// <param name="context">The MonoRail request context</param>
91 /// <param name="controller">The controller instance</param>
92 /// <returns><c>true</c> if the request should proceed, otherwise <c>false</c></returns>
93 protected virtual bool OnStartRequest(IRailsEngineContext context, IController controller)
95 return true;