diff options
author | Chris Toshok <toshok@novell.com> | 2006-03-08 01:00:21 +0300 |
---|---|---|
committer | Chris Toshok <toshok@novell.com> | 2006-03-08 01:00:21 +0300 |
commit | f28eecd2e195e440c7b593a908ac4a2c0005a41f (patch) | |
tree | 2e6069b58e1066f92068d7dc2941dd7c6d977779 /mcs | |
parent | ffcc362a420d56d3f0e050a8f98a16c8c72d2334 (diff) |
2006-03-07 Chris Toshok <toshok@ximian.com>
* ThemeDirectoryCompiler.cs: new file.
* PageThemeCompiler.cs: new file.
svn path=/trunk/mcs/; revision=57671
Diffstat (limited to 'mcs')
3 files changed, 326 insertions, 0 deletions
diff --git a/mcs/class/System.Web/System.Web.Compilation/ChangeLog b/mcs/class/System.Web/System.Web.Compilation/ChangeLog index 5cd910ed575..b400d897e24 100644 --- a/mcs/class/System.Web/System.Web.Compilation/ChangeLog +++ b/mcs/class/System.Web/System.Web.Compilation/ChangeLog @@ -1,5 +1,11 @@ 2006-03-07 Chris Toshok <toshok@ximian.com> + * ThemeDirectoryCompiler.cs: new file. + + * PageThemeCompiler.cs: new file. + +2006-03-07 Chris Toshok <toshok@ximian.com> + * BaseCompiler.cs: fix typo in "initialize" in multiple places. (Init): move the CreateMethods call here. diff --git a/mcs/class/System.Web/System.Web.Compilation/PageThemeCompiler.cs b/mcs/class/System.Web/System.Web.Compilation/PageThemeCompiler.cs new file mode 100644 index 00000000000..3e1ec760247 --- /dev/null +++ b/mcs/class/System.Web/System.Web.Compilation/PageThemeCompiler.cs @@ -0,0 +1,236 @@ +// +// System.Web.Compilation.PageThemeCompiler +// +// Authors: +// Chris Toshok (toshok@ximian.com) +// +// (C) 2006 Novell, Inc (http://www.novell.com/) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#if NET_2_0 + +using System; +using System.CodeDom; +using System.Collections; +using System.Collections.Specialized; +using System.Reflection; +using System.Text; +using System.Web.UI; +using System.Web.SessionState; +using System.Web.Util; + +namespace System.Web.Compilation +{ + class PageThemeCompiler : TemplateControlCompiler + { + PageThemeParser parser; + + public PageThemeCompiler (PageThemeParser parser) + : base (parser) + { + this.parser = parser; + } + + protected internal override void CreateMethods () + { + CodeMemberField fld; + CodeMemberProperty prop; + + /* override the following abstract PageTheme properties: + protected abstract string AppRelativeTemplateSourceDirectory { get; } + protected abstract IDictionary ControlSkins { get; } + protected abstract string[] LinkedStyleSheets { get; } + */ + + /* ControlSkins */ + fld = new CodeMemberField (typeof (HybridDictionary), "__controlSkins"); + fld.Attributes = MemberAttributes.Private; + fld.InitExpression = new CodeObjectCreateExpression (typeof (HybridDictionary)); + mainClass.Members.Add (fld); + + prop = new CodeMemberProperty (); + prop.Name = "ControlSkins"; + prop.Attributes = MemberAttributes.Family | MemberAttributes.Override; + prop.Type = new CodeTypeReference (typeof (IDictionary)); + prop.GetStatements.Add (new CodeMethodReturnStatement (new CodeVariableReferenceExpression ("__controlSkins"))); + mainClass.Members.Add (prop); + + /* LinkedStyleSheets */ + fld = new CodeMemberField (typeof (string[]), "__linkedStyleSheets"); + fld.Attributes = MemberAttributes.Private; + fld.InitExpression = new CodePrimitiveExpression (null); + mainClass.Members.Add (fld); + + prop = new CodeMemberProperty (); + prop.Name = "LinkedStyleSheets"; + prop.Attributes = MemberAttributes.Family | MemberAttributes.Override; + prop.Type = new CodeTypeReference (typeof (string[])); + prop.GetStatements.Add (new CodeMethodReturnStatement (new CodeVariableReferenceExpression ("__linkedStyleSheets"))); + mainClass.Members.Add (prop); + + /* AppRelativeTemplateSourceDirectory */ + prop = new CodeMemberProperty (); + prop.Name = "AppRelativeTemplateSourceDirectory"; + prop.Attributes = MemberAttributes.Family | MemberAttributes.Override; + prop.Type = new CodeTypeReference (typeof (string)); + prop.GetStatements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (parser.BaseVirtualDir))); + mainClass.Members.Add (prop); + + ControlBuilder builder = parser.RootBuilder; + if (builder.Children != null) { + foreach (object o in builder.Children) { + if (! (o is ControlBuilder)) + continue; + + ControlBuilder b = (ControlBuilder) o; + CreateControlSkinMethod (b); + } + } + } + + void CreateControlSkinMethod (ControlBuilder builder) + { + EnsureID (builder); + + CodeMemberMethod method = new CodeMemberMethod (); + method.Name = "__BuildControl_" + builder.ID; + method.Parameters.Add (new CodeParameterDeclarationExpression (typeof (Control), "ctrl")); + + mainClass.Members.Add (method); + + builder.method = method; + builder.methodStatements = method.Statements; + + method.ReturnType = new CodeTypeReference (typeof (Control)); + + // _ctrl = ($controlType)(ctrl); + // + CodeCastExpression castExpr = new CodeCastExpression (builder.ControlType, new CodeVariableReferenceExpression ("ctrl")); + + method.Statements.Add (new CodeVariableDeclarationStatement (builder.ControlType, "__ctrl")); + CodeAssignStatement assign = new CodeAssignStatement (); + assign.Left = ctrlVar; + assign.Right = castExpr; + method.Statements.Add (assign); + + CreateAssignStatementsFromAttributes (builder); + + if (builder.Children != null) { + foreach (object o in builder.Children) { + if (! (o is ControlBuilder)) + continue; + + ControlBuilder b = (ControlBuilder) o; + + Console.WriteLine ("b.Type == {0}, b.ControlType = {0}", b.GetType(), b.ControlType); + + if (b is CollectionBuilder) { + /* emit a prop.Clear call before populating the collection */ + CodePropertyReferenceExpression items = new CodePropertyReferenceExpression (ctrlVar, + "Items"); + method.Statements.Add (new CodeMethodInvokeExpression (items, "Clear")); + } + + CreateControlTree (b, false, builder.ChildrenAsProperties); + AddChildCall (builder, b); + } + } + + builder.method.Statements.Add (new CodeMethodReturnStatement (ctrlVar)); + } + + protected override void AddClassAttributes () + { + base.AddClassAttributes (); + } + + protected override void CreateStaticFields () + { + base.CreateStaticFields (); + ControlBuilder builder = parser.RootBuilder; + + if (builder.Children != null) { + foreach (object o in builder.Children) { + if (o is string) /* literal stuff gets ignored */ + continue; + + ControlBuilder b = (ControlBuilder) o; + + EnsureID (b); + + string id = b.ID; + string skinId = b.attribs["skinid"] as string; + Type controlType = b.ControlType; + + if (skinId == null) skinId = ""; + + // private static object __BuildControl__$id_skinKey = System.Web.UI.PageTheme.CreateSkinKey(typeof($controlType), "$skinID") + // + CodeMemberField fld = new CodeMemberField (typeof (object), "__BuildControl_" + id + "_skinKey"); + fld.Attributes = MemberAttributes.Private | MemberAttributes.Static; + fld.InitExpression = new CodeMethodInvokeExpression (new CodeTypeReferenceExpression (typeof (PageTheme)), + "CreateSkinKey", + new CodeTypeOfExpression (controlType), + new CodePrimitiveExpression (skinId)); + + mainClass.Members.Add (fld); + } + } + } + + protected override void CreateConstructor (CodeStatementCollection localVars, + CodeStatementCollection trueStmt) + { + ControlBuilder builder = parser.RootBuilder; + + if (builder.Children != null) { + foreach (object o in builder.Children) { + if (o is string) /* literal stuff gets ignored */ + continue; + + ControlBuilder b = (ControlBuilder) o; + + string id = b.ID; + Type controlType = b.ControlType; + + if (localVars == null) + localVars = new CodeStatementCollection (); + + // this.__controlSkins[__BuildControl_$id_skinKey] = new System.Web.UI.ControlSkin(typeof ($controlType), this.__BuildControl__$id) + // + localVars.Add (new CodeAssignStatement (new CodeIndexerExpression (new CodePropertyReferenceExpression (thisRef, "__controlSkins"), + new CodeVariableReferenceExpression ("__BuildControl_" + id + "_skinKey")), + new CodeObjectCreateExpression (typeof (ControlSkin), + new CodeTypeOfExpression (controlType), + new CodeDelegateCreateExpression (new CodeTypeReference (typeof (ControlSkinDelegate)), + thisRef, "__BuildControl_" + id)))); + } + + base.CreateConstructor (localVars, trueStmt); + } + } + } +} + +#endif diff --git a/mcs/class/System.Web/System.Web.Compilation/ThemeDirectoryCompiler.cs b/mcs/class/System.Web/System.Web.Compilation/ThemeDirectoryCompiler.cs new file mode 100644 index 00000000000..d73ac488c29 --- /dev/null +++ b/mcs/class/System.Web/System.Web.Compilation/ThemeDirectoryCompiler.cs @@ -0,0 +1,84 @@ +// +// System.Web.UI.ThemeDirectoryCompiler +// +// Authors: +// Chris Toshok (toshok@ximian.com) +// +// (C) 2006 Novell, Inc. (http://www.novell.com) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#if NET_2_0 + +using System; +using System.Collections; +using System.IO; +using System.Web; +using System.Web.Compilation; +using System.Web.Util; + +namespace System.Web.UI +{ + internal sealed class ThemeDirectoryCompiler + { + public static Type GetCompiledType (string virtualPath, HttpContext context) + { + /* XXX map the virtual path to a physical path */ + string physicalPath = virtualPath; + string[] skin_files = Directory.GetFiles (physicalPath, "*.skin"); + + PageThemeParser ptp = new PageThemeParser (virtualPath, context); + ptp.RootBuilder = new RootBuilder (); + + for (int i = 0; i < skin_files.Length; i ++) { + PageThemeFileParser ptfp = new PageThemeFileParser (virtualPath + Path.GetFileName (skin_files[i]), + skin_files[i], + context); + + AspGenerator gen = new AspGenerator (ptfp); + gen.Parse (); + + foreach (object o in ptfp.RootBuilder.Children) { + if (!(o is ControlBuilder)) + continue; + ptp.RootBuilder.AppendSubBuilder ((ControlBuilder)o); + } + } + + PageThemeCompiler compiler = new PageThemeCompiler (ptp); + return compiler.GetCompiledType (); + } + + public static PageTheme GetCompiledInstance (string virtualPath, HttpContext context) + { + Type t = ThemeDirectoryCompiler.GetCompiledType (virtualPath, context); + if (t == null) + return null; + + PageTheme pt = (PageTheme)Activator.CreateInstance (t); + return pt; + } + } +} + +#endif |