Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System.Web / System.Web.UI / UserControlParser.cs
index 222a0b6dd1559c217891d5b4a1ea29d771f7c4f6..b93e19fb57a74edfa84275451e6cc3357057512b 100644 (file)
@@ -29,6 +29,7 @@
 //
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using System.Web;
 using System.Web.Compilation;
@@ -38,61 +39,139 @@ namespace System.Web.UI
 {
        internal class UserControlParser : TemplateControlParser
        {
-               internal UserControlParser (string virtualPath, string inputFile, HttpContext context)
+               string masterPage;
+#if NET_4_0
+               string providerName;
+#endif
+               internal UserControlParser (VirtualPath virtualPath, string inputFile, HttpContext context)
                        : this (virtualPath, inputFile, context, null)
                {
                }
 
-               internal UserControlParser (string virtualPath, string inputFile, ArrayList deps, HttpContext context)
+               internal UserControlParser (VirtualPath virtualPath, string inputFile, List <string> deps, HttpContext context)
                        : this (virtualPath, inputFile, context, null)
                {
                        this.Dependencies = deps;
                }
-               
-               internal UserControlParser (string virtualPath, string inputFile, HttpContext context, string type)
+
+               internal UserControlParser (VirtualPath virtualPath, string inputFile, HttpContext context, string type)
                {
-                       if (type == null) type = PagesConfig.UserControlBaseType;
+                       VirtualPath = virtualPath;
                        Context = context;
-                       BaseVirtualDir = UrlUtils.GetDirectory (virtualPath);
+                       BaseVirtualDir = virtualPath.DirectoryNoNormalize;
                        InputFile = inputFile;
                        SetBaseType (type);
                        AddApplicationAssembly ();
+                       LoadConfigDefaults ();
+               }
+
+               internal UserControlParser (VirtualPath virtualPath, TextReader reader, HttpContext context)
+                       : this (virtualPath, null, reader, context)
+               {
+               }
+               
+               internal UserControlParser (VirtualPath virtualPath, string inputFile, TextReader reader, HttpContext context)
+               {
+                       VirtualPath = virtualPath;
+                       Context = context;
+                       BaseVirtualDir = virtualPath.DirectoryNoNormalize;
+                       
+                       if (String.IsNullOrEmpty (inputFile))
+                               InputFile = virtualPath.PhysicalPath;
+                       else
+                               InputFile = inputFile;
+                       
+                       Reader = reader;
+                       SetBaseType (null);
+                       AddApplicationAssembly ();
+                       LoadConfigDefaults ();
+               }
+
+               internal UserControlParser (TextReader reader, int? uniqueSuffix, HttpContext context)
+               {
+                       Context = context;
+
+                       string fpath = context.Request.FilePath;
+                       VirtualPath = new VirtualPath (fpath);
+                       BaseVirtualDir = VirtualPathUtility.GetDirectory (fpath, false);
+
+                       // We're probably being called by ParseControl - let's use the requested
+                       // control's path plus unique suffix as our input file, since that's the
+                       // context we're being invoked from.
+                       InputFile = VirtualPathUtility.GetFileName (fpath) + "#" + (uniqueSuffix != null ? ((int)uniqueSuffix).ToString ("x") : "0");
+                       Reader = reader;
+                       SetBaseType (null);
+                       AddApplicationAssembly ();
+                       LoadConfigDefaults ();
+               }               
+
+               internal static Type GetCompiledType (TextReader reader, int? inputHashCode, HttpContext context)
+               {
+                       UserControlParser ucp = new UserControlParser (reader, inputHashCode, context);
+                       return ucp.CompileIntoType ();
                }
                
-               internal static Type GetCompiledType (string virtualPath, string inputFile, ArrayList deps, HttpContext context)
+               internal static Type GetCompiledType (string virtualPath, string inputFile, List <string> deps, HttpContext context)
                {
-                       UserControlParser ucp = new UserControlParser (virtualPath, inputFile, deps, context);
+                       UserControlParser ucp = new UserControlParser (new VirtualPath (virtualPath), inputFile, deps, context);
+
                        return ucp.CompileIntoType ();
                }
 
                public static Type GetCompiledType (string virtualPath, string inputFile, HttpContext context)
                {
-                       UserControlParser ucp = new UserControlParser (virtualPath, inputFile, context);
+                       UserControlParser ucp = new UserControlParser (new VirtualPath (virtualPath), inputFile, context);
+
                        return ucp.CompileIntoType ();
                }
 
-               protected override Type CompileIntoType ()
+               internal override Type CompileIntoType ()
                {
                        AspGenerator generator = new AspGenerator (this);
                        return generator.GetCompiledType ();
                }
 
-               internal override void ProcessMainAttributes (Hashtable atts)
+               internal override void ProcessMainAttributes (IDictionary atts)
                {
+                       masterPage = GetString (atts, "MasterPageFile", null);
+                       if (masterPage != null)
+                               AddDependency (masterPage);
+
                        base.ProcessMainAttributes (atts);
                }
-               
-               internal override Type DefaultBaseType {
-                       get { return typeof (UserControl); }
+#if NET_4_0
+               internal override void ProcessOutputCacheAttributes (IDictionary atts)
+               {
+                       providerName = GetString (atts, "ProviderName", null);
+                       base.ProcessOutputCacheAttributes (atts);
                }
 
+               internal override Type DefaultBaseType {
+                       get {
+                               Type ret = PageParser.DefaultUserControlBaseType;
+                               if (ret == null)
+                                       return base.DefaultBaseType;
+
+                               return ret;
+                       }
+               }
+#endif
                internal override string DefaultBaseTypeName {
-                       get { return "System.Web.UI.UserControl"; }
+                       get { return PagesConfig.UserControlBaseType; }
                }
 
                internal override string DefaultDirectiveName {
                        get { return "control"; }
                }
+
+               internal string MasterPageFile {
+                       get { return masterPage; }
+               }
+#if NET_4_0
+               internal string ProviderName {
+                       get { return providerName; }
+               }
+#endif
        }
 }