2004-01-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Compilation / AspGenerator.cs
index 1cf35dcbb7e1cc86117a9577dd20efd771968c36..3045ecc89647d9f878b833686a6d36aeb44bc686 100644 (file)
@@ -8,8 +8,10 @@
 //
 using System;
 using System.Collections;
+using System.CodeDom.Compiler;
 using System.IO;
 using System.Text;
+using System.Web.Caching;
 using System.Web.UI;
 using System.Web.Util;
 
@@ -153,9 +155,9 @@ namespace System.Web.Compilation
                
                void InitParser (string filename)
                {
-                       //FIXME: use the encoding of the file or the one specified in the machine.config/web.config file.
-                       StreamReader reader = new StreamReader (filename, Encoding.Default);
+                       StreamReader reader = new StreamReader (filename, WebEncoding.FileEncoding);
                        AspParser parser = new AspParser (filename, reader);
+                       reader.Close ();
                        parser.Error += new ParseErrorHandler (ParseError);
                        parser.TagParsed += new TagParsedHandler (TagParsed);
                        parser.TextParsed += new TextParsedHandler (TextParsed);
@@ -175,6 +177,11 @@ namespace System.Web.Compilation
 
                public Type GetCompiledType ()
                {
+                       Type type = (Type) HttpRuntime.Cache.Get (tparser.InputFile);
+                       if (type != null) {
+                               return type;
+                       }
+
                        InitParser (Path.GetFullPath (tparser.InputFile));
                        DoParse ();
 #if DEBUG
@@ -187,7 +194,12 @@ namespace System.Web.Compilation
 
                        BaseCompiler compiler = GetCompilerFromType ();
 
-                       return compiler.GetCompiledType ();
+                       type = compiler.GetCompiledType ();
+                       CacheDependency cd = new CacheDependency ((string[])
+                                                       tparser.Dependencies.ToArray (typeof (string)));
+
+                       HttpRuntime.Cache.Insert (tparser.InputFile, type, cd);
+                       return type;
                }
 
 #if DEBUG
@@ -292,7 +304,7 @@ namespace System.Web.Compilation
 
                void TextParsed (ILocation location, string text)
                {
-                       if (text.IndexOf ("<%") != -1 && !inScript && !javascript) {
+                       if (text.IndexOf ("<%") != -1 && !inScript) {
                                if (this.text.Length > 0)
                                        FlushText ();
                                CodeRenderParser r = new CodeRenderParser (text, stack.Builder);
@@ -322,6 +334,14 @@ namespace System.Web.Compilation
 
                bool ProcessTag (string tagid, TagAttributes atts)
                {
+                       if ((atts == null || !atts.IsRunAtServer ()) && String.Compare (tagid, "tbody", true) == 0) {
+                               // MS completely ignores tbody or, if runat="server", fails when compiling
+                               if (stack.Count > 0)
+                                       return stack.Builder.ChildrenAsProperties;
+
+                               return false;
+                       }
+
                        ControlBuilder parent = stack.Builder;
                        ControlBuilder builder = null;
                        BuilderLocation bl = null;
@@ -337,6 +357,10 @@ namespace System.Web.Compilation
                        }
 
                        if (builder == null && atts != null && atts.IsRunAtServer ()) {
+                               string id = htable ["id"] as string;
+                               if (id != null && !CodeGenerator.IsValidLanguageIndependentIdentifier (id))
+                                       throw new ParseException (Location, "'" + id + "' is not a valid identifier");
+                                       
                                try {
                                        builder = rootBuilder.CreateSubBuilder (tagid, htable, null, tparser, location);
                                } catch (TypeLoadException e) {
@@ -401,6 +425,16 @@ namespace System.Web.Compilation
                bool CloseControl (string tagid)
                {
                        ControlBuilder current = stack.Builder;
+                       if (String.Compare (tagid, "tbody", true) == 0) {
+                               if (!current.ChildrenAsProperties) {
+                                       try {
+                                               TextParsed (location, location.PlainText);
+                                               FlushText ();
+                                       } catch {}
+                               }
+                               return true;
+                       }
+                       
                        string btag = current.TagName;
                        if (0 != String.Compare (tagid, btag, true))
                                return false;
@@ -439,9 +473,9 @@ namespace System.Web.Compilation
                                return;
 
                        if (String.Compare (lang, tparser.Language, true) != 0) {
-                               // FIXME: throw the same exception as MS
-                               throw new Exception ("Trying to mix " + tparser.Language + " and " +
-                                                    lang + ".");
+                               throw new ParseException (Location,
+                                               String.Format ("Trying to mix language '{0}' and '{1}'.", 
+                                                               tparser.Language, lang));
                        }
                }
                // Used to get CodeRender tags in attribute values