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 /// <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
);
39 else if (exec
== ExecuteEnum
.AfterRendering
)
41 OnAfterRendering(context
, controller
);
44 else if (exec
== ExecuteEnum
.BeforeAction
)
46 return OnBeforeAction(context
, controller
);
48 else // if (exec == ExecuteEnum.StartRequest)
50 return OnStartRequest(context
, controller
);
55 /// Override this method if the filter was set to
56 /// handle <see cref="ExecuteEnum.AfterAction"/>
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
)
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 protected virtual void OnAfterRendering(IRailsEngineContext context
, IController controller
)
75 /// Override this method if the filter was set to
76 /// handle <see cref="ExecuteEnum.BeforeAction"/>
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
)
87 /// Override this method if the filter was set to
88 /// handle <see cref="ExecuteEnum.StartRequest"/>
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
)