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 private Hashtable built_objects;
48 public sealed class RootBuilder : TemplateBuilder {
50 static Hashtable htmlControls;
51 static Hashtable htmlInputControls;
52 AspComponentFoundry foundry;
57 htmlControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
59 htmlControls = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
60 CaseInsensitiveComparer.DefaultInvariant);
63 htmlControls.Add ("A", typeof (HtmlAnchor));
64 htmlControls.Add ("BUTTON", typeof (HtmlButton));
65 htmlControls.Add ("FORM", typeof (HtmlForm));
67 htmlControls.Add ("HEAD", typeof (HtmlHead));
69 htmlControls.Add ("IMG", typeof (HtmlImage));
70 htmlControls.Add ("INPUT", "INPUT");
72 htmlControls.Add ("LINK", typeof (HtmlLink));
73 htmlControls.Add ("META", typeof (HtmlLink));
75 htmlControls.Add ("SELECT", typeof (HtmlSelect));
76 htmlControls.Add ("TABLE", typeof (HtmlTable));
77 htmlControls.Add ("TD", typeof (HtmlTableCell));
78 htmlControls.Add ("TH", typeof (HtmlTableCell));
79 htmlControls.Add ("TR", typeof (HtmlTableRow));
80 htmlControls.Add ("TEXTAREA", typeof (HtmlTextArea));
83 htmlInputControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
85 htmlInputControls = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
86 CaseInsensitiveComparer.DefaultInvariant);
89 htmlInputControls.Add ("BUTTON", typeof (HtmlInputButton));
91 htmlInputControls.Add ("SUBMIT", typeof (HtmlInputSubmit));
92 htmlInputControls.Add ("RESET", typeof (HtmlInputReset));
94 htmlInputControls.Add ("SUBMIT", typeof (HtmlInputButton));
95 htmlInputControls.Add ("RESET", typeof (HtmlInputButton));
97 htmlInputControls.Add ("CHECKBOX", typeof (HtmlInputCheckBox));
98 htmlInputControls.Add ("FILE", typeof (HtmlInputFile));
99 htmlInputControls.Add ("HIDDEN", typeof (HtmlInputHidden));
100 htmlInputControls.Add ("IMAGE", typeof (HtmlInputImage));
101 htmlInputControls.Add ("RADIO", typeof (HtmlInputRadioButton));
102 htmlInputControls.Add ("TEXT", typeof (HtmlInputText));
104 htmlInputControls.Add ("PASSWORD", typeof (HtmlInputPassword));
106 htmlInputControls.Add ("PASSWORD", typeof (HtmlInputText));
110 public RootBuilder (TemplateParser parser)
112 foundry = new AspComponentFoundry ();
115 fileName = parser.InputFile;
116 Init (parser, null, null, null, null, null);
119 public override Type GetChildControlType (string tagName, IDictionary attribs)
122 throw new ArgumentNullException ("tagName");
126 int colon = tagName.IndexOf (':');
129 throw new Exception ("Empty TagPrefix is not valid");
131 if (colon + 1 == tagName.Length)
134 prefix = tagName.Substring (0, colon);
135 cname = tagName.Substring (colon + 1);
141 Type t = foundry.GetComponentType (prefix, cname);
144 else if (prefix != "")
145 throw new Exception ("Unknown server tag '" + tagName + "'");
147 return LookupHtmlControls (tagName, attribs);
150 static Type LookupHtmlControls (string tagName, IDictionary attribs)
152 object o = htmlControls [tagName];
155 throw new HttpException ("Unable to map input type control to a Type.");
157 string ctype = attribs ["TYPE"] as string;
159 ctype = "TEXT"; // The default used by MS
161 Type t = htmlInputControls [ctype] as Type;
163 throw new HttpException ("Unable to map input type control to a Type.");
169 o = typeof (HtmlGenericControl);
174 internal AspComponentFoundry Foundry {
175 get { return foundry; }
177 if (value is AspComponentFoundry)
182 // FIXME: it's empty (but not null) when using the new default ctor
183 // but I'm not sure when something should gets in...
184 public IDictionary BuiltObjects {
186 if (built_objects == null)
187 built_objects = new Hashtable ();
188 return built_objects;