2 // System.Web.UI.ThemeDirectoryCompiler
5 // Chris Toshok (toshok@ximian.com)
7 // (C) 2006-2009 Novell, Inc. (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
35 using System.Web.Compilation;
36 using System.Web.Util;
38 namespace System.Web.UI
40 sealed class ThemeDirectoryCompiler
42 public static Type GetCompiledType (string theme, HttpContext context)
44 string virtualPath = "~/App_Themes/" + theme + "/";
45 string physicalPath = context.Request.MapPath (virtualPath);
46 if (!Directory.Exists (physicalPath))
47 throw new HttpException (String.Format ("Theme '{0}' cannot be found in the application or global theme directories.", theme));
48 string [] skin_files = Directory.GetFiles (physicalPath, "*.skin");
50 PageThemeParser ptp = new PageThemeParser (new VirtualPath (virtualPath), context);
52 string[] css_files = Directory.GetFiles (physicalPath, "*.css");
53 string[] css_urls = new string[css_files.Length];
54 for (int i = 0; i < css_files.Length; i++) {
55 ptp.AddDependency (css_files [i]);
56 css_urls [i] = virtualPath + Path.GetFileName (css_files [i]);
59 Array.Sort (css_urls, StringComparer.OrdinalIgnoreCase);
60 ptp.LinkedStyleSheets = css_urls;
62 AspComponentFoundry shared_foundry = new AspComponentFoundry ();
63 ptp.RootBuilder = new RootBuilder ();
66 for (int i = 0; i < skin_files.Length; i ++) {
67 skin_file_url = VirtualPathUtility.Combine (virtualPath, Path.GetFileName (skin_files [i]));
68 PageThemeFileParser ptfp = new PageThemeFileParser (new VirtualPath (skin_file_url),
72 ptp.AddDependency (skin_files [i]);
73 AspGenerator gen = new AspGenerator (ptfp);
74 ptfp.RootBuilder.Foundry = shared_foundry;
77 if (ptfp.RootBuilder.Children != null)
78 foreach (object o in ptfp.RootBuilder.Children) {
79 if (!(o is ControlBuilder))
81 ptp.RootBuilder.AppendSubBuilder ((ControlBuilder)o);
84 foreach (string ass in ptfp.Assemblies)
85 if (!ptp.Assemblies.Contains (ass))
86 ptp.AddAssemblyByFileName (ass);
89 PageThemeCompiler compiler = new PageThemeCompiler (ptp);
90 return compiler.GetCompiledType ();
93 public static PageTheme GetCompiledInstance (string theme, HttpContext context)
95 Type t = ThemeDirectoryCompiler.GetCompiledType (theme, context);
99 PageTheme pt = (PageTheme)Activator.CreateInstance (t);