Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / LocalizationFilterAttribute.cs
blobebcd7461d1460687733427327f9935b1a8ba7d73
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 using System;
18 using Filters;
20 /// <summary>
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.
24 /// <para>
25 /// For example, it can use the browser, or a cookie, an entry in the
26 /// query string (or even in the session)
27 /// </para>
28 /// </summary>
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;
36 /// <summary>
37 /// Defines that
38 /// you want to use a cookie named
39 /// "locale", but if that fails it falls back
40 /// to the client's browser locale.
41 /// </summary>
42 public LocalizationFilterAttribute() : base(ExecuteEnum.BeforeAction, typeof(LocalizationFilter))
46 /// <summary>
47 /// Defines a new LocalizationFilter.
48 /// </summary>
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()
53 this.key = key;
54 requestStore = store;
57 #region Properties
59 /// <summary>
60 /// Key under which the locale value is stored.
61 /// </summary>
62 public String Key
64 get { return key; }
65 set { key = value; }
68 /// <summary>
69 /// Location where the locale value is to be stored.
70 /// </summary>
71 public RequestStore Store
73 get { return requestStore; }
74 set { requestStore = value; }
77 /// <summary>
78 /// True if an exception is to be thrown when a specific
79 /// culture appears to be incorrect (can't be created).
80 /// </summary>
81 public bool FailOnError
83 get { return failOnError; }
84 set { failOnError = value; }
87 /// <summary>
88 /// Use client browser defined languages as default.
89 /// </summary>
90 public bool UseBrowser
92 get { return useBrowser; }
93 set { useBrowser = value; }
96 #endregion