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 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)]
39 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 public class RootBuilder : TemplateBuilder {
42 Hashtable built_objects;
46 foundry = new AspComponentFoundry ();
50 public sealed class RootBuilder : TemplateBuilder {
52 static Hashtable htmlControls;
53 static Hashtable htmlInputControls;
54 AspComponentFoundry foundry;
59 htmlControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
61 htmlControls = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
62 CaseInsensitiveComparer.DefaultInvariant);
65 htmlControls.Add ("A", typeof (HtmlAnchor));
66 htmlControls.Add ("BUTTON", typeof (HtmlButton));
67 htmlControls.Add ("FORM", typeof (HtmlForm));
69 htmlControls.Add ("HEAD", typeof (HtmlHead));
71 htmlControls.Add ("IMG", typeof (HtmlImage));
72 htmlControls.Add ("INPUT", "INPUT");
74 htmlControls.Add ("LINK", typeof (HtmlLink));
75 htmlControls.Add ("META", typeof (HtmlLink));
77 htmlControls.Add ("SELECT", typeof (HtmlSelect));
78 htmlControls.Add ("TABLE", typeof (HtmlTable));
79 htmlControls.Add ("TD", typeof (HtmlTableCell));
80 htmlControls.Add ("TH", typeof (HtmlTableCell));
81 htmlControls.Add ("TR", typeof (HtmlTableRow));
82 htmlControls.Add ("TEXTAREA", typeof (HtmlTextArea));
85 htmlInputControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
87 htmlInputControls = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
88 CaseInsensitiveComparer.DefaultInvariant);
91 htmlInputControls.Add ("BUTTON", typeof (HtmlInputButton));
93 htmlInputControls.Add ("SUBMIT", typeof (HtmlInputSubmit));
94 htmlInputControls.Add ("RESET", typeof (HtmlInputReset));
96 htmlInputControls.Add ("SUBMIT", typeof (HtmlInputButton));
97 htmlInputControls.Add ("RESET", typeof (HtmlInputButton));
99 htmlInputControls.Add ("CHECKBOX", typeof (HtmlInputCheckBox));
100 htmlInputControls.Add ("FILE", typeof (HtmlInputFile));
101 htmlInputControls.Add ("HIDDEN", typeof (HtmlInputHidden));
102 htmlInputControls.Add ("IMAGE", typeof (HtmlInputImage));
103 htmlInputControls.Add ("RADIO", typeof (HtmlInputRadioButton));
104 htmlInputControls.Add ("TEXT", typeof (HtmlInputText));
106 htmlInputControls.Add ("PASSWORD", typeof (HtmlInputPassword));
108 htmlInputControls.Add ("PASSWORD", typeof (HtmlInputText));
112 public RootBuilder (TemplateParser parser)
114 foundry = new AspComponentFoundry ();
117 FileName = parser.InputFile;
118 Init (parser, null, null, null, null, null);
121 public override Type GetChildControlType (string tagName, IDictionary attribs)
124 throw new ArgumentNullException ("tagName");
126 AspComponent component = foundry.GetComponent (tagName);
128 if (component != null) {
130 if (!String.IsNullOrEmpty (component.Source)) {
131 TemplateParser parser = Parser;
133 if (component.FromConfig) {
134 string parserDir = parser.BaseVirtualDir;
135 VirtualPath vp = new VirtualPath (component.Source);
137 if (parserDir == vp.Directory)
138 throw new ParseException (parser.Location,
139 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));
141 Parser.AddDependency (component.Source);
145 return component.Type;
146 } else if (component != null && component.Prefix != String.Empty)
147 throw new Exception ("Unknown server tag '" + tagName + "'");
149 return LookupHtmlControls (tagName, attribs);
152 static Type LookupHtmlControls (string tagName, IDictionary attribs)
154 object o = htmlControls [tagName];
157 throw new HttpException ("Unable to map input type control to a Type.");
159 string ctype = attribs ["TYPE"] as string;
161 ctype = "TEXT"; // The default used by MS
163 Type t = htmlInputControls [ctype] as Type;
165 throw new HttpException ("Unable to map input type control to a Type.");
171 o = typeof (HtmlGenericControl);
176 internal AspComponentFoundry Foundry {
177 get { return foundry; }
179 if (value is AspComponentFoundry)
184 // FIXME: it's empty (but not null) when using the new default ctor
185 // but I'm not sure when something should gets in...
186 public IDictionary BuiltObjects {
188 if (built_objects == null)
189 built_objects = new Hashtable ();
190 return built_objects;