Files
mono/mcs/class/System.Web/System.Web.UI/TemplateControl.cs
T
Gonzalo Paniagua Javier 8e91ed0203 2002-12-18 Gonzalo Paniagua Javier <[email protected]>
* System.Web/HttpApplicationFactory.cs: add the context as parameter
	when building the application Type.

	* System.Web/HttpCookie.cs: new internal constructor.
	* System.Web/HttpCookieCollection.cs: new internal method to make a
	cookie expire.

	* System.Web/HttpRequest.cs: MapPath fixes.
	* System.Web/HttpResponse.cs: implemented ApplyAppPathModifier.
	* System.Web/HttpRuntime.cs: fixed typo in AppDomainAppVirtualPath.
	* System.Web.Compilation/AspGenerator.cs: now it uses the current
	HttpContext when creating user controls. TemplateSourceDirectory is no
	longer a dummy value.

	* System.Web.Compilation/GlobalAsaxCompiler.cs:
	* System.Web.Compilation/PageCompiler.cs:
	* System.Web.Compilation/UserControlCompiler.cs: set the context which
	will be used to locate the files.

	* System.Web.UI/BaseParser.cs: use MapPath and context to locate files.
	* System.Web.UI/Control.cs: implemented MapPathSecure.
	* System.Web.UI/TemplateControl.cs: use UrlUtils to generate the path.
	* System.Web.UI/TemplateControlParser.cs: use the context and MapPath.
	* System.Web.UI/UserControl.cs: implemented MapPath.
	* System.Web.UI/UserControlParser.cs: added context parameter to
	constructor.
	* System.Web.Util/PathUtil.cs: removed.
	* System.Web.Util/UrlUtils.cs: fixed Combine to handle '~'.

svn path=/trunk/mcs/; revision=9737
2002-12-18 02:17:17 +00:00

218 lines
4.8 KiB
C#
Executable File

//
// System.Web.UI.TemplateControl.cs
//
// Authors:
// Duncan Mak ([email protected])
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.Collections;
using System.Reflection;
using System.Web.Compilation;
using System.Web.Util;
namespace System.Web.UI {
public abstract class TemplateControl : Control, INamingContainer
{
static object abortTransaction = new object ();
static object commitTransaction = new object ();
static object error = new object ();
static string [] methodNames = { "Page_Init",
"Page_Load",
"Page_DataBind",
"Page_PreRender",
"Page_Dispose",
"Page_Error" };
const BindingFlags bflags = BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.DeclaredOnly |
BindingFlags.Static |
BindingFlags.Instance;
#region Constructor
protected TemplateControl ()
{
Construct ();
}
#endregion
#region Properties
protected virtual int AutoHandlers {
get { return 0; }
set { }
}
protected virtual bool SupportAutoEvents {
get { return true; }
}
#endregion
#region Methods
protected virtual void Construct ()
{
}
[MonoTODO]
protected virtual LiteralControl CreateResourceBasedLiteralControl (int offset,
int size,
bool fAsciiOnly)
{
return null;
}
internal void WireupAutomaticEvents ()
{
if (!SupportAutoEvents || !AutoEventWireup)
return;
Type type = GetType ();
foreach (MethodInfo method in type.GetMethods (bflags)) {
int pos = Array.IndexOf (methodNames, method.Name);
if (pos == -1)
continue;
string name = methodNames [pos];
pos = name.IndexOf ("_");
if (pos == -1 || pos + 1 == name.Length)
continue;
if (method.ReturnType != typeof (void))
continue;
ParameterInfo [] parms = method.GetParameters ();
if (parms.Length != 2 ||
parms [0].ParameterType != typeof (object) ||
parms [1].ParameterType != typeof (EventArgs))
continue;
string eventName = name.Substring (pos + 1);
EventInfo evt = type.GetEvent (eventName);
if (evt == null)
continue;
evt.AddEventHandler (this, Delegate.CreateDelegate (typeof (EventHandler), method));
}
}
protected virtual void FrameworkInitialize ()
{
}
Type GetTypeFromControlPath (string virtualPath)
{
if (virtualPath == null)
throw new ArgumentNullException ("virtualPath");
string vpath = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
return UserControlCompiler.CompileUserControlType (new UserControlParser (vpath, Context));
}
public Control LoadControl (string virtualPath)
{
object control = Activator.CreateInstance (GetTypeFromControlPath (virtualPath));
if (control is UserControl)
((UserControl) control).InitializeAsUserControl (Page);
return (Control) control;
}
public ITemplate LoadTemplate (string virtualPath)
{
Type t = GetTypeFromControlPath (virtualPath);
return new SimpleTemplate (t);
}
protected virtual void OnAbortTransaction (EventArgs e)
{
EventHandler eh = Events [error] as EventHandler;
if (eh != null)
eh.Invoke (this, e);
}
protected virtual void OnCommitTransaction (EventArgs e)
{
EventHandler eh = Events [commitTransaction] as EventHandler;
if (eh != null)
eh.Invoke (this, e);
}
protected virtual void OnError (EventArgs e)
{
EventHandler eh = Events [abortTransaction] as EventHandler;
if (eh != null)
eh.Invoke (this, e);
}
[MonoTODO]
public Control ParseControl (string content)
{
return null;
}
[MonoTODO]
public static object ReadStringResource (Type t)
{
return null;
}
[MonoTODO]
protected void SetStringResourcePointer (object stringResourcePointer,
int maxResourceOffset)
{
}
[MonoTODO]
protected void WriteUTF8ResourceString (HtmlTextWriter output, int offset,
int size, bool fAsciiOnly)
{
}
#endregion
#region Events
public event EventHandler AbortTransaction {
add { Events.AddHandler (abortTransaction, value); }
remove { Events.RemoveHandler (abortTransaction, value); }
}
public event EventHandler CommitTransaction {
add { Events.AddHandler (commitTransaction, value); }
remove { Events.RemoveHandler (commitTransaction, value); }
}
public event EventHandler Error {
add { Events.AddHandler (error, value); }
remove { Events.RemoveHandler (error, value); }
}
#endregion
class SimpleTemplate : ITemplate
{
Type type;
public SimpleTemplate (Type type)
{
this.type = type;
}
public void InstantiateIn (Control control)
{
Control template = Activator.CreateInstance (type) as Control;
template.SetBindingContainer (false);
control.Controls.Add (template);
}
}
}
}