2 // System.Web.Compilation.TemplateBuildProvider
5 // Chris Toshok (toshok@ximian.com)
6 // Marek Habersack (mhabersack@novell.com)
8 // (C) 2008 Novell, Inc
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
34 using System
.CodeDom
.Compiler
;
35 using System
.Collections
;
37 using System
.Reflection
;
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)
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");
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
);
100 if (ptfp
.RootBuilder
.Children
!= null)
101 foreach (object o
in ptfp
.RootBuilder
.Children
) {
102 if (!(o
is ControlBuilder
))
104 ptp
.RootBuilder
.AppendSubBuilder ((ControlBuilder
)o
);
107 foreach (string ass
in ptfp
.Assemblies
)
108 if (!ptp
.Assemblies
.Contains (ass
))
109 ptp
.AddAssemblyByFileName (ass
);
115 protected override bool IsDirectoryBuilder
{