2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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
34 namespace System.Web.Compilation
35 {
36         sealed class Directive
37         {
38                 static Hashtable directivesHash;
39                 static string [] page_atts = {  "AspCompat", "AutoEventWireup", "Buffer",
40                                                 "ClassName", "ClientTarget", "CodePage",
41                                                 "CompilerOptions", "ContentType", "Culture", "Debug",
42                                                 "Description", "EnableSessionState", "EnableViewState",
43                                                 "EnableViewStateMac", "ErrorPage", "Explicit",
44                                                 "Inherits", "Language", "LCID", "ResponseEncoding",
45                                                 "Src", "SmartNavigation", "Strict", "Trace",
46                                                 "TraceMode", "Transaction", "UICulture",
47                                                 "WarningLevel", "CodeBehind" , "ValidateRequest" };
48
49                 static string [] control_atts = { "AutoEventWireup", "ClassName", "CompilerOptions",
50                                                   "Debug", "Description", "EnableViewState",
51                                                   "Explicit", "Inherits", "Language", "Strict", "Src",
52                                                   "WarningLevel", "CodeBehind", "TargetSchema" };
53
54                 static string [] import_atts = { "namespace" };
55                 static string [] implements_atts = { "interface" };
56                 static string [] assembly_atts = { "name", "src" };
57                 static string [] register_atts = { "tagprefix", "tagname", "Namespace", "Src", "Assembly" };
58
59                 static string [] outputcache_atts = { "Duration", "Location", "VaryByControl", 
60                                                       "VaryByCustom", "VaryByHeader", "VaryByParam" };
61
62                 static string [] reference_atts = { "page", "control" };
63
64                 static string [] webservice_atts = { "class", "codebehind", "debug", "language" };
65
66                 static string [] application_atts = { "description", "inherits", "codebehind" };
67
68                 static Directive ()
69                 {
70                         InitHash ();
71                 }
72                 
73                 private static void InitHash ()
74                 {
75                         CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider ();
76                         CaseInsensitiveComparer comparer =  new CaseInsensitiveComparer ();
77
78                         directivesHash = new Hashtable (provider, comparer); 
79
80                         // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
81                         Hashtable valid_attributes = new Hashtable (provider, comparer);
82                         foreach (string att in page_atts) valid_attributes.Add (att, null);
83                         directivesHash.Add ("PAGE", valid_attributes);
84
85                         valid_attributes = new Hashtable (provider, comparer);
86                         foreach (string att in control_atts) valid_attributes.Add (att, null);
87                         directivesHash.Add ("CONTROL", valid_attributes);
88
89                         valid_attributes = new Hashtable (provider, comparer);
90                         foreach (string att in import_atts) valid_attributes.Add (att, null);
91                         directivesHash.Add ("IMPORT", valid_attributes);
92
93                         valid_attributes = new Hashtable (provider, comparer);
94                         foreach (string att in implements_atts) valid_attributes.Add (att, null);
95                         directivesHash.Add ("IMPLEMENTS", valid_attributes);
96
97                         valid_attributes = new Hashtable (provider, comparer);
98                         foreach (string att in register_atts) valid_attributes.Add (att, null);
99                         directivesHash.Add ("REGISTER", valid_attributes);
100
101                         valid_attributes = new Hashtable (provider, comparer);
102                         foreach (string att in assembly_atts) valid_attributes.Add (att, null);
103                         directivesHash.Add ("ASSEMBLY", valid_attributes);
104
105                         valid_attributes = new Hashtable (provider, comparer);
106                         foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
107                         directivesHash.Add ("OUTPUTCACHE", valid_attributes);
108
109                         valid_attributes = new Hashtable (provider, comparer);
110                         foreach (string att in reference_atts) valid_attributes.Add (att, null);
111                         directivesHash.Add ("REFERENCE", valid_attributes);
112
113                         valid_attributes = new Hashtable (provider, comparer);
114                         foreach (string att in webservice_atts) valid_attributes.Add (att, null);
115                         directivesHash.Add ("WEBSERVICE", valid_attributes);
116
117                         valid_attributes = new Hashtable (provider, comparer);
118                         // same attributes as webservice
119                         foreach (string att in webservice_atts) valid_attributes.Add (att, null);
120                         directivesHash.Add ("WEBHANDLER", valid_attributes);
121
122                         valid_attributes = new Hashtable (provider, comparer);
123                         foreach (string att in application_atts) valid_attributes.Add (att, null);
124                         directivesHash.Add ("APPLICATION", valid_attributes);
125
126 #if NET_2_0
127                         valid_attributes = new Hashtable (provider, comparer);
128                         foreach (string att in control_atts) valid_attributes.Add (att, null);
129                         directivesHash.Add ("MASTER", valid_attributes);
130 #endif
131                 }
132                 
133                 private Directive () { }
134
135                 public static bool IsDirective (string id)
136                 {
137                         return directivesHash.Contains (id);
138                 }
139         }
140 }
141