2 // System.Web.UI.RootBuilder
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc. (http://www.ximian.com)
8 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
31 using System.Security.Permissions;
32 using System.Web.Compilation;
33 using System.Web.UI.HtmlControls;
35 namespace System.Web.UI
37 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 public class RootBuilder : TemplateBuilder
41 Hashtable built_objects;
42 static Hashtable htmlControls;
43 static Hashtable htmlInputControls;
44 AspComponentFoundry foundry;
48 foundry = new AspComponentFoundry ();
54 htmlControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
55 htmlControls.Add ("A", typeof (HtmlAnchor));
56 htmlControls.Add ("BUTTON", typeof (HtmlButton));
57 htmlControls.Add ("FORM", typeof (HtmlForm));
58 htmlControls.Add ("HEAD", typeof (HtmlHead));
59 htmlControls.Add ("IMG", typeof (HtmlImage));
60 htmlControls.Add ("INPUT", "INPUT");
61 htmlControls.Add ("LINK", typeof (HtmlLink));
62 htmlControls.Add ("META", typeof (HtmlLink));
63 htmlControls.Add ("SELECT", typeof (HtmlSelect));
64 htmlControls.Add ("TABLE", typeof (HtmlTable));
65 htmlControls.Add ("TD", typeof (HtmlTableCell));
66 htmlControls.Add ("TH", typeof (HtmlTableCell));
67 htmlControls.Add ("TR", typeof (HtmlTableRow));
68 htmlControls.Add ("TEXTAREA", typeof (HtmlTextArea));
70 htmlInputControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
72 htmlInputControls.Add ("BUTTON", typeof (HtmlInputButton));
73 htmlInputControls.Add ("SUBMIT", typeof (HtmlInputSubmit));
74 htmlInputControls.Add ("RESET", typeof (HtmlInputReset));
75 htmlInputControls.Add ("CHECKBOX", typeof (HtmlInputCheckBox));
76 htmlInputControls.Add ("FILE", typeof (HtmlInputFile));
77 htmlInputControls.Add ("HIDDEN", typeof (HtmlInputHidden));
78 htmlInputControls.Add ("IMAGE", typeof (HtmlInputImage));
79 htmlInputControls.Add ("RADIO", typeof (HtmlInputRadioButton));
80 htmlInputControls.Add ("TEXT", typeof (HtmlInputText));
81 htmlInputControls.Add ("PASSWORD", typeof (HtmlInputPassword));
84 public RootBuilder (TemplateParser parser)
86 foundry = new AspComponentFoundry ();
89 FileName = parser.InputFile;
90 Init (parser, null, null, null, null, null);
93 public override Type GetChildControlType (string tagName, IDictionary attribs)
96 throw new ArgumentNullException ("tagName");
98 AspComponent component = foundry.GetComponent (tagName);
100 if (component != null) {
101 if (!String.IsNullOrEmpty (component.Source)) {
102 TemplateParser parser = Parser;
104 if (component.FromConfig) {
105 string parserDir = parser.BaseVirtualDir;
106 VirtualPath vp = new VirtualPath (component.Source);
108 if (parserDir == vp.Directory)
109 throw new ParseException (parser.Location,
110 String.Format ("The page '{0}' cannot use the user control '{1}', because it is registered in web.config and lives in the same directory as the page.", parser.VirtualPath, vp.Absolute));
112 Parser.AddDependency (component.Source);
115 return component.Type;
116 } else if (component != null && component.Prefix != String.Empty)
117 throw new Exception ("Unknown server tag '" + tagName + "'");
119 return LookupHtmlControls (tagName, attribs);
122 static Type LookupHtmlControls (string tagName, IDictionary attribs)
124 object o = htmlControls [tagName];
127 throw new HttpException ("Unable to map input type control to a Type.");
129 string ctype = attribs ["TYPE"] as string;
131 ctype = "TEXT"; // The default used by MS
133 Type t = htmlInputControls [ctype] as Type;
135 throw new HttpException ("Unable to map input type control to a Type.");
141 o = typeof (HtmlGenericControl);
146 internal AspComponentFoundry Foundry {
147 get { return foundry; }
149 if (value is AspComponentFoundry)
154 // FIXME: it's empty (but not null) when using the new default ctor
155 // but I'm not sure when something should gets in...
156 public IDictionary BuiltObjects {
158 if (built_objects == null)
159 built_objects = new Hashtable ();
160 return built_objects;