ThemeDirectoryBuildProvider.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // System.Web.Compilation.TemplateBuildProvider
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. // Marek Habersack ([email protected])
  7. //
  8. // (C) 2008 Novell, Inc
  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. #if NET_2_0
  31. using System;
  32. using System.CodeDom;
  33. using System.CodeDom.Compiler;
  34. using System.Collections;
  35. using System.IO;
  36. using System.Reflection;
  37. using System.Web;
  38. using System.Web.UI;
  39. namespace System.Web.Compilation
  40. {
  41. internal class ThemeDirectoryBuildProvider : TemplateBuildProvider
  42. {
  43. public ThemeDirectoryBuildProvider ()
  44. {
  45. }
  46. protected override void OverrideAssemblyPrefix (TemplateParser parser, AssemblyBuilder assemblyBuilder)
  47. {
  48. if (parser == null || assemblyBuilder == null)
  49. return;
  50. string newPrefix = assemblyBuilder.OutputFilesPrefix + parser.ClassName + ".";
  51. assemblyBuilder.OutputFilesPrefix = newPrefix;
  52. }
  53. protected override BaseCompiler CreateCompiler (TemplateParser parser)
  54. {
  55. return new PageThemeCompiler (parser as PageThemeParser);
  56. }
  57. protected override TemplateParser CreateParser (string virtualPath, string inputFile, TextReader reader, HttpContext context)
  58. {
  59. return CreateParser (virtualPath, inputFile, context);
  60. }
  61. protected override TemplateParser CreateParser (string virtualPath, string inputFile, HttpContext context)
  62. {
  63. string vp = VirtualPathUtility.AppendTrailingSlash (virtualPath);
  64. string physicalPath = context.Request.MapPath (vp);
  65. if (!Directory.Exists (physicalPath))
  66. throw new HttpException (String.Concat ("Theme '", vp ,"' cannot be found in the application or global theme directories."));
  67. PageThemeParser ptp = new PageThemeParser (vp, context);
  68. string[] css_files = Directory.GetFiles (physicalPath, "*.css");
  69. string[] css_urls = new string [css_files.Length];
  70. for (int i = 0; i < css_files.Length; i++) {
  71. css_urls [i] = VirtualPathUtility.Combine (vp, Path.GetFileName (css_files [i]));
  72. ptp.AddDependency (css_urls [i]);
  73. }
  74. ptp.LinkedStyleSheets = css_urls;
  75. AspComponentFoundry shared_foundry = new AspComponentFoundry ();
  76. ptp.RootBuilder = new RootBuilder ();
  77. string [] skin_files = Directory.GetFiles (physicalPath, "*.skin");
  78. string skin_file_url;
  79. AspGenerator generator;
  80. foreach (string skin_file in skin_files) {
  81. skin_file_url = VirtualPathUtility.Combine (vp, Path.GetFileName (skin_file));
  82. PageThemeFileParser ptfp = new PageThemeFileParser (skin_file_url, skin_file, context);
  83. ptp.AddDependency (skin_file_url);
  84. generator = new AspGenerator (ptfp);
  85. ptfp.RootBuilder.Foundry = shared_foundry;
  86. generator.Parse ();
  87. if (ptfp.RootBuilder.Children != null)
  88. foreach (object o in ptfp.RootBuilder.Children) {
  89. if (!(o is ControlBuilder))
  90. continue;
  91. ptp.RootBuilder.AppendSubBuilder ((ControlBuilder)o);
  92. }
  93. foreach (string ass in ptfp.Assemblies)
  94. if (!ptp.Assemblies.Contains (ass))
  95. ptp.AddAssemblyByFileName (ass);
  96. }
  97. return ptp;
  98. }
  99. protected override bool IsDirectoryBuilder {
  100. get { return true; }
  101. }
  102. }
  103. }
  104. #endif