2
// System.Web.Compilation.TagAttributes
5
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
7
// (C) 2003 Ximian, Inc (http://www.ximian.com)
11
// Permission is hereby granted, free of charge, to any person obtaining
12
// a copy of this software and associated documentation files (the
13
// "Software"), to deal in the Software without restriction, including
14
// without limitation the rights to use, copy, modify, merge, publish,
15
// distribute, sublicense, and/or sell copies of the Software, and to
16
// permit persons to whom the Software is furnished to do so, subject to
17
// the following conditions:
19
// The above copyright notice and this permission notice shall be
20
// included in all copies or substantial portions of the Software.
22
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
using System.Collections;
35
using MonoDevelop.AspNet.Parser.Internal;
37
namespace MonoDevelop.AspNet.Parser.Dom
39
public class TagAttributes
47
public TagAttributes ()
50
keys = new ArrayList ();
51
values = new ArrayList ();
56
atts_hash = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
57
for (int i = 0; i < keys.Count; i++) {
58
CheckServerKey (keys [i]);
59
atts_hash.Add (keys [i], values [i]);
66
public bool IsRunAtServer ()
71
public void Add (object key, object value)
73
if (key != null && value != null &&
74
0 == String.Compare ((string) key, "runat", true)) {
75
if (0 != String.Compare ((string) value, "server", true))
76
throw new HttpException ("runat attribute must have a 'server' value");
79
return; // ignore duplicate runat="server"
85
value = HttpUtility.HtmlDecode (value.ToString ());
89
if (atts_hash.ContainsKey (key))
90
throw new HttpException ("Tag contains duplicated '" + key +
92
atts_hash.Add (key, value);
99
public ICollection Keys
101
get { return (got_hashed ? atts_hash.Keys : keys); }
104
public ICollection Values
106
get { return (got_hashed ? atts_hash.Values : values); }
109
private int CaseInsensitiveSearch (string key)
111
// Hope not to have many attributes when the tag is not a server tag...
112
for (int i = 0; i < keys.Count; i++){
113
if (0 == String.Compare ((string) keys [i], key, true))
119
public object this [object key]
123
return atts_hash [key];
125
int idx = CaseInsensitiveSearch ((string) key);
134
CheckServerKey (key);
135
atts_hash [key] = value;
137
int idx = CaseInsensitiveSearch ((string) key);
145
get { return (got_hashed ? atts_hash.Count : keys.Count);}
148
public bool IsDataBound (string att)
150
if (att == null || !got_hashed)
153
return (StrUtils.StartsWith (att, "<%#") && StrUtils.EndsWith (att, "%>"));
156
public Hashtable GetDictionary (string key)
161
if (tmp_hash == null)
162
tmp_hash = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
165
for (int i = keys.Count - 1; i >= 0; i--)
166
if (key == null || String.Compare (key, (string) keys [i], true) == 0)
167
tmp_hash [keys [i]] = values [i];
172
public override string ToString ()
174
StringBuilder result = new StringBuilder ();
176
foreach (string key in Keys){
178
value = this [key] as string;
180
result.AppendFormat ("=\"{0}\"", value);
185
if (result.Length > 0 && result [result.Length - 1] == ' ')
188
return result.ToString ();
191
void CheckServerKey (object key)
193
if (key == null || ((string)key).Length == 0)
194
throw new HttpException ("The server tag is not well formed.");