RootBuilder.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // System.Web.UI.RootBuilder
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc. (http://www.ximian.com)
  8. using System;
  9. using System.Collections;
  10. using System.Web.Compilation;
  11. using System.Web.UI.HtmlControls;
  12. namespace System.Web.UI
  13. {
  14. public sealed class RootBuilder : TemplateBuilder
  15. {
  16. static Hashtable htmlControls;
  17. static Hashtable htmlInputControls;
  18. AspComponentFoundry foundry;
  19. static RootBuilder ()
  20. {
  21. htmlControls = new Hashtable (new CaseInsensitiveHashCodeProvider (),
  22. new CaseInsensitiveComparer ());
  23. htmlControls.Add ("A", typeof (HtmlAnchor));
  24. htmlControls.Add ("BUTTON", typeof (HtmlButton));
  25. htmlControls.Add ("FORM", typeof (HtmlForm));
  26. htmlControls.Add ("IMG", typeof (HtmlImage));
  27. htmlControls.Add ("INPUT", "INPUT");
  28. htmlControls.Add ("SELECT", typeof (HtmlSelect));
  29. htmlControls.Add ("TABLE", typeof (HtmlTable));
  30. htmlControls.Add ("TD", typeof (HtmlTableCell));
  31. htmlControls.Add ("TH", typeof (HtmlTableCell));
  32. htmlControls.Add ("TR", typeof (HtmlTableRow));
  33. htmlControls.Add ("TEXTAREA", typeof (HtmlTextArea));
  34. htmlInputControls = new Hashtable (new CaseInsensitiveHashCodeProvider (),
  35. new CaseInsensitiveComparer ());
  36. htmlInputControls.Add ("BUTTON", typeof (HtmlInputButton));
  37. htmlInputControls.Add ("SUBMIT", typeof (HtmlInputButton));
  38. htmlInputControls.Add ("RESET", typeof (HtmlInputButton));
  39. htmlInputControls.Add ("CHECKBOX", typeof (HtmlInputCheckBox));
  40. htmlInputControls.Add ("FILE", typeof (HtmlInputFile));
  41. htmlInputControls.Add ("HIDDEN", typeof (HtmlInputHidden));
  42. htmlInputControls.Add ("IMAGE", typeof (HtmlInputImage));
  43. htmlInputControls.Add ("RADIO", typeof (HtmlInputRadioButton));
  44. htmlInputControls.Add ("TEXT", typeof (HtmlInputText));
  45. htmlInputControls.Add ("PASSWORD", typeof (HtmlInputText));
  46. }
  47. public RootBuilder (TemplateParser parser)
  48. {
  49. foundry = new AspComponentFoundry ();
  50. line = 1;
  51. fileName = parser.InputFile;
  52. Init (parser, null, null, null, null, null);
  53. }
  54. public override Type GetChildControlType (string tagName, IDictionary attribs)
  55. {
  56. string prefix;
  57. string cname;
  58. int colon = tagName.IndexOf (':');
  59. if (colon != -1) {
  60. if (colon == 0)
  61. throw new Exception ("Empty TagPrefix is not valid");
  62. if (colon + 1 == tagName.Length)
  63. return null;
  64. prefix = tagName.Substring (0, colon);
  65. cname = tagName.Substring (colon + 1);
  66. } else {
  67. prefix = "";
  68. cname = tagName;
  69. }
  70. Type t = foundry.GetComponentType (prefix, cname);
  71. if (t != null)
  72. return t;
  73. else if (prefix != "")
  74. throw new Exception ("TagPrefix " + prefix + " not registered");
  75. return LookupHtmlControls (tagName, attribs);
  76. }
  77. static Type LookupHtmlControls (string tagName, IDictionary attribs)
  78. {
  79. object o = htmlControls [tagName];
  80. if (o is string) {
  81. if (attribs == null)
  82. throw new HttpException ("Unable to map input type control to a Type.");
  83. string ctype = attribs ["TYPE"] as string;
  84. if (ctype == null)
  85. ctype = "TEXT"; // The default used by MS
  86. Type t = htmlInputControls [ctype] as Type;
  87. if (t == null)
  88. throw new HttpException ("Unable to map input type control to a Type.");
  89. return t;
  90. }
  91. if (o == null)
  92. o = typeof (HtmlGenericControl);
  93. return (Type) o;
  94. }
  95. internal AspComponentFoundry Foundry {
  96. get { return foundry; }
  97. }
  98. }
  99. }