New test.
[mono.git] / mcs / class / System.Web / System.Web.Configuration / PagesConfigurationHandler.cs
1 //
2 // System.Web.Configuration.PagesConfigurationHandler
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novel.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 using System.Configuration;
32 using System.Xml;
33
34 namespace System.Web.Configuration
35 {
36         class PagesConfigurationHandler : IConfigurationSectionHandler
37         {
38                 public object Create (object parent, object configContext, XmlNode section)
39                 {
40                         PagesConfiguration config = new PagesConfiguration (parent);
41
42                         if (section.HasChildNodes)
43                                 HandlersUtil.ThrowException ("No child nodes allowed here.", section);
44
45                         string attvalue = AttValue ("buffer", section);
46                         if (attvalue != null)
47                                 config.Buffer = GetBool ("buffer", attvalue, section);
48
49                         attvalue = AttValue ("enableSessionState", section);
50                         if (attvalue != null) {
51                                 if (attvalue != "true" && attvalue != "false" && attvalue != "ReadOnly")
52                                         HandlersUtil.ThrowException ("Invalid value for 'enableSessionState'", section);
53
54                                 config.EnableSessionState = attvalue;
55                         }
56
57                         attvalue = AttValue ("enableViewState", section);
58                         if (attvalue != null)
59                                 config.EnableViewState = GetBool ("enableViewState", attvalue, section);
60
61                         attvalue = AttValue ("enableViewStateMac", section);
62                         if (attvalue != null)
63                                 config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
64
65                         attvalue = AttValue ("smartNavigation", section);
66                         if (attvalue != null)
67                                 config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
68
69                         attvalue = AttValue ("autoEventWireup", section);
70                         if (attvalue != null)
71                                 config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
72
73                         attvalue = AttValue ("validateRequest", section);
74                         if (attvalue != null)
75                                 config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
76
77                         attvalue = AttValue ("pageBaseType", section);
78                         if (attvalue != null) {
79                                 string v = attvalue.Trim ();
80                                 if (v.Length == 0)
81                                         HandlersUtil.ThrowException ("pageBaseType is empty.", section);
82
83                                 config.PageBaseType = v;
84                         }
85
86                         attvalue = AttValue ("userControlBaseType", section);
87                         if (attvalue != null) {
88                                 string v = attvalue.Trim ();
89                                 if (v.Length == 0)
90                                         HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
91
92                                 config.UserControlBaseType = v;
93                         }
94
95                         if (section.Attributes == null || section.Attributes.Count != 0)
96                                 HandlersUtil.ThrowException ("Unknown attribute(s).", section);
97
98                         return config;
99                 }
100
101                 static bool GetBool (string name, string value, XmlNode section)
102                 {
103                         if (value == "true")
104                                 return true;
105
106                         if (value != "false")
107                                 HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
108
109                         return false;
110                 }
111
112                 // A few methods to save some typing
113                 static string AttValue (string name, XmlNode node)
114                 {
115                         return HandlersUtil.ExtractAttributeValue (name, node, true);
116                 }
117                 //
118         }
119 }
120