Do not skip comments, just pluck expressions/tags from within them
[mono.git] / mcs / class / System.Web / System.Web.Compilation / ThemeDirectoryBuildProvider.cs
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 //
10
11 //
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.
30 //
31 #if NET_2_0
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;
40
41 namespace System.Web.Compilation
42 {
43         internal class ThemeDirectoryBuildProvider : TemplateBuildProvider
44         {
45                 public ThemeDirectoryBuildProvider ()
46                 {
47                 }
48
49                 protected override void OverrideAssemblyPrefix (TemplateParser parser, AssemblyBuilder assemblyBuilder)
50                 {
51                         if (parser == null || assemblyBuilder == null)
52                                 return;
53
54                         string newPrefix = assemblyBuilder.OutputFilesPrefix + parser.ClassName + ".";
55                         assemblyBuilder.OutputFilesPrefix = newPrefix;
56                 }
57                 
58                 protected override BaseCompiler CreateCompiler (TemplateParser parser)
59                 {
60                         return new PageThemeCompiler (parser as PageThemeParser);
61                 }
62                 
63                 protected override TemplateParser CreateParser (VirtualPath virtualPath, string inputFile, TextReader reader, HttpContext context)
64                 {
65                         return CreateParser (virtualPath, inputFile, context);
66                 }
67
68                 protected override TemplateParser CreateParser (VirtualPath virtualPath, string inputFile, HttpContext context)
69                 {
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."));
74
75                         PageThemeParser ptp = new PageThemeParser (virtualPath, context);
76                         
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]);
82                         }
83                         ptp.LinkedStyleSheets = css_urls;
84                         
85                         AspComponentFoundry shared_foundry = new AspComponentFoundry ();
86                         ptp.RootBuilder = new RootBuilder ();
87
88                         string [] skin_files = Directory.GetFiles (physicalPath, "*.skin");
89                         string skin_file_url;
90                         AspGenerator generator;
91                         
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);
95
96                                 ptp.AddDependency (skin_file_url);
97                                 generator = new AspGenerator (ptfp, shared_foundry);
98                                 generator.Parse ();
99
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);
105                                         }
106
107                                 foreach (string ass in ptfp.Assemblies)
108                                         if (!ptp.Assemblies.Contains (ass))
109                                                 ptp.AddAssemblyByFileName (ass);
110                         }
111
112                         return ptp;
113                 }
114
115                 protected override bool IsDirectoryBuilder {
116                         get { return true; }
117                 }
118         }
119 }
120 #endif