One more changelog
[mono.git] / mcs / class / System.Web / System.Web.UI / PageParser.cs
index f5552e938dee62a0edd8098ebc765308daaee912..0703b24f193e07baa0748c16e5afb647f4b81626 100644 (file)
@@ -5,19 +5,42 @@
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 //
-using System;
+// 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.
+//
+
 using System.Collections;
 using System.Collections.Specialized;
 using System.Globalization;
+using System.Security.Permissions;
 using System.Text;
-using System.Web;
 using System.Web.Compilation;
 using System.Web.Configuration;
 using System.Web.Util;
+using System.IO;
 
 namespace System.Web.UI
 {
+       // CAS - no InheritanceDemand here as the class is sealed
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public sealed class PageParser : TemplateControlParser
        {
                bool enableSessionState = true;
@@ -37,6 +60,15 @@ namespace System.Web.UI
                string clientTarget;
                Type baseType = typeof (Page);
 
+#if NET_2_0
+               string masterPage;
+               Type masterType;
+               string title;
+               string theme;
+               string styleSheetTheme;
+               bool enable_event_validation;
+#endif
+
                public PageParser ()
                {
                }
@@ -50,6 +82,17 @@ namespace System.Web.UI
                        AddApplicationAssembly ();
                }
 
+#if NET_2_0
+               internal PageParser (string virtualPath, TextReader reader, HttpContext context)
+               {
+                       Context = context;
+                       BaseVirtualDir = UrlUtils.GetDirectory (virtualPath);
+                       Reader = reader;
+                       SetBaseType (PagesConfig.PageBaseType);
+                       AddApplicationAssembly ();
+               }
+#endif
+
                public static IHttpHandler GetCompiledPageInstance (string virtualPath,
                                                                    string inputFile, 
                                                                    HttpContext context)
@@ -58,10 +101,16 @@ namespace System.Web.UI
                        IHttpHandler h = (IHttpHandler) pp.GetCompiledInstance ();
                        return h;
                }
