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