Mark tests as not working under TARGET_JVM
[mono.git] / mcs / class / System.Web / System.Web.UI / RootBuilder.cs
1 //
2 // System.Web.UI.RootBuilder
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc. (http://www.ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using System.Collections;
31 using System.Security.Permissions;
32 using System.Web.Compilation;
33 using System.Web.UI.HtmlControls;
34
35 namespace System.Web.UI {
36
37         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 #if NET_2_0
39         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40         public class RootBuilder : TemplateBuilder {
41
42                 private Hashtable built_objects;
43
44                 public RootBuilder ()
45                 {
46                 }
47 #else
48         public sealed class RootBuilder : TemplateBuilder {
49 #endif
50                 static Hashtable htmlControls;
51                 static Hashtable htmlInputControls;
52                 AspComponentFoundry foundry;
53
54                 static RootBuilder ()
55                 {
56 #if NET_2_0
57                         htmlControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
58 #else
59                         htmlControls = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
60                                                       CaseInsensitiveComparer.DefaultInvariant); 
61 #endif
62
63                         htmlControls.Add ("A", typeof (HtmlAnchor));
64                         htmlControls.Add ("BUTTON", typeof (HtmlButton));
65                         htmlControls.Add ("FORM", typeof (HtmlForm));
66 #if NET_2_0
67                         htmlControls.Add ("HEAD", typeof (HtmlHead));
68 #endif
69                         htmlControls.Add ("IMG", typeof (HtmlImage));
70                         htmlControls.Add ("INPUT", "INPUT");
71 #if NET_2_0
72                         htmlControls.Add ("LINK", typeof (HtmlLink));
73                         htmlControls.Add ("META", typeof (HtmlLink));
74 #endif
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));
81
82 #if NET_2_0
83                         htmlInputControls = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
84 #else
85                         htmlInputControls = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
86                                                            CaseInsensitiveComparer.DefaultInvariant);
87 #endif
88
89                         htmlInputControls.Add ("BUTTON", typeof (HtmlInputButton));
90 #if NET_2_0
91                         htmlInputControls.Add ("SUBMIT", typeof (HtmlInputSubmit));
92                         htmlInputControls.Add ("RESET", typeof (HtmlInputReset));
93 #else
94                         htmlInputControls.Add ("SUBMIT", typeof (HtmlInputButton));
95                         htmlInputControls.Add ("RESET", typeof (HtmlInputButton));
96 #endif
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));
103 #if NET_2_0
104                         htmlInputControls.Add ("PASSWORD", typeof (HtmlInputPassword));
105 #else
106                         htmlInputControls.Add ("PASSWORD", typeof (HtmlInputText));
107 #endif
108                 }
109
110                 public RootBuilder (TemplateParser parser)
111                 {
112                         foundry = new AspComponentFoundry ();
113                         line = 1;
114                         if (parser != null)
115                                 fileName = parser.InputFile;
116                         Init (parser, null, null, null, null, null);
117                 }
118
119                 public override Type GetChildControlType (string tagName, IDictionary attribs) 
120                 {
121                         if (tagName == null)
122                                 throw new ArgumentNullException ("tagName");
123
124                         string prefix;
125                         string cname;
126                         int colon = tagName.IndexOf (':');
127                         if (colon != -1) {
128                                 if (colon == 0)
129                                         throw new Exception ("Empty TagPrefix is not valid");
130
131                                 if (colon + 1 == tagName.Length)
132                                         return null;
133
134                                 prefix = tagName.Substring (0, colon);
135                                 cname = tagName.Substring (colon + 1);
136                         } else {
137                                 prefix = "";
138                                 cname = tagName;
139                         }
140
141                         Type t = foundry.GetComponentType (prefix, cname);
142                         if (t != null)
143                                 return t;
144                         else if (prefix != "")
145                                 throw new Exception ("Unknown server tag '" + tagName + "'");
146                         
147                         return LookupHtmlControls (tagName, attribs);
148                 }
149
150                 static Type LookupHtmlControls (string tagName, IDictionary attribs)
151                 {
152                         object o = htmlControls [tagName];
153                         if (o is string) {
154                                 if (attribs == null)
155                                         throw new HttpException ("Unable to map input type control to a Type.");
156
157                                 string ctype = attribs ["TYPE"] as string;
158                                 if (ctype == null)
159                                         ctype = "TEXT"; // The default used by MS
160
161                                 Type t = htmlInputControls [ctype] as Type;
162                                 if (t == null)
163                                         throw new HttpException ("Unable to map input type control to a Type.");
164
165                                 return t;
166                         }
167
168                         if (o == null)
169                                 o = typeof (HtmlGenericControl);
170
171                         return (Type) o;
172                 }
173
174                 internal AspComponentFoundry Foundry {
175                         get { return foundry; }
176                 }
177 #if NET_2_0
178                 // FIXME: it's empty (but not null) when using the new default ctor
179                 // but I'm not sure when something should gets in...
180                 public IDictionary BuiltObjects {
181                         get {
182                                 if (built_objects == null)
183                                         built_objects = new Hashtable ();
184                                 return built_objects;
185                         }
186                 }
187 #endif
188         }
189 }