Directive.cs 5.6 KB

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