1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
//
// XhtmlTextWriter.cs
//
// Author:
// Cesar Lopez Nataren <cnataren@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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
using System.Collections;
namespace System.Web.UI
{
public class XhtmlTextWriter : HtmlTextWriter
{
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;
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 ();
}
static void SetupHash (Hashtable hash, string [] values)
{
foreach (string str in values)
hash.Add (str, true);
}
static string [] DefaultCommonAttributes = {
"class",
"id",
"title",
"xml:lang"
};
//
// XHTML elements whose CommonAttributes are supressed
//
static string [] DefaultSuppressCommonAttributes = {
"base",
"meta",
"br",
"head",
"title",
"html",
"style"
};
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_names);
string [] base_attrs_names = {"href"};
SetupElementSpecificAttributes ("base", base_attrs_names);
string [] blockquote_attrs_names = {"cite"};
SetupElementSpecificAttributes ("blockquote", blockquote_attrs_names);
string [] br_attrs_names = {"id", "class", "title"};
SetupElementSpecificAttributes ("br", br_attrs_names);
string [] form_attrs_names = {"action", "method", "enctype"};
SetupElementSpecificAttributes ("form", form_attrs_names);
string [] head_attrs_names = {"xml:lang"};
SetupElementSpecificAttributes ("head", head_attrs_names);
string [] html_attrs_names = {"version", "xml:lang", "xmlns"};
SetupElementSpecificAttributes ("html", html_attrs_names);
string [] img_attrs_names = {"src", "alt", "width", "longdesc", "height"};
SetupElementSpecificAttributes ("img", img_attrs_names);
string [] input_attrs_names = {"size", "accesskey", "title", "name", "type", "disabled",
"value", "src", "checked", "maxlength", "tabindex"};
SetupElementSpecificAttributes ("input", input_attrs_names);
string [] label_attrs_names = {"accesskey", "for"};
SetupElementSpecificAttributes ("label", label_attrs_names);
string [] li_attrs_names = {"value"};
SetupElementSpecificAttributes ("li", li_attrs_names);
string [] link_attrs_names = {"hreflang", "rev", "type", "charset", "rel", "href", "media"};
SetupElementSpecificAttributes ("link", link_attrs_names);
string [] meta_attrs_names = {"content", "name", "xml:lang", "http-equiv", "scheme"};
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_names);
string [] ol_attrs_names = {"start"};
SetupElementSpecificAttributes ("ol", ol_attrs_names);
string [] optgroup_attrs_names = {"label", "disabled"};
SetupElementSpecificAttributes ("optgroup", optgroup_attrs_names);
string [] option_attrs_names = {"selected", "value"};
SetupElementSpecificAttributes ("option", option_attrs_names);
string [] param_attrs_names = {"id", "name", "valuetype", "value", "type"};
SetupElementSpecificAttributes ("param", param_attrs_names);
string [] pre_attrs_names = {"xml:space"};
SetupElementSpecificAttributes ("pre", pre_attrs_names);
string [] q_attrs_names = {"cite"};
SetupElementSpecificAttributes ("q", q_attrs_names);
string [] select_attrs_names = {"name", "tabindex", "disabled", "multiple", "size"};
SetupElementSpecificAttributes ("select", select_attrs_names);
string [] style_attrs_names = {"xml:lang", "xml:space", "type", "title", "media"};
SetupElementSpecificAttributes ("style", style_attrs_names);
string [] table_attrs_names = {"width", "summary"};
SetupElementSpecificAttributes ("table", table_attrs_names);
string [] textarea_attrs_names = {"name", "cols", "accesskey", "tabindex", "rows"};
SetupElementSpecificAttributes ("textarea", textarea_attrs_names);
string [] td_and_th_attrs_names = {"headers", "align", "rowspan", "colspan", "axis",
"scope", "abbr", "valign"};
SetupElementSpecificAttributes ("td", td_and_th_attrs_names);
SetupElementSpecificAttributes ("th", td_and_th_attrs_names);
string [] title_attrs_names = {"xml:lang"};
SetupElementSpecificAttributes ("title", title_attrs_names);
string [] tr_attrs_names = {"align", "valign"};
SetupElementSpecificAttributes ("tr", tr_attrs_names);
}
static void SetupElementSpecificAttributes (string elementName, string [] attributesNames)
{
Hashtable attrs = new Hashtable (attributesNames.Length);
SetupHash (attrs, attributesNames);
default_element_specific_attrs.Add (elementName, attrs);
}
public XhtmlTextWriter (TextWriter writer)
: this (writer, DefaultTabString)
{
}
public XhtmlTextWriter (TextWriter writer, string tabString)
: base (writer, tabString)
{
}
protected Hashtable CommonAttributes {
get {
if (common_attrs == null)
common_attrs = (Hashtable) default_common_attrs.Clone ();
return common_attrs;
}
}
protected Hashtable ElementSpecificAttributes {
get {
if (element_specific_attrs == null)
element_specific_attrs = (Hashtable) default_element_specific_attrs.Clone ();
return element_specific_attrs;
}
}
protected Hashtable SuppressCommonAttributes {
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) ElementSpecificAttributes [elementName];
if (elem_attrs == null) {
Hashtable attrs = new Hashtable ();
attrs.Add (attributeName, true);
ElementSpecificAttributes.Add (elementName, attrs);
} else
elem_attrs.Add (attributeName, true);
}
public override bool IsValidFormAttribute (string attributeName)
{
return attributeName == "action" || attributeName == "method" || attributeName == "enctype";
}
public virtual void RemoveRecognizedAttribute (string elementName, string attributeName)
{
Hashtable elem_attrs = (Hashtable) ElementSpecificAttributes [elementName];
if (elem_attrs != null)
elem_attrs.Remove (attributeName);
}
public virtual void SetDocType (XhtmlMobileDocType docType)
{
//doc_type = docType;
}
// writes <br/>
public override void WriteBreak ()
{
string tag = GetTagName (HtmlTextWriterTag.Br);
WriteBeginTag (tag);
Write (SlashChar);
Write (TagRightChar);
}
protected override bool OnAttributeRender (string name, string value, HtmlTextWriterAttribute key)
{
// I tested every possible value of HtmlTextWriterAttribute
// and the MS implementation always throws ArgumentNullException
throw new ArgumentNullException ();
}
protected override bool OnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
{
// I tested every possible value of HtmlTextWriterStyle
// and the MS implementation always returned false. Sigh
return false;
}
}
}
|