2004-01-12 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[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                         bool bvalue = false;
25                         string attvalue = AttValue ("buffer", section);
26                         if (attvalue != null)
27                                 config.Buffer = GetBool ("buffer", attvalue, section);
28
29                         attvalue = AttValue ("enableSessionState", section);
30                         if (attvalue != null) {
31                                 if (attvalue != "true" && attvalue != "false" && attvalue != "ReadOnly")
32                                         HandlersUtil.ThrowException ("Invalid value for 'enableSessionState'", section);
33
34                                 config.EnableSessionState = attvalue;
35                         }
36
37                         attvalue = AttValue ("enableViewState", section);
38                         if (attvalue != null)
39                                 config.EnableViewState = GetBool ("enableViewState", attvalue, section);
40
41                         attvalue = AttValue ("enableViewStateMac", section);
42                         if (attvalue != null)
43                                 config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
44
45                         attvalue = AttValue ("smartNavigation", section);
46                         if (attvalue != null)
47                                 config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
48
49                         attvalue = AttValue ("autoEventWireup", section);
50                         if (attvalue != null)
51                                 config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
52
53                         attvalue = AttValue ("validateRequest", section);
54                         if (attvalue != null)
55                                 config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
56
57                         attvalue = AttValue ("pageBaseType", section);
58                         if (attvalue != null) {
59                                 string v = attvalue.Trim ();
60                                 if (v.Length == 0)
61                                         HandlersUtil.ThrowException ("pageBaseType is empty.", section);
62
63                                 config.PageBaseType = v;
64                         }
65
66                         attvalue = AttValue ("userControlBaseType", section);
67                         if (attvalue != null) {
68                                 string v = attvalue.Trim ();
69                                 if (v.Length == 0)
70                                         HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
71
72                                 config.UserControlBaseType = v;
73                         }
74
75                         if (section.Attributes == null || section.Attributes.Count != 0)
76                                 HandlersUtil.ThrowException ("Unknown attribute(s).", section);
77
78                         return config;
79                 }
80
81                 static bool GetBool (string name, string value, XmlNode section)
82                 {
83                         if (value == "true")
84                                 return true;
85
86                         if (value != "false")
87                                 HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
88
89                         return false;
90                 }
91
92                 // A few methods to save some typing
93                 static string AttValue (string name, XmlNode node, bool optional)
94                 {
95                         return HandlersUtil.ExtractAttributeValue (name, node, optional);
96                 }
97
98                 static string AttValue (string name, XmlNode node)
99                 {
100                         return HandlersUtil.ExtractAttributeValue (name, node, true);
101                 }
102                 //
103         }
104 }
105