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 using Castle
.MonoRail
.Framework
.Filters
;
21 /// This is an special filter attribute. It is used
22 /// to define from where MonoRail should read the localization information
23 /// to find out the locale of the client.
25 /// For example, it can use the browser, or a cookie, an entry in the
26 /// query string (or even in the session)
29 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false, Inherited
=true), Serializable
]
30 public class LocalizationFilterAttribute
: FilterAttribute
32 private bool failOnError
= false, useBrowser
= true;
33 private String key
= "locale";
34 private RequestStore requestStore
= RequestStore
.Cookie
;
38 /// you want to use a cookie named
39 /// "locale", but if that fails it falls back
40 /// to the client's browser locale.
42 public LocalizationFilterAttribute() : base(ExecuteEnum
.BeforeAction
, typeof(LocalizationFilter
))
47 /// Defines a new LocalizationFilter.
49 /// <param name="store">Location where the localization parameter is stored.</param>
50 /// <param name="key">Name of the parameter in the store.</param>
51 public LocalizationFilterAttribute(RequestStore store
, String key
) : this()
60 /// Key under which the locale value is stored.
69 /// Location where the locale value is to be stored.
71 public RequestStore Store
73 get { return requestStore; }
74 set { requestStore = value; }
78 /// True if an exception is to be thrown when a specific
79 /// culture appears to be incorrect (can't be created).
81 public bool FailOnError
83 get { return failOnError; }
84 set { failOnError = value; }
88 /// Use client browser defined languages as default.
90 public bool UseBrowser
92 get { return useBrowser; }
93 set { useBrowser = value; }