提交 a08b0012 编写于 作者: G Gonzalo Paniagua Javier

2003-05-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>

	* System.Web.Compilation/AspGenerator.cs:
	* System.Web.Compilation/AspParser.cs:
	* System.Web.Compilation/TagType.cs:
	* System.Web.UI/TemplateParser.cs: Added support for server side
	includes.

svn path=/trunk/mcs/; revision=14242
上级 b76faa4b
......@@ -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;
}
......
......@@ -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 = "<!" + comment + end;
string pathType, filename;
if (double_dash && GetInclude (comment, out pathType, out filename)) {
tagtype = TagType.Include;
attributes = new TagAttributes ();
attributes.Add (pathType, filename);
} else {
tagtype = TagType.Text;
id = "<!" + comment + end;
}
break;
case Token.IDENTIFIER:
id = tokenizer.Value;
......
2003-05-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* AspGenerator.cs:
* AspParser.cs:
* TagType.cs: Added support for server side includes.
2003-05-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* CSCompiler.cs: actually add the list of referenced assemblies to the
......
......@@ -18,7 +18,8 @@ namespace System.Web.Compilation
ServerComment,
DataBinding,
CodeRender,
CodeRenderExpression
CodeRenderExpression,
Include
}
}
2003-05-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* TemplateParser.cs: Added support for server side includes.
2003-05-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* TemplateControl.cs: fixed the flags used to find the methods that
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册