New test.
[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", 
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" };
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 #endif
76                 
77                 static Directive ()
78                 {
79                         InitHash ();
80                 }
81                 
82                 private static void InitHash ()
83                 {
84 #if NET_2_0
85                         StringComparer comparer = StringComparer.InvariantCultureIgnoreCase;
86                         directivesHash = new Hashtable (comparer);
87 #else
88                         CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture);
89                         CaseInsensitiveComparer comparer =  new CaseInsensitiveComparer (CultureInfo.InvariantCulture);
90
91                         directivesHash = new Hashtable (provider, comparer); 
92 #endif
93
94                         // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
95 #if NET_2_0
96                         Hashtable valid_attributes = new Hashtable (comparer);
97 #else
98                         Hashtable valid_attributes = new Hashtable (provider, comparer);
99 #endif
100                         foreach (string att in page_atts) valid_attributes.Add (att, null);
101                         directivesHash.Add ("PAGE", valid_attributes);
102
103 #if NET_2_0
104                         valid_attributes = new Hashtable (comparer);
105 #else
106                         valid_attributes = new Hashtable (provider, comparer);
107 #endif
108                         foreach (string att in control_atts) valid_attributes.Add (att, null);
109                         directivesHash.Add ("CONTROL", valid_attributes);
110
111 #if NET_2_0
112                         valid_attributes = new Hashtable (comparer);
113 #else
114                         valid_attributes = new Hashtable (provider, comparer);
115 #endif
116                         foreach (string att in import_atts) valid_attributes.Add (att, null);
117                         directivesHash.Add ("IMPORT", valid_attributes);
118
119 #if NET_2_0
120                         valid_attributes = new Hashtable (comparer);
121 #else
122                         valid_attributes = new Hashtable (provider, comparer);
123 #endif
124                         foreach (string att in implements_atts) valid_attributes.Add (att, null);
125                         directivesHash.Add ("IMPLEMENTS", valid_attributes);
126
127 #if NET_2_0
128                         valid_attributes = new Hashtable (comparer);
129 #else
130                         valid_attributes = new Hashtable (provider, comparer);
131 #endif
132                         foreach (string att in register_atts) valid_attributes.Add (att, null);
133                         directivesHash.Add ("REGISTER", valid_attributes);
134
135 #if NET_2_0
136                         valid_attributes = new Hashtable (comparer);
137 #else
138                         valid_attributes = new Hashtable (provider, comparer);
139 #endif
140                         foreach (string att in assembly_atts) valid_attributes.Add (att, null);
141                         directivesHash.Add ("ASSEMBLY", valid_attributes);
142
143 #if NET_2_0
144                         valid_attributes = new Hashtable (comparer);
145 #else
146                         valid_attributes = new Hashtable (provider, comparer);
147 #endif
148                         foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
149                         directivesHash.Add ("OUTPUTCACHE", valid_attributes);
150
151 #if NET_2_0
152                         valid_attributes = new Hashtable (comparer);
153 #else
154                         valid_attributes = new Hashtable (provider, comparer);
155 #endif
156                         foreach (string att in reference_atts) valid_attributes.Add (att, null);
157                         directivesHash.Add ("REFERENCE", valid_attributes);
158
159 #if NET_2_0
160                         valid_attributes = new Hashtable (comparer);
161 #else
162                         valid_attributes = new Hashtable (provider, comparer);
163 #endif
164                         foreach (string att in webservice_atts) valid_attributes.Add (att, null);
165                         directivesHash.Add ("WEBSERVICE", valid_attributes);
166
167 #if NET_2_0
168                         valid_attributes = new Hashtable (comparer);
169 #else
170                         valid_attributes = new Hashtable (provider, comparer);
171 #endif
172                         // same attributes as webservice
173                         foreach (string att in webservice_atts) valid_attributes.Add (att, null);
174                         directivesHash.Add ("WEBHANDLER", valid_attributes);
175
176 #if NET_2_0
177                         valid_attributes = new Hashtable (comparer);
178 #else
179                         valid_attributes = new Hashtable (provider, comparer);
180 #endif
181                         foreach (string att in application_atts) valid_attributes.Add (att, null);
182                         directivesHash.Add ("APPLICATION", valid_attributes);
183
184 #if NET_2_0
185                         valid_attributes = new Hashtable (comparer);
186                         foreach (string att in mastertype_atts) valid_attributes.Add (att, null);
187                         directivesHash.Add ("MASTERTYPE", valid_attributes);
188                         
189                         valid_attributes = new Hashtable (comparer);
190                         foreach (string att in control_atts) valid_attributes.Add (att, null);
191                         directivesHash.Add ("MASTER", valid_attributes);
192 #endif
193                 }
194                 
195                 private Directive () { }
196
197                 public static bool IsDirective (string id)
198                 {
199                         return directivesHash.Contains (id);
200                 }
201         }
202 }
203