diff --git a/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs b/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs index 0806226401f0eb275da432eaa7b25c0a8fa3d5da..cfb73d938adb9fda06c2c117cecc3014189841bd 100644 --- a/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs +++ b/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs @@ -201,6 +201,14 @@ namespace System.Web.Compilation case TagType.CodeRender: ProcessCode (tagtype, tagid, location); break; + case TagType.Include: + string file = attributes ["virtual"] as string; + bool isvirtual = (file != null); + if (!isvirtual) + file = attributes ["file"] as string; + + TextParsed (location, tparser.ProcessInclude (isvirtual, file)); + break; default: break; } diff --git a/mcs/class/System.Web/System.Web.Compilation/AspParser.cs b/mcs/class/System.Web/System.Web.Compilation/AspParser.cs index 21a9eb8686d8baeb9f33d1df3c69fc6260c583c1..420f18596016165406bb44c1d867e613aa00c4dc 100644 --- a/mcs/class/System.Web/System.Web.Compilation/AspParser.cs +++ b/mcs/class/System.Web/System.Web.Compilation/AspParser.cs @@ -152,6 +152,53 @@ namespace System.Web.Compilation } } + bool GetInclude (string str, out string pathType, out string filename) + { + pathType = null; + filename = null; + str = str.Substring (2).Trim (); + int len = str.Length; + int lastQuote = str.LastIndexOf ('"'); + if (len < 10 || lastQuote != len - 1 || !str.StartsWith ("#include ")) + return false; + + str = str.Substring (9).Trim (); + bool isfile = (str.StartsWith ("file")); + if (!isfile && !str.StartsWith ("virtual")) + return false; + + pathType = (isfile) ? "file" : "virtual"; + if (str.Length < pathType.Length + 3) + return false; + + str = str.Substring (pathType.Length).Trim (); + if (str.Length < 3 || str [0] != '=') + return false; + + int index = 1; + for (; index < str.Length; index++) { + if (Char.IsWhiteSpace (str [index])) + index++; + else if (str [index] == '"') + break; + } + + if (index == str.Length || index == lastQuote) + return false; + + str = str.Substring (index); + if (str.Length == 2) { // only quotes + OnError ("Empty file name."); + return false; + } + + filename = str.Trim ().Substring (index, str.Length - 2); + if (filename.LastIndexOf ('"') != -1) + return false; // file=""" -> no error + + return true; + } + void GetTag (out TagType tagtype, out string id, out TagAttributes attributes) { int token = tokenizer.get_token (); @@ -185,8 +232,15 @@ namespace System.Web.Compilation if (comment == null) OnError ("Unfinished HTML comment/DTD"); - tagtype = TagType.Text; - id = " + + * AspGenerator.cs: + * AspParser.cs: + * TagType.cs: Added support for server side includes. + 2003-05-03 Gonzalo Paniagua Javier * CSCompiler.cs: actually add the list of referenced assemblies to the diff --git a/mcs/class/System.Web/System.Web.Compilation/TagType.cs b/mcs/class/System.Web/System.Web.Compilation/TagType.cs index 4d8eed5264add6a290174823804a7fb13db6c137..cebe7477a5cbd5459a2ae7c40c4f8cd7099ebdb8 100644 --- a/mcs/class/System.Web/System.Web.Compilation/TagType.cs +++ b/mcs/class/System.Web/System.Web.Compilation/TagType.cs @@ -18,7 +18,8 @@ namespace System.Web.Compilation ServerComment, DataBinding, CodeRender, - CodeRenderExpression + CodeRenderExpression, + Include } } diff --git a/mcs/class/System.Web/System.Web.UI/ChangeLog b/mcs/class/System.Web/System.Web.UI/ChangeLog index 5beebd0158d2571a37fe553967b9b6e0d72a9d0e..28cdb3676caa1a3e96a385f655035fb4daee36f0 100644 --- a/mcs/class/System.Web/System.Web.UI/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI/ChangeLog @@ -1,3 +1,7 @@ +2003-05-04 Gonzalo Paniagua Javier + + * TemplateParser.cs: Added support for server side includes. + 2003-05-03 Gonzalo Paniagua Javier * TemplateControl.cs: fixed the flags used to find the methods that diff --git a/mcs/class/System.Web/System.Web.UI/TemplateParser.cs b/mcs/class/System.Web/System.Web.UI/TemplateParser.cs index 69f6a43e0a0076514e612591957d2e98bbddc501..23f18a277ab226097cd17711ffca92619710174a 100755 --- a/mcs/class/System.Web/System.Web.UI/TemplateParser.cs +++ b/mcs/class/System.Web/System.Web.UI/TemplateParser.cs @@ -313,6 +313,30 @@ namespace System.Web.UI ThrowParseException ("Unknown attribute: " + GetOneKey (atts)); } + internal string ProcessInclude (bool isvirtual, string file) + { + if (isvirtual) { + file = MapPath (file); + } else if (!Path.IsPathRooted (file)) { + file = UrlUtils.Combine (BaseVirtualDir, file); + } + + string result = null; + TextReader reader = null; + try { + reader = new StreamReader (file); //FIXME: encoding + result = reader.ReadToEnd (); + AddDependency (file); + } catch (Exception e) { + ThrowParseException (e.Message); + } finally { + if (reader != null) + reader.Close (); + } + + return result; + } + Assembly GetAssemblyFromSource (string vpath) { vpath = UrlUtils.Combine (BaseVirtualDir, vpath);