ThemeDirectoryBuildProvider.cs 4.0 KB

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