Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / WebFormView.cs
1 namespace System.Web.Mvc {
2     using System;
3     using System.Globalization;
4     using System.IO;
5     using System.Web.Mvc.Resources;
6
7     public class WebFormView : BuildManagerCompiledView {
8
9         public WebFormView(ControllerContext controllerContext, string viewPath)
10             : this(controllerContext, viewPath, null, null) {
11         }
12
13         public WebFormView(ControllerContext controllerContext, string viewPath, string masterPath)
14             : this(controllerContext, viewPath, masterPath, null) {
15         }
16
17         public WebFormView(ControllerContext controllerContext, string viewPath, string masterPath, IViewPageActivator viewPageActivator)
18             : base(controllerContext, viewPath, viewPageActivator) {
19             MasterPath = masterPath ?? String.Empty;
20         }
21
22         public string MasterPath {
23             get;
24             private set;
25         }
26
27         protected override void RenderView(ViewContext viewContext, TextWriter writer, object instance) {
28
29             ViewPage viewPage = instance as ViewPage;
30             if (viewPage != null) {
31                 RenderViewPage(viewContext, viewPage);
32                 return;
33             }
34
35             ViewUserControl viewUserControl = instance as ViewUserControl;
36             if (viewUserControl != null) {
37                 RenderViewUserControl(viewContext, viewUserControl);
38                 return;
39             }
40
41             throw new InvalidOperationException(
42                 String.Format(
43                     CultureInfo.CurrentCulture,
44                     MvcResources.WebFormViewEngine_WrongViewBase,
45                     ViewPath));
46         }
47
48         private void RenderViewPage(ViewContext context, ViewPage page) {
49             if (!String.IsNullOrEmpty(MasterPath)) {
50                 page.MasterLocation = MasterPath;
51             }
52
53             page.ViewData = context.ViewData;
54             page.RenderView(context);
55         }
56
57         private void RenderViewUserControl(ViewContext context, ViewUserControl control) {
58             if (!String.IsNullOrEmpty(MasterPath)) {
59                 throw new InvalidOperationException(MvcResources.WebFormViewEngine_UserControlCannotHaveMaster);
60             }
61
62             control.ViewData = context.ViewData;
63             control.RenderView(context);
64         }
65     }
66 }