RootBuilder.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Web.Compilation;
  31. using System.Web.UI.HtmlControls;
  32. namespace System.Web.UI
  33. {
  34. public sealed class RootBuilder : TemplateBuilder
  35. {
  36. static Hashtable htmlControls;
  37. static Hashtable htmlInputControls;
  38. AspComponentFoundry foundry;
  39. static RootBuilder ()
  40. {
  41. htmlControls = new Hashtable (new CaseInsensitiveHashCodeProvider (),
  42. new CaseInsensitiveComparer ());
  43. htmlControls.Add ("A", typeof (HtmlAnchor));
  44. htmlControls.Add ("BUTTON", typeof (HtmlButton));
  45. htmlControls.Add ("FORM", typeof (HtmlForm));
  46. htmlControls.Add ("IMG", typeof (HtmlImage));
  47. htmlControls.Add ("INPUT", "INPUT");
  48. htmlControls.Add ("SELECT", typeof (HtmlSelect));
  49. htmlControls.Add ("TABLE", typeof (HtmlTable));
  50. htmlControls.Add ("TD", typeof (HtmlTableCell));
  51. htmlControls.Add ("TH", typeof (HtmlTableCell));
  52. htmlControls.Add ("TR", typeof (HtmlTableRow));
  53. htmlControls.Add ("TEXTAREA", typeof (HtmlTextArea));
  54. htmlInputControls = new Hashtable (new CaseInsensitiveHashCodeProvider (),
  55. new CaseInsensitiveComparer ());
  56. htmlInputControls.Add ("BUTTON", typeof (HtmlInputButton));
  57. htmlInputControls.Add ("SUBMIT", typeof (HtmlInputButton));
  58. htmlInputControls.Add ("RESET", typeof (HtmlInputButton));
  59. htmlInputControls.Add ("CHECKBOX", typeof (HtmlInputCheckBox));
  60. htmlInputControls.Add ("FILE", typeof (HtmlInputFile));
  61. htmlInputControls.Add ("HIDDEN", typeof (HtmlInputHidden));
  62. htmlInputControls.Add ("IMAGE", typeof (HtmlInputImage));
  63. htmlInputControls.Add ("RADIO", typeof (HtmlInputRadioButton));
  64. htmlInputControls.Add ("TEXT", typeof (HtmlInputText));
  65. htmlInputControls.Add ("PASSWORD", typeof (HtmlInputText));
  66. }
  67. public RootBuilder (TemplateParser parser)
  68. {
  69. foundry = new AspComponentFoundry ();
  70. line = 1;
  71. fileName = parser.InputFile;
  72. Init (parser, null, null, null, null, null);
  73. }
  74. public override Type GetChildControlType (string tagName, IDictionary attribs)
  75. {
  76. string prefix;
  77. string cname;
  78. int colon = tagName.IndexOf (':');
  79. if (colon != -1) {
  80. if (colon == 0)
  81. throw new Exception ("Empty TagPrefix is not valid");
  82. if (colon + 1 == tagName.Length)
  83. return null;
  84. prefix = tagName.Substring (0, colon);
  85. cname = tagName.Substring (colon + 1);
  86. } else {
  87. prefix = "";
  88. cname = tagName;
  89. }
  90. Type t = foundry.GetComponentType (prefix, cname);
  91. if (t != null)
  92. return t;
  93. else if (prefix != "")
  94. throw new Exception ("TagPrefix " + prefix + " not registered");
  95. return LookupHtmlControls (tagName, attribs);
  96. }
  97. static Type LookupHtmlControls (string tagName, IDictionary attribs)
  98. {
  99. object o = htmlControls [tagName];
  100. if (o is string) {
  101. if (attribs == null)
  102. throw new HttpException ("Unable to map input type control to a Type.");
  103. string ctype = attribs ["TYPE"] as string;
  104. if (ctype == null)
  105. ctype = "TEXT"; // The default used by MS
  106. Type t = htmlInputControls [ctype] as Type;
  107. if (t == null)
  108. throw new HttpException ("Unable to map input type control to a Type.");
  109. return t;
  110. }
  111. if (o == null)
  112. o = typeof (HtmlGenericControl);
  113. return (Type) o;
  114. }
  115. internal AspComponentFoundry Foundry {
  116. get { return foundry; }
  117. }
  118. }
  119. }