UserControlParser.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // System.Web.UI.UserControlParser
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,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.IO;
  32. using System.Web;
  33. using System.Web.Compilation;
  34. using System.Web.Util;
  35. namespace System.Web.UI
  36. {
  37. internal class UserControlParser : TemplateControlParser
  38. {
  39. #if NET_2_0
  40. string masterPage;
  41. #endif
  42. internal UserControlParser (string virtualPath, string inputFile, HttpContext context)
  43. : this (virtualPath, inputFile, context, null)
  44. {
  45. }
  46. internal UserControlParser (string virtualPath, string inputFile, ArrayList deps, HttpContext context)
  47. : this (virtualPath, inputFile, context, null)
  48. {
  49. this.Dependencies = deps;
  50. }
  51. internal UserControlParser (string virtualPath, string inputFile, HttpContext context, string type)
  52. {
  53. if (type == null) type = PagesConfig.UserControlBaseType;
  54. Context = context;
  55. BaseVirtualDir = UrlUtils.GetDirectory (virtualPath);
  56. InputFile = inputFile;
  57. SetBaseType (type);
  58. AddApplicationAssembly ();
  59. }
  60. #if NET_2_0
  61. internal UserControlParser (string virtualPath, TextReader reader, HttpContext context)
  62. {
  63. Context = context;
  64. BaseVirtualDir = UrlUtils.GetDirectory (virtualPath);
  65. Reader = reader;
  66. SetBaseType (PagesConfig.UserControlBaseType);
  67. AddApplicationAssembly ();
  68. }
  69. #endif
  70. internal static Type GetCompiledType (string virtualPath, string inputFile, ArrayList deps, HttpContext context)
  71. {
  72. UserControlParser ucp = new UserControlParser (virtualPath, inputFile, deps, context);
  73. return ucp.CompileIntoType ();
  74. }
  75. public static Type GetCompiledType (string virtualPath, string inputFile, HttpContext context)
  76. {
  77. UserControlParser ucp = new UserControlParser (virtualPath, inputFile, context);
  78. return ucp.CompileIntoType ();
  79. }
  80. protected override Type CompileIntoType ()
  81. {
  82. AspGenerator generator = new AspGenerator (this);
  83. return generator.GetCompiledType ();
  84. }
  85. internal override void ProcessMainAttributes (Hashtable atts)
  86. {
  87. #if NET_2_0
  88. masterPage = GetString (atts, "MasterPageFile", null);
  89. if (masterPage != null) {
  90. // Make sure the page exists
  91. if (masterPage != null) {
  92. string path = MapPath (masterPage);
  93. MasterPageParser.GetCompiledMasterType (masterPage, path, HttpContext.Current);
  94. AddDependency (path);
  95. }
  96. }
  97. #endif
  98. base.ProcessMainAttributes (atts);
  99. }
  100. internal override Type DefaultBaseType {
  101. get { return typeof (UserControl); }
  102. }
  103. internal override string DefaultBaseTypeName {
  104. get { return "System.Web.UI.UserControl"; }
  105. }
  106. internal override string DefaultDirectiveName {
  107. get { return "control"; }
  108. }
  109. #if NET_2_0
  110. internal string MasterPageFile {
  111. get { return masterPage; }
  112. }
  113. #endif
  114. }
  115. }