-
+               
                internal override void ProcessMainAttributes (Hashtable atts)
                {
-                       string enabless = GetString (atts, "EnableSessionState", PagesConfig.EnableSessionState);
+                       string enabless = GetString (atts, "EnableSessionState",
+#if NET_2_0
+                                                    PagesConfig.EnableSessionState.ToString()
+#else
+                                                    PagesConfig.EnableSessionState
+#endif
+                                                    );
                        if (enabless != null) {
                                readonlySessionState = (String.Compare (enabless, "readonly", true) == 0);
                                if (readonlySessionState == true || String.Compare (enabless, "true", true) == 0) {
@@ -142,12 +191,15 @@ namespace System.Web.UI
                                
                                CultureInfo ci = null;
                                try {
-                                       ci = new CultureInfo (culture);                                 
+#if NET_2_0
+                                       if (!culture.StartsWith ("auto"))
+#endif
+                                               ci = new CultureInfo (culture);
                                } catch {
                                        ThrowParseException ("Unsupported Culture: " + culture);
                                }
 
-                               if (ci.IsNeutralCulture) {
+                               if (ci != null && ci.IsNeutralCulture) {
                                        string suggestedCulture = SuggestCulture (culture);
                                        string fmt = "Culture attribute must be set to a non-neutral Culture.";
                                        if (suggestedCulture != null)
@@ -162,12 +214,15 @@ namespace System.Web.UI
                        if (uiculture != null) {
                                CultureInfo ci = null;
                                try {
-                                       ci = new CultureInfo (uiculture);                                       
+#if NET_2_0
+                                       if (!uiculture.StartsWith ("auto"))
+#endif
+                                               ci = new CultureInfo (uiculture);
                                } catch {
                                        ThrowParseException ("Unsupported Culture: " + uiculture);
                                }
 
-                               if (ci.IsNeutralCulture) {
+                               if (ci != null && ci.IsNeutralCulture) {
                                        string suggestedCulture = SuggestCulture (uiculture);
                                        string fmt = "UICulture attribute must be set to a non-neutral Culture.";
                                        if (suggestedCulture != null)
@@ -178,13 +233,6 @@ namespace System.Web.UI
                                }
                        }
 
-                       TraceConfig traceConfig = (TraceConfig) Context.GetConfig ("system.web/trace");
-                       if (traceConfig != null) {
-                               trace = traceConfig.Enabled;
-                               if (trace)
-                                       haveTrace = true;
-                       }
-
                        string tracestr = GetString (atts, "Trace", null);
                        if (tracestr != null) {
                                haveTrace = true;
@@ -206,17 +254,20 @@ namespace System.Web.UI
                                                        "one of the following values: SortByTime, SortByCategory.");
                        }
 
-                       if (traceConfig != null) {
-                               if (traceConfig.LocalOnly && !Context.Request.IsLocal) {
-                                       haveTrace = false;
-                                       trace = false;
-                               }
-                       }
-                       
                        errorPage = GetString (atts, "ErrorPage", null);
                        validateRequest = GetBool (atts, "ValidateRequest", PagesConfig.ValidateRequest);
                        clientTarget = GetString (atts, "ClientTarget", null);
                        if (clientTarget != null) {
+#if NET_2_0
+                               ClientTargetSection sec = (ClientTargetSection)WebConfigurationManager.GetSection ("system.web/clientTarget");
+                               if (sec.ClientTargets[clientTarget] == null) {
+                                       ThrowParseException (String.Format (
+                                                       "ClientTarget '{0}' is an invalid alias. See the " +
+                                                       "documentation for <clientTarget> config. section.",
+                                                       clientTarget));
+                               }
+                               clientTarget = sec.ClientTargets[clientTarget].UserAgent;
+#else
                                NameValueCollection coll;
                                coll = (NameValueCollection) Context.GetConfig ("system.web/clientTarget");
                                if (coll == null || coll [clientTarget] == null) {
@@ -226,10 +277,24 @@ namespace System.Web.UI
                                                        clientTarget));
                                }
                                clientTarget = (string) coll [clientTarget];
+#endif
                        }
 
                        notBuffer = !GetBool (atts, "Buffer", true);
+                       
+#if NET_2_0
+                       masterPage = GetString (atts, "MasterPageFile", null);
+                       
+                       // Make sure the page exists
+                       if (masterPage != null)
+                               MasterPageParser.GetCompiledMasterType (masterPage, MapPath (masterPage), HttpContext.Current);
 
+                       title = GetString(atts, "Title", null);
+
+                       theme = GetString (atts, "Theme", null);
+                       styleSheetTheme = GetString (atts, "StyleSheetTheme", null);
+                       enable_event_validation = GetBool (atts, "EnableEventValidation", true);
+#endif
                        // Ignored by now
                        GetString (atts, "EnableViewStateMac", null);
                        GetString (atts, "SmartNavigation", null);
@@ -237,6 +302,29 @@ namespace System.Web.UI
                        base.ProcessMainAttributes (atts);
                }
                
+#if NET_2_0
+               internal override void AddDirective (string directive, Hashtable atts)
+               {
+                       if (String.Compare ("MasterType", directive, true) == 0) {
+                               string type = GetString (atts, "TypeName", null);
+                               if (type != null) {
+                                       masterType = LoadType (type);
+                                       if (masterType == null)
+                                               ThrowParseException ("Could not load type '" + type + "'.");
+                               } else {
+                                       string path = GetString (atts, "VirtualPath", null);
+                                       if (path != null)
+                                               masterType = MasterPageParser.GetCompiledMasterType (path, MapPath (path), HttpContext.Current);
+                                       else
+                                               ThrowParseException ("The MasterType directive must have either a TypeName or a VirtualPath attribute.");
+                               }
+                               AddAssembly (masterType.Assembly, true);
+                       }
+                       else
+                               base.AddDirective (directive, atts);
+               }
+#endif
+               
                static string SuggestCulture (string culture)
                {
                        string retval = null;
@@ -324,6 +412,32 @@ namespace System.Web.UI
                internal bool NotBuffer {
                        get { return notBuffer; }
                }
+
+#if NET_2_0
+               internal string Theme {
+                       get { return theme; }
+               }
+
+               internal string StyleSheetTheme {
+                       get { return styleSheetTheme; }
+               }
+
+               internal string MasterPageFile {
+                       get { return masterPage; }
+               }
+               
+               internal Type MasterType {
+                       get { return masterType; }
+               }
+
+               internal string Title {
+                       get { return title; }
+               }
+
+               internal bool EnableEventValidation {
+                       get { return enable_event_validation; }
+               }
+#endif
        }
 }