Directive.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Web.Compilation.Directive
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.Globalization;
  32. using System.Web.Util;
  33. namespace System.Web.Compilation
  34. {
  35. sealed class Directive
  36. {
  37. static Hashtable directivesHash;
  38. static string [] page_atts = { "AspCompat", "AutoEventWireup", "Buffer",
  39. "ClassName", "ClientTarget", "CodePage",
  40. "CompilerOptions", "ContentType", "Culture", "Debug",
  41. "Description",
  42. "EnableEventValidation", "MaintainScrollPositionOnPostBack",
  43. "EnableSessionState", "EnableViewState",
  44. "EnableViewStateMac", "ErrorPage", "Explicit",
  45. "Inherits", "Language", "LCID", "ResponseEncoding",
  46. "Src", "SmartNavigation", "Strict", "Trace",
  47. "TraceMode", "Transaction", "UICulture",
  48. "WarningLevel", "CodeBehind" , "ValidateRequest" };
  49. static string [] control_atts = { "AutoEventWireup", "ClassName", "CompilerOptions",
  50. "Debug", "Description", "EnableViewState",
  51. "Explicit", "Inherits", "Language", "Strict", "Src",
  52. "WarningLevel", "CodeBehind", "TargetSchema", "LinePragmas" };
  53. static string [] import_atts = { "namespace" };
  54. static string [] implements_atts = { "interface" };
  55. static string [] assembly_atts = { "name", "src" };
  56. static string [] register_atts = { "tagprefix", "tagname", "Namespace", "Src", "Assembly" };
  57. static string [] outputcache_atts = { "Duration", "Location", "VaryByControl",
  58. "VaryByCustom", "VaryByHeader", "VaryByParam" };
  59. static string [] reference_atts = { "page", "control" };
  60. static string [] webservice_atts = { "class", "codebehind", "debug", "language" };
  61. static string [] application_atts = { "description", "inherits", "codebehind" };
  62. static string [] mastertype_atts = { "virtualpath", "typename" };
  63. static string [] previouspagetype_atts = { "virtualpath", "typename" };
  64. static Directive ()
  65. {
  66. InitHash ();
  67. }
  68. static void InitHash ()
  69. {
  70. StringComparer comparer = StringComparer.InvariantCultureIgnoreCase;
  71. directivesHash = new Hashtable (comparer);
  72. // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
  73. Hashtable valid_attributes = new Hashtable (comparer);
  74. foreach (string att in page_atts) valid_attributes.Add (att, null);
  75. directivesHash.Add ("PAGE", valid_attributes);
  76. valid_attributes = new Hashtable (comparer);
  77. foreach (string att in control_atts) valid_attributes.Add (att, null);
  78. directivesHash.Add ("CONTROL", valid_attributes);
  79. valid_attributes = new Hashtable (comparer);
  80. foreach (string att in import_atts) valid_attributes.Add (att, null);
  81. directivesHash.Add ("IMPORT", valid_attributes);
  82. valid_attributes = new Hashtable (comparer);
  83. foreach (string att in implements_atts) valid_attributes.Add (att, null);
  84. directivesHash.Add ("IMPLEMENTS", valid_attributes);
  85. valid_attributes = new Hashtable (comparer);
  86. foreach (string att in register_atts) valid_attributes.Add (att, null);
  87. directivesHash.Add ("REGISTER", valid_attributes);
  88. valid_attributes = new Hashtable (comparer);
  89. foreach (string att in assembly_atts) valid_attributes.Add (att, null);
  90. directivesHash.Add ("ASSEMBLY", valid_attributes);
  91. valid_attributes = new Hashtable (comparer);
  92. foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
  93. directivesHash.Add ("OUTPUTCACHE", valid_attributes);
  94. valid_attributes = new Hashtable (comparer);
  95. foreach (string att in reference_atts) valid_attributes.Add (att, null);
  96. directivesHash.Add ("REFERENCE", valid_attributes);
  97. valid_attributes = new Hashtable (comparer);
  98. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  99. directivesHash.Add ("WEBSERVICE", valid_attributes);
  100. valid_attributes = new Hashtable (comparer);
  101. // same attributes as webservice
  102. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  103. directivesHash.Add ("WEBHANDLER", valid_attributes);
  104. valid_attributes = new Hashtable (comparer);
  105. foreach (string att in application_atts) valid_attributes.Add (att, null);
  106. directivesHash.Add ("APPLICATION", valid_attributes);
  107. valid_attributes = new Hashtable (comparer);
  108. foreach (string att in mastertype_atts) valid_attributes.Add (att, null);
  109. directivesHash.Add ("MASTERTYPE", valid_attributes);
  110. valid_attributes = new Hashtable (comparer);
  111. foreach (string att in control_atts) valid_attributes.Add (att, null);
  112. directivesHash.Add ("MASTER", valid_attributes);
  113. valid_attributes = new Hashtable (comparer);
  114. foreach (string att in previouspagetype_atts) valid_attributes.Add (att, null);
  115. directivesHash.Add ("PREVIOUSPAGETYPE", valid_attributes);
  116. }
  117. Directive () { }
  118. public static bool IsDirective (string id)
  119. {
  120. return directivesHash.Contains (id);
  121. }
  122. }
  123. }