fixed ParseServerVariables().
[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 using System.Configuration;
11 using System.Xml;
12
13 namespace System.Web.Configuration
14 {
15         class PagesConfigurationHandler : IConfigurationSectionHandler
16         {
17                 public object Create (object parent, object configContext, XmlNode section)
18                 {
19                         PagesConfiguration config = new PagesConfiguration (parent);
20
21                         if (section.HasChildNodes)
22                                 HandlersUtil.ThrowException ("No child nodes allowed here.", section);
23
24                         string attvalue = AttValue ("buffer", section);
25                         if (attvalue != null)
26                                 config.Buffer = GetBool ("buffer", attvalue, section);
27
28                         attvalue = AttValue ("enableSessionState", section);
29                         if (attvalue != null) {
30                                 if (attvalue != "true" && attvalue != "false" && attvalue != "ReadOnly")
31                                         HandlersUtil.ThrowException ("Invalid value for 'enableSessionState'", section);
32
33                                 config.EnableSessionState = attvalue;
34                         }
35
36                         attvalue = AttValue ("enableViewState", section);
37                         if (attvalue != null)
38                                 config.EnableViewState = GetBool ("enableViewState", attvalue, section);
39
40                         attvalue = AttValue ("enableViewStateMac", section);
41                         if (attvalue != null)
42                                 config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
43
44                         attvalue = AttValue ("smartNavigation", section);
45                         if (attvalue != null)
46                                 config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
47
48                         attvalue = AttValue ("autoEventWireup", section);
49                         if (attvalue != null)
50                                 config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
51
52                         attvalue = AttValue ("validateRequest", section);
53                         if (attvalue != null)
54                                 config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
55
56                         attvalue = AttValue ("pageBaseType", section);
57                         if (attvalue != null) {
58                                 string v = attvalue.Trim ();
59                                 if (v.Length == 0)
60                                         HandlersUtil.ThrowException ("pageBaseType is empty.", section);
61
62                                 config.PageBaseType = v;
63                         }
64
65                         attvalue = AttValue ("userControlBaseType", section);
66                         if (attvalue != null) {
67                                 string v = attvalue.Trim ();
68                                 if (v.Length == 0)
69                                         HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
70
71                                 config.UserControlBaseType = v;
72                         }
73
74                         if (section.Attributes == null || section.Attributes.Count != 0)
75                                 HandlersUtil.ThrowException ("Unknown attribute(s).", section);
76
77                         return config;
78                 }
79
80                 static bool GetBool (string name, string value, XmlNode section)
81                 {
82                         if (value == "true")
83                                 return true;
84
85                         if (value != "false")
86                                 HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
87
88                         return false;
89                 }
90
91                 // A few methods to save some typing
92                 static string AttValue (string name, XmlNode node, bool optional)
93                 {
94                         return HandlersUtil.ExtractAttributeValue (name, node, optional);
95                 }
96
97                 static string AttValue (string name, XmlNode node)
98                 {
99                         return HandlersUtil.ExtractAttributeValue (name, node, true);
100                 }
101                 //
102         }
103 }
104