2010-03-02 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Web / System.Web.Compilation / ThemeDirectoryBuildProvider.cs
blob4c733e16b27220bb4245ada97cd1f8307b8ae6d6
1 //
2 // System.Web.Compilation.TemplateBuildProvider
3 //
4 // Authors:
5 // Chris Toshok (toshok@ximian.com)
6 // Marek Habersack (mhabersack@novell.com)
7 //
8 // (C) 2008 Novell, Inc
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.CodeDom;
34 using System.CodeDom.Compiler;
35 using System.Collections;
36 using System.IO;
37 using System.Reflection;
38 using System.Web;
39 using System.Web.UI;
41 namespace System.Web.Compilation
43 internal class ThemeDirectoryBuildProvider : TemplateBuildProvider
45 public ThemeDirectoryBuildProvider ()
49 protected override void OverrideAssemblyPrefix (TemplateParser parser, AssemblyBuilder assemblyBuilder)
51 if (parser == null || assemblyBuilder == null)
52 return;
54 string newPrefix = assemblyBuilder.OutputFilesPrefix + parser.ClassName + ".";
55 assemblyBuilder.OutputFilesPrefix = newPrefix;
58 protected override BaseCompiler CreateCompiler (TemplateParser parser)
60 return new PageThemeCompiler (parser as PageThemeParser);
63 protected override TemplateParser CreateParser (VirtualPath virtualPath, string inputFile, TextReader reader, HttpContext context)
65 return CreateParser (virtualPath, inputFile, context);
68 protected override TemplateParser CreateParser (VirtualPath virtualPath, string inputFile, HttpContext context)
70 string vp = VirtualPathUtility.AppendTrailingSlash (virtualPath.Original);
71 string physicalPath = virtualPath.PhysicalPath;
72 if (!Directory.Exists (physicalPath))
73 throw new HttpException (String.Concat ("Theme '", virtualPath.Original ,"' cannot be found in the application or global theme directories."));
75 PageThemeParser ptp = new PageThemeParser (virtualPath, context);
77 string[] css_files = Directory.GetFiles (physicalPath, "*.css");
78 string[] css_urls = new string [css_files.Length];
79 for (int i = 0; i < css_files.Length; i++) {
80 css_urls [i] = VirtualPathUtility.Combine (vp, Path.GetFileName (css_files [i]));
81 ptp.AddDependency (css_urls [i]);
83 ptp.LinkedStyleSheets = css_urls;
85 AspComponentFoundry shared_foundry = new AspComponentFoundry ();
86 ptp.RootBuilder = new RootBuilder ();
88 string [] skin_files = Directory.GetFiles (physicalPath, "*.skin");
89 string skin_file_url;
90 AspGenerator generator;
92 foreach (string skin_file in skin_files) {
93 skin_file_url = VirtualPathUtility.Combine (vp, Path.GetFileName (skin_file));
94 PageThemeFileParser ptfp = new PageThemeFileParser (new VirtualPath (skin_file_url), skin_file, context);
96 ptp.AddDependency (skin_file_url);
97 generator = new AspGenerator (ptfp, shared_foundry);
98 generator.Parse ();
100 if (ptfp.RootBuilder.Children != null)
101 foreach (object o in ptfp.RootBuilder.Children) {
102 if (!(o is ControlBuilder))
103 continue;
104 ptp.RootBuilder.AppendSubBuilder ((ControlBuilder)o);
107 foreach (string ass in ptfp.Assemblies)
108 if (!ptp.Assemblies.Contains (ass))
109 ptp.AddAssemblyByFileName (ass);
112 return ptp;
115 protected override bool IsDirectoryBuilder {
116 get { return true; }