importing messaging-2008 branch to trunk.
[mono.git] / mcs / class / System.Web / System.Web.Compilation / Directive.cs
1 //
2 // System.Web.Compilation.Directive
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc (http://www.ximian.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;
32 using System.Collections;
33 using System.Globalization;
34
35 namespace System.Web.Compilation
36 {
37         sealed class Directive
38         {
39                 static Hashtable directivesHash;
40                 static string [] page_atts = {  "AspCompat", "AutoEventWireup", "Buffer",
41                                                 "ClassName", "ClientTarget", "CodePage",
42                                                 "CompilerOptions", "ContentType", "Culture", "Debug",
43                                                 "Description",
44 #if NET_2_0
45                                                 "EnableEventValidation", "MaintainScrollPositionOnPostBack",
46 #endif
47                                                 "EnableSessionState", "EnableViewState",
48                                                 "EnableViewStateMac", "ErrorPage", "Explicit",
49                                                 "Inherits", "Language", "LCID", "ResponseEncoding",
50                                                 "Src", "SmartNavigation", "Strict", "Trace",
51                                                 "TraceMode", "Transaction", "UICulture",
52                                                 "WarningLevel", "CodeBehind" , "ValidateRequest" };
53
54                 static string [] control_atts = { "AutoEventWireup", "ClassName", "CompilerOptions",
55                                                   "Debug", "Description", "EnableViewState",
56                                                   "Explicit", "Inherits", "Language", "Strict", "Src",
57                                                   "WarningLevel", "CodeBehind", "TargetSchema", "LinePragmas" };
58
59                 static string [] import_atts = { "namespace" };
60                 static string [] implements_atts = { "interface" };
61                 static string [] assembly_atts = { "name", "src" };
62                 static string [] register_atts = { "tagprefix", "tagname", "Namespace", "Src", "Assembly" };
63
64                 static string [] outputcache_atts = { "Duration", "Location", "VaryByControl", 
65                                                       "VaryByCustom", "VaryByHeader", "VaryByParam" };
66
67                 static string [] reference_atts = { "page", "control" };
68
69                 static string [] webservice_atts = { "class", "codebehind", "debug", "language" };
70
71                 static string [] application_atts = { "description", "inherits", "codebehind" };
72
73 #if NET_2_0
74                 static string [] mastertype_atts = { "virtualpath", "typename" };
75                 static string [] previouspagetype_atts = { "virtualpath", "typename" };
76 #endif
77                 
78                 static Directive ()
79                 {
80                         InitHash ();
81                 }
82                 
83                 static void InitHash ()
84                 {
85 #if NET_2_0
86                         StringComparer comparer = StringComparer.InvariantCultureIgnoreCase;
87                         directivesHash = new Hashtable (comparer);
88 #else
89                         CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture);
90                         CaseInsensitiveComparer comparer =  new CaseInsensitiveComparer (CultureInfo.InvariantCulture);
91
92                         directivesHash = new Hashtable (provider, comparer); 
93 #endif
94
95                         // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
96 #if NET_2_0
97                         Hashtable valid_attributes = new Hashtable (comparer);
98 #else
99                         Hashtable valid_attributes = new Hashtable (provider, comparer);
100 #endif
101                         foreach (string att in page_atts) valid_attributes.Add (att, null);
102                         directivesHash.Add ("PAGE", valid_attributes);
103
104 #if NET_2_0
105                         valid_attributes = new Hashtable (comparer);
106 #else
107                         valid_attributes = new Hashtable (provider, comparer);
108 #endif
109                         foreach (string att in control_atts) valid_attributes.Add (att, null);
110                         directivesHash.Add ("CONTROL", valid_attributes);
111
112 #if NET_2_0
113                         valid_attributes = new Hashtable (comparer);
114 #else
115                         valid_attributes = new Hashtable (provider, comparer);
116 #endif
117                         foreach (string att in import_atts) valid_attributes.Add (att, null);
118                         directivesHash.Add ("IMPORT", valid_attributes);
119
120 #if NET_2_0
121                         valid_attributes = new Hashtable (comparer);
122 #else
123                         valid_attributes = new Hashtable (provider, comparer);
124 #endif
125                         foreach (string att in implements_atts) valid_attributes.Add (att, null);
126                         directivesHash.Add ("IMPLEMENTS", valid_attributes);
127
128 #if NET_2_0
129                         valid_attributes = new Hashtable (comparer);
130 #else
131                         valid_attributes = new Hashtable (provider, comparer);
132 #endif
133                         foreach (string att in register_atts) valid_attributes.Add (att, null);
134                         directivesHash.Add ("REGISTER", valid_attributes);
135
136 #if NET_2_0
137                         valid_attributes = new Hashtable (comparer);
138 #else
139                         valid_attributes = new Hashtable (provider, comparer);
140 #endif
141                         foreach (string att in assembly_atts) valid_attributes.Add (att, null);
142                         directivesHash.Add ("ASSEMBLY", valid_attributes);
143
144 #if NET_2_0
145                         valid_attributes = new Hashtable (comparer);
146 #else
147                         valid_attributes = new Hashtable (provider, comparer);
148 #endif
149                         foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
150                         directivesHash.Add ("OUTPUTCACHE", valid_attributes);
151
152 #if NET_2_0
153                         valid_attributes = new Hashtable (comparer);
154 #else
155                         valid_attributes = new Hashtable (provider, comparer);
156 #endif
157                         foreach (string att in reference_atts) valid_attributes.Add (att, null);
158                         directivesHash.Add ("REFERENCE", valid_attributes);
159
160 #if NET_2_0
161                         valid_attributes = new Hashtable (comparer);
162 #else
163                         valid_attributes = new Hashtable (provider, comparer);
164 #endif
165                         foreach (string att in webservice_atts) valid_attributes.Add (att, null);
166                         directivesHash.Add ("WEBSERVICE", valid_attributes);
167
168 #if NET_2_0
169                         valid_attributes = new Hashtable (comparer);
170 #else
171                         valid_attributes = new Hashtable (provider, comparer);
172 #endif
173                         // same attributes as webservice
174                         foreach (string att in webservice_atts) valid_attributes.Add (att, null);
175                         directivesHash.Add ("WEBHANDLER", valid_attributes);
176
177 #if NET_2_0
178                         valid_attributes = new Hashtable (comparer);
179 #else
180                         valid_attributes = new Hashtable (provider, comparer);
181 #endif
182                         foreach (string att in application_atts) valid_attributes.Add (att, null);
183                         directivesHash.Add ("APPLICATION", valid_attributes);
184
185 #if NET_2_0
186                         valid_attributes = new Hashtable (comparer);
187                         foreach (string att in mastertype_atts) valid_attributes.Add (att, null);
188                         directivesHash.Add ("MASTERTYPE", valid_attributes);
189                         
190                         valid_attributes = new Hashtable (comparer);
191                         foreach (string att in control_atts) valid_attributes.Add (att, null);
192                         directivesHash.Add ("MASTER", valid_attributes);
193
194                         valid_attributes = new Hashtable (comparer);
195                         foreach (string att in previouspagetype_atts) valid_attributes.Add (att, null);
196                         directivesHash.Add ("PREVIOUSPAGETYPE", valid_attributes);
197 #endif
198                 }
199                 
200                 Directive () { }
201
202                 public static bool IsDirective (string id)
203                 {
204                         return directivesHash.Contains (id);
205                 }
206         }
207 }
208