X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI%2FXhtmlTextWriter.cs;h=883d887c476ba5ca5af5b5ad4a3be76cac30933b;hb=879970ea20a49e63a5413adec014754b30a53e03;hp=d0f6dd63c48aff73069b033e2924ee6ea84937c6;hpb=6b4c7232fd97322f47e41ce5fc9da9d92fd81343;p=mono.git diff --git a/mcs/class/System.Web/System.Web.UI/XhtmlTextWriter.cs b/mcs/class/System.Web/System.Web.UI/XhtmlTextWriter.cs index d0f6dd63c48..883d887c476 100644 --- a/mcs/class/System.Web/System.Web.UI/XhtmlTextWriter.cs +++ b/mcs/class/System.Web/System.Web.UI/XhtmlTextWriter.cs @@ -6,7 +6,7 @@ // // -// Copyright (C) 2006 Novell, Inc (http://www.novell.com) +// Copyright (C) 2006-2010 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -28,22 +28,35 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if NET_2_0 - using System.IO; using System.Collections; -namespace System.Web.UI { - +namespace System.Web.UI +{ public class XhtmlTextWriter : HtmlTextWriter { - Hashtable common_attrs = new Hashtable (DefaultCommonAttributes.Length); - Hashtable suppress_common_attrs = new Hashtable (DefaultSuppressCommonAttributes.Length); - Hashtable element_specific_attrs = new Hashtable (); + static Hashtable default_common_attrs; + static Hashtable default_suppress_common_attrs; + static Hashtable default_element_specific_attrs; + + Hashtable common_attrs; + Hashtable suppress_common_attrs; + Hashtable element_specific_attrs; - Hashtable attr_render = new Hashtable (); + static XhtmlTextWriter () + { + default_common_attrs = new Hashtable (DefaultCommonAttributes.Length); + SetupHash (default_common_attrs, DefaultCommonAttributes); + default_suppress_common_attrs = new Hashtable (DefaultSuppressCommonAttributes.Length); + SetupHash (default_suppress_common_attrs, DefaultSuppressCommonAttributes); + SetupElementsSpecificAttributes (); + } - //XhtmlMobileDocType doc_type; + static void SetupHash (Hashtable hash, string [] values) + { + foreach (string str in values) + hash.Add (str, true); + } static string [] DefaultCommonAttributes = { "class", @@ -65,173 +78,144 @@ namespace System.Web.UI { "style" }; - public XhtmlTextWriter (TextWriter writer) - : this (writer, DefaultTabString) - { - } - - public XhtmlTextWriter (TextWriter writer, string tabString) - : base (writer, tabString) - { - SetupCommonAttributes (); - SetupSuppressCommonAttributes (); - SetupElementsSpecificAttributes (); - } - - void SetupHash (Hashtable hash, string [] values) { - foreach (string str in values) - hash.Add (str, true); - } - - // - // if you need to add a new default common attribute, - // add the literal as a member of the DefaultCommonAttributes array - // - void SetupCommonAttributes () - { - SetupHash (common_attrs, DefaultCommonAttributes); - } - - // - // if you need to add a new suppressed common attribute, - // add the literal as a member of the SuppressCommonAttrs array - // - void SetupSuppressCommonAttributes () - { - SetupHash (suppress_common_attrs, DefaultSuppressCommonAttributes); - } - - // - // I did not make them static because different instances of XhtmlTextWriter's - // do not share the changes made to the element's attributes tables, - // they are not read-only. - // - Hashtable a_attrs, base_attrs, blockquote_attrs, br_attrs, form_attrs, head_attrs; - Hashtable html_attrs, img_attrs, input_attrs, label_attrs, li_attrs, link_attrs; - Hashtable meta_attrs, object_attrs, ol_attrs, optgroup_attrs, option_attrs, param_attrs; - Hashtable pre_attrs, q_attrs, select_attrs, style_attrs, table_attrs, textarea_attrs; - Hashtable td_attrs, th_attrs, title_attrs, tr_attrs; - - void SetupElementsSpecificAttributes () + static void SetupElementsSpecificAttributes () { + default_element_specific_attrs = new Hashtable (); string [] a_attrs_names = {"accesskey", "href", "charset", "hreflang", "rel", "type", "rev", "title", "tabindex"}; - SetupElementSpecificAttributes ("a", a_attrs, a_attrs_names); + SetupElementSpecificAttributes ("a", a_attrs_names); string [] base_attrs_names = {"href"}; - SetupElementSpecificAttributes ("base", base_attrs, base_attrs_names); + SetupElementSpecificAttributes ("base", base_attrs_names); string [] blockquote_attrs_names = {"cite"}; - SetupElementSpecificAttributes ("blockquote", blockquote_attrs, blockquote_attrs_names); + SetupElementSpecificAttributes ("blockquote", blockquote_attrs_names); string [] br_attrs_names = {"id", "class", "title"}; - SetupElementSpecificAttributes ("br", br_attrs, br_attrs_names); + SetupElementSpecificAttributes ("br", br_attrs_names); string [] form_attrs_names = {"action", "method", "enctype"}; - SetupElementSpecificAttributes ("form", form_attrs, form_attrs_names); + SetupElementSpecificAttributes ("form", form_attrs_names); string [] head_attrs_names = {"xml:lang"}; - SetupElementSpecificAttributes ("head", head_attrs, head_attrs_names); + SetupElementSpecificAttributes ("head", head_attrs_names); string [] html_attrs_names = {"version", "xml:lang", "xmlns"}; - SetupElementSpecificAttributes ("html", html_attrs, html_attrs_names); + SetupElementSpecificAttributes ("html", html_attrs_names); string [] img_attrs_names = {"src", "alt", "width", "longdesc", "height"}; - SetupElementSpecificAttributes ("img", img_attrs, img_attrs_names); + SetupElementSpecificAttributes ("img", img_attrs_names); string [] input_attrs_names = {"size", "accesskey", "title", "name", "type", "disabled", "value", "src", "checked", "maxlength", "tabindex"}; - SetupElementSpecificAttributes ("input", input_attrs, input_attrs_names); + SetupElementSpecificAttributes ("input", input_attrs_names); string [] label_attrs_names = {"accesskey", "for"}; - SetupElementSpecificAttributes ("label", label_attrs, label_attrs_names); + SetupElementSpecificAttributes ("label", label_attrs_names); string [] li_attrs_names = {"value"}; - SetupElementSpecificAttributes ("li", li_attrs, li_attrs_names); + SetupElementSpecificAttributes ("li", li_attrs_names); string [] link_attrs_names = {"hreflang", "rev", "type", "charset", "rel", "href", "media"}; - SetupElementSpecificAttributes ("link", link_attrs, link_attrs_names); + SetupElementSpecificAttributes ("link", link_attrs_names); string [] meta_attrs_names = {"content", "name", "xml:lang", "http-equiv", "scheme"}; - SetupElementSpecificAttributes ("meta", meta_attrs, meta_attrs_names); + SetupElementSpecificAttributes ("meta", meta_attrs_names); string [] object_attrs_names = {"codebase", "classid", "data", "standby", "name", "type", "height", "archive", "declare", "width", "tabindex", "codetype"}; - SetupElementSpecificAttributes ("object", object_attrs, object_attrs_names); + SetupElementSpecificAttributes ("object", object_attrs_names); string [] ol_attrs_names = {"start"}; - SetupElementSpecificAttributes ("ol", ol_attrs, ol_attrs_names); + SetupElementSpecificAttributes ("ol", ol_attrs_names); string [] optgroup_attrs_names = {"label", "disabled"}; - SetupElementSpecificAttributes ("optgroup", optgroup_attrs, optgroup_attrs_names); + SetupElementSpecificAttributes ("optgroup", optgroup_attrs_names); string [] option_attrs_names = {"selected", "value"}; - SetupElementSpecificAttributes ("option", option_attrs, option_attrs_names); + SetupElementSpecificAttributes ("option", option_attrs_names); string [] param_attrs_names = {"id", "name", "valuetype", "value", "type"}; - SetupElementSpecificAttributes ("param", param_attrs, param_attrs_names); + SetupElementSpecificAttributes ("param", param_attrs_names); string [] pre_attrs_names = {"xml:space"}; - SetupElementSpecificAttributes ("pre", pre_attrs, pre_attrs_names); + SetupElementSpecificAttributes ("pre", pre_attrs_names); string [] q_attrs_names = {"cite"}; - SetupElementSpecificAttributes ("q", q_attrs, q_attrs_names); + SetupElementSpecificAttributes ("q", q_attrs_names); string [] select_attrs_names = {"name", "tabindex", "disabled", "multiple", "size"}; - SetupElementSpecificAttributes ("select", select_attrs, select_attrs_names); + SetupElementSpecificAttributes ("select", select_attrs_names); string [] style_attrs_names = {"xml:lang", "xml:space", "type", "title", "media"}; - SetupElementSpecificAttributes ("style", style_attrs, style_attrs_names); + SetupElementSpecificAttributes ("style", style_attrs_names); string [] table_attrs_names = {"width", "summary"}; - SetupElementSpecificAttributes ("table", table_attrs, table_attrs_names); + SetupElementSpecificAttributes ("table", table_attrs_names); string [] textarea_attrs_names = {"name", "cols", "accesskey", "tabindex", "rows"}; - SetupElementSpecificAttributes ("textarea", textarea_attrs, textarea_attrs_names); + SetupElementSpecificAttributes ("textarea", textarea_attrs_names); string [] td_and_th_attrs_names = {"headers", "align", "rowspan", "colspan", "axis", "scope", "abbr", "valign"}; - SetupElementSpecificAttributes ("td", td_attrs, td_and_th_attrs_names); - SetupElementSpecificAttributes ("th", th_attrs, td_and_th_attrs_names); + SetupElementSpecificAttributes ("td", td_and_th_attrs_names); + SetupElementSpecificAttributes ("th", td_and_th_attrs_names); string [] title_attrs_names = {"xml:lang"}; - SetupElementSpecificAttributes ("title", title_attrs, title_attrs_names); + SetupElementSpecificAttributes ("title", title_attrs_names); string [] tr_attrs_names = {"align", "valign"}; - SetupElementSpecificAttributes ("tr", tr_attrs, tr_attrs_names); + SetupElementSpecificAttributes ("tr", tr_attrs_names); } - void SetupElementSpecificAttributes (string elementName, Hashtable attrs, string [] attributesNames) + static void SetupElementSpecificAttributes (string elementName, string [] attributesNames) { - attrs = new Hashtable (attributesNames.Length); - InitElementAttributes (attrs, attributesNames); - element_specific_attrs.Add (elementName, attrs); + Hashtable attrs = new Hashtable (attributesNames.Length); + SetupHash (attrs, attributesNames); + default_element_specific_attrs.Add (elementName, attrs); } - void InitElementAttributes (Hashtable attrs, string [] attributesNames) + public XhtmlTextWriter (TextWriter writer) + : this (writer, DefaultTabString) + { + } + + public XhtmlTextWriter (TextWriter writer, string tabString) + : base (writer, tabString) { - SetupHash (attrs, attributesNames); } protected Hashtable CommonAttributes { - get { return common_attrs; } + get { + if (common_attrs == null) + common_attrs = (Hashtable) default_common_attrs.Clone (); + return common_attrs; + } } protected Hashtable ElementSpecificAttributes { - get { return element_specific_attrs; } + get { + if (element_specific_attrs == null) + element_specific_attrs = (Hashtable) default_element_specific_attrs.Clone (); + return element_specific_attrs; + } } protected Hashtable SuppressCommonAttributes { - get { return suppress_common_attrs; } + get { + if (suppress_common_attrs == null) + suppress_common_attrs = (Hashtable) default_suppress_common_attrs.Clone (); + return suppress_common_attrs; + } } public virtual void AddRecognizedAttribute (string elementName, string attributeName) { - Hashtable elem_attrs = (Hashtable) element_specific_attrs [elementName]; + Hashtable elem_attrs = (Hashtable) ElementSpecificAttributes [elementName]; if (elem_attrs == null) { Hashtable attrs = new Hashtable (); attrs.Add (attributeName, true); - element_specific_attrs.Add (elementName, attrs); + ElementSpecificAttributes.Add (elementName, attrs); } else elem_attrs.Add (attributeName, true); } @@ -243,7 +227,7 @@ namespace System.Web.UI { public virtual void RemoveRecognizedAttribute (string elementName, string attributeName) { - Hashtable elem_attrs = (Hashtable) element_specific_attrs [elementName]; + Hashtable elem_attrs = (Hashtable) ElementSpecificAttributes [elementName]; if (elem_attrs != null) elem_attrs.Remove (attributeName); @@ -267,7 +251,7 @@ namespace System.Web.UI { { // I tested every possible value of HtmlTextWriterAttribute // and the MS implementation always throws ArgumentNullException - return (bool) attr_render [null]; + throw new ArgumentNullException (); } protected override bool OnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key) @@ -278,5 +262,3 @@ namespace System.Web.UI { } } } - -#endif