2004-01-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI / Utils.cs
1 /**
2  * Namespace: System.Web.UI
3  * Class:     Utils
4  *
5  * Author:  Gaurav Vaish
6  * Maintainer-> gvaish@iitk.ac.in
7  * Implementation: yes
8  * Contact: <gvaish@iitk.ac.in>
9  * Status:  ??%
10  *
11  * (C) Gaurav Vaish (2001)
12  */
13
14 using System;
15 using System.Collections;
16 using System.Web;
17 using System.Reflection;
18
19 namespace System.Web.UI
20 {
21         internal class Utils
22         {
23                 internal static object InvokeMethod(MethodInfo info, object obj, object[] parameters)
24                 {
25                         object retVal = null;
26                         try
27                         {
28                                 retVal = info.Invoke(obj, parameters);
29                         } catch(TargetInvocationException tie)
30                         {
31                                 throw tie.InnerException;
32                         }
33                         return retVal;
34                 }
35                 
36                 internal static string GetClientValidatedEvent(Page page)
37                 {
38                         return "if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();";
39                 }
40                 
41                 internal static string GetClientValidatedPostBack(Control control)
42                 {
43                         return (" { if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) " +
44                                 control.Page.GetPostBackEventReference(control) +
45                                 " } " );
46                 }
47                 
48                 [MonoTODO]
49                 internal static string GetScriptLocation(HttpContext context)
50                 {
51                         IDictionary dict = context.GetConfig("system.web/webControls")
52                                             as IDictionary;
53                         string loc = null;
54                         if(dict != null)
55                         {
56                                 loc = dict["clientScriptsLocation"] as string;
57                         }
58                         if(loc == null)
59                         {
60                                 throw new HttpException("Missing_clientScriptsLocation");
61                         }
62                         if(loc.IndexOf("{0}") > 0)
63                         {
64                                 //FIXME: Version Number of the ASP.Net should come into play.
65                                 //Like if ASP 1.0 and 1.1 both are installed, the script
66                                 // locations are in /aspnet_client/system_web/1_0_3705_0/
67                                 // and /aspnet_client/system_web/1_1_4322/
68                                 // (these entries are from my machine
69                                 // So, first I should get this Version Info from somewhere
70                                 loc = String.Format(loc, "system_web");
71                         }
72                         return loc;
73                 }
74         }
75 }