2005-11-24 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / PagesSection.cs
1 //
2 // System.Web.Configuration.PagesSection
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.ComponentModel;
35 using System.Configuration;
36 using System.Web.UI;
37 using System.Xml;
38
39 namespace System.Web.Configuration
40 {
41         public sealed class PagesSection: ConfigurationSection
42         {
43                 static ConfigurationPropertyCollection properties;
44                 static ConfigurationProperty asyncTimeoutProp;
45                 static ConfigurationProperty autoEventWireupProp;
46                 static ConfigurationProperty bufferProp;
47                 static ConfigurationProperty controlsProp;
48                 static ConfigurationProperty enableEventValidationProp;
49                 static ConfigurationProperty enableSessionStateProp;
50                 static ConfigurationProperty enableViewStateProp;
51                 static ConfigurationProperty enableViewStateMacProp;
52                 static ConfigurationProperty maintainScrollPositionOnPostBackProp;
53                 static ConfigurationProperty masterPageFileProp;
54                 static ConfigurationProperty maxPageStateFieldLengthProp;
55                 static ConfigurationProperty modeProp;
56                 static ConfigurationProperty namespacesProp;
57                 static ConfigurationProperty pageBaseTypeProp;
58                 static ConfigurationProperty pageParserFilterTypeProp;
59                 static ConfigurationProperty smartNavigationProp;
60                 static ConfigurationProperty styleSheetThemeProp;
61                 static ConfigurationProperty tagMappingProp;
62                 static ConfigurationProperty themeProp;
63                 static ConfigurationProperty userControlBaseTypeProp;
64                 static ConfigurationProperty validateRequestProp;
65                 static ConfigurationProperty viewStateEncryptionModeProp;
66
67                 static PagesSection ()
68                 {
69                         asyncTimeoutProp = new ConfigurationProperty ("asyncTimeout", typeof (TimeSpan), null,
70                                                                       PropertyHelper.TimeSpanSecondsConverter,
71                                                                       PropertyHelper.PositiveTimeSpanValidator,
72                                                                       ConfigurationPropertyOptions.None);
73                         autoEventWireupProp = new ConfigurationProperty ("autoEventWireup", typeof(bool), true);
74                         bufferProp = new ConfigurationProperty ("buffer", typeof(bool), false);
75                         controlsProp = new ConfigurationProperty ("controls", typeof(TagPrefixCollection), null);
76                         enableEventValidationProp = new ConfigurationProperty ("enableEventValidation", typeof (bool), true);
77                         enableSessionStateProp = new ConfigurationProperty ("enableSessionState", typeof (PagesEnableSessionState), true);
78                         enableViewStateProp = new ConfigurationProperty ("enableViewState", typeof (bool), true);
79                         enableViewStateMacProp = new ConfigurationProperty ("enableViewStateMac", typeof (bool), true);
80                         maintainScrollPositionOnPostBackProp = new ConfigurationProperty ("maintainScrollPositionOnPostBack", typeof (bool), false);
81                         masterPageFileProp = new ConfigurationProperty ("masterPageFile", typeof (string), "");
82                         maxPageStateFieldLengthProp = new ConfigurationProperty ("maxPageStateFieldLength", typeof (int), -1);
83                         modeProp = new ConfigurationProperty ("compilationMode", typeof (CompilationMode), CompilationMode.Always,
84                                                               new GenericEnumConverter (typeof (CompilationMode)), PropertyHelper.DefaultValidator,
85                                                               ConfigurationPropertyOptions.None);
86                         namespacesProp = new ConfigurationProperty ("namespacesProp", typeof (NamespaceCollection), null);
87                         pageBaseTypeProp = new ConfigurationProperty ("pageBaseType", typeof (string), "System.Web.UI.Page");
88                         pageParserFilterTypeProp = new ConfigurationProperty ("pageParserFilterType", typeof (string), "");
89                         smartNavigationProp = new ConfigurationProperty ("smartNavigation", typeof (bool), false);
90                         styleSheetThemeProp = new ConfigurationProperty ("styleSheetTheme", typeof (string), "");
91                         tagMappingProp = new ConfigurationProperty ("tagMapping", typeof (TagMapCollection), null);
92                         themeProp = new ConfigurationProperty ("theme", typeof (string), "");
93                         userControlBaseTypeProp = new ConfigurationProperty ("userControlBaseType", typeof (string), "System.Web.UI.UserControl");
94                         validateRequestProp = new ConfigurationProperty ("validateRequest", typeof (bool), true);
95                         viewStateEncryptionModeProp = new ConfigurationProperty ("viewStateEncryptionMode", typeof (ViewStateEncryptionMode), ViewStateEncryptionMode.Auto,
96                                                                                  new GenericEnumConverter (typeof (ViewStateEncryptionMode)), PropertyHelper.DefaultValidator,
97                                                                                  ConfigurationPropertyOptions.None);
98
99                         properties = new ConfigurationPropertyCollection ();
100                         properties.Add (asyncTimeoutProp);
101                         properties.Add (autoEventWireupProp);
102                         properties.Add (bufferProp);
103                         properties.Add (enableEventValidationProp);
104                         properties.Add (enableSessionStateProp);
105                         properties.Add (enableViewStateProp);
106                         properties.Add (enableViewStateMacProp);
107                         properties.Add (maintainScrollPositionOnPostBackProp);
108                         properties.Add (masterPageFileProp);
109                         properties.Add (maxPageStateFieldLengthProp);
110                         properties.Add (modeProp);
111                         properties.Add (pageBaseTypeProp);
112                         properties.Add (pageParserFilterTypeProp);
113                         properties.Add (smartNavigationProp);
114                         properties.Add (styleSheetThemeProp);
115                         properties.Add (themeProp);
116                         properties.Add (userControlBaseTypeProp);
117                         properties.Add (validateRequestProp);
118                         properties.Add (viewStateEncryptionModeProp);
119                 }
120
121                 public PagesSection ()
122                 {
123                 }
124                 
125                 [TimeSpanValidator (MinValueString = "00:00:00",
126                                     MaxValueString = "10675199.02:48:05.4775807")]
127                 [TypeConverter (typeof (TimeSpanSecondsConverter))]
128                 [ConfigurationProperty ("asyncTimeout", DefaultValue = "00:00:45")]
129                 public TimeSpan AsyncTimeout {
130                         get { return (TimeSpan) base [asyncTimeoutProp]; }
131                         set { base [asyncTimeoutProp] = value; }
132                 }
133
134                 [ConfigurationProperty ("autoEventWireup", DefaultValue = "True")]
135                 public bool AutoEventWireup {
136                         get { return (bool) base [autoEventWireupProp]; }
137                         set { base [autoEventWireupProp] = value; }
138                 }
139
140                 [ConfigurationProperty ("buffer", DefaultValue = "True")]
141                 public bool Buffer {
142                         get { return (bool) base [bufferProp]; }
143                         set { base [bufferProp] = value; }
144                 }
145
146                 [ConfigurationProperty ("compilationMode", DefaultValue = "Always")]
147                 public CompilationMode CompilationMode {
148                         get { return (CompilationMode) base [modeProp]; }
149                         set { base [modeProp] = value; }
150                 }
151
152                 [ConfigurationProperty ("controls")]
153                 public TagPrefixCollection Controls {
154                         get { return (TagPrefixCollection) base[controlsProp]; }
155                 }
156
157                 [ConfigurationProperty ("enableEventValidation", DefaultValue = "True")]
158                 public bool EnableEventValidation {
159                         get { return (bool) base[enableEventValidationProp]; }
160                         set { base[enableEventValidationProp] = value; }
161                 }
162
163                 [ConfigurationProperty ("enableSessionState", DefaultValue = "true")]
164                 public PagesEnableSessionState EnableSessionState {
165                         get { return (PagesEnableSessionState) base[enableSessionStateProp]; }
166                         set { base[enableSessionStateProp] = value; }
167                 }
168
169                 [ConfigurationProperty ("enableViewState", DefaultValue = "True")]
170                 public bool EnableViewState {
171                         get { return (bool) base[enableViewStateProp]; }
172                         set { base[enableViewStateProp] = value; }
173                 }
174
175                 [ConfigurationProperty ("enableViewStateMac", DefaultValue = "True")]
176                 public bool EnableViewStateMac {
177                         get { return (bool) base[enableViewStateMacProp]; }
178                         set { base[enableViewStateMacProp] = value; }
179                 }
180
181                 [ConfigurationProperty ("maintainScrollPositionOnPostBack", DefaultValue = "False")]
182                 public bool MaintainScrollPositionOnPostBack {
183                         get { return (bool) base[maintainScrollPositionOnPostBackProp]; }
184                         set { base [maintainScrollPositionOnPostBackProp] = value; }
185                 }
186
187                 [ConfigurationProperty ("masterPageFile", DefaultValue = "")]
188                 public string MasterPageFile {
189                         get { return (string) base[masterPageFileProp]; }
190                         set { base[masterPageFileProp] = value; }
191                 }
192
193                 [ConfigurationProperty ("maxPageStateFieldLength", DefaultValue = "-1")]
194                 public int MaxPageStateFieldLength {
195                         get { return (int) base[maxPageStateFieldLengthProp]; }
196                         set { base[maxPageStateFieldLengthProp] = value; }
197                 }
198
199                 [ConfigurationProperty ("namespaces")]
200                 public NamespaceCollection Namespaces {
201                         get { return (NamespaceCollection) base[namespacesProp]; }
202                 }
203
204                 [ConfigurationProperty ("pageBaseType", DefaultValue = "System.Web.UI.Page")]
205                 public string PageBaseType {
206                         get { return (string) base[pageBaseTypeProp]; }
207                         set { base[pageBaseTypeProp] = value; }
208                 }
209
210                 [ConfigurationProperty ("pageParserFilterType", DefaultValue = "")]
211                 public string PageParserFilterType {
212                         get { return (string) base[pageParserFilterTypeProp]; }
213                         set { base [pageParserFilterTypeProp] = value; }
214                 }
215
216                 [ConfigurationProperty ("smartNavigation", DefaultValue = "False")]
217                 public bool SmartNavigation {
218                         get { return (bool) base[smartNavigationProp]; }
219                         set { base[smartNavigationProp] = value; }
220                 }
221
222                 [ConfigurationProperty ("styleSheetTheme", DefaultValue = "")]
223                 public string StyleSheetTheme {
224                         get { return (string) base[styleSheetThemeProp]; }
225                         set { base[styleSheetThemeProp] = value; }
226                 }
227
228                 [ConfigurationProperty ("tagMapping")]
229                 public TagMapCollection TagMapping {
230                         get { return (TagMapCollection) base [tagMappingProp]; }
231                 }
232
233                 [ConfigurationProperty ("theme", DefaultValue = "")]
234                 public string Theme {
235                         get { return (string) base[themeProp]; }
236                         set { base[themeProp] = value; }
237                 }
238
239                 [ConfigurationProperty ("userControlBaseType", DefaultValue = "System.Web.UI.UserControl")]
240                 public string UserControlBaseType {
241                         get { return (string) base[userControlBaseTypeProp]; }
242                         set { base[userControlBaseTypeProp] = value; }
243                 }
244
245                 [ConfigurationProperty ("validateRequest", DefaultValue = "True")]
246                 public bool ValidateRequest {
247                         get { return (bool) base[validateRequestProp]; }
248                         set { base[validateRequestProp] = value; }
249                 }
250
251                 [ConfigurationProperty ("viewStateEncryptionMode", DefaultValue = "Auto")]
252                 public ViewStateEncryptionMode ViewStateEncryptionMode {
253                         get { return (ViewStateEncryptionMode) base [viewStateEncryptionModeProp]; }
254                         set { base [viewStateEncryptionModeProp] = value; }
255                 }
256
257                 protected override ConfigurationPropertyCollection Properties {
258                         get { return properties; }
259                 }
260
261                 [MonoTODO]
262                 protected override void DeserializeSection (XmlReader reader)
263                 {
264                         base.DeserializeSection (reader);
265
266                         /* XXX more here?.. */
267                 }
268
269 #region CompatabilityCode
270                 [MonoTODO ("we really shouldn't need this..")]
271                 internal static PagesSection GetInstance ()
272                 {
273                         PagesSection config;
274
275                         if (HttpContext.Current != null) {
276                                 config = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
277                                 if (config == null)
278                                         throw new Exception ("Configuration error.");
279                         } else {
280                                 // empty config (as used in unit tests)
281                                 config = new PagesSection ();
282                         }
283
284                         return config;
285                 }
286 #endregion
287         }
288 }
289
290 #endif