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;
34 using System.Web.Util;
36 namespace System.Web.Compilation
46 public TagAttributes ()
49 keys = new ArrayList ();
50 values = new ArrayList ();
56 atts_hash = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
58 atts_hash = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
59 CaseInsensitiveComparer.DefaultInvariant);
61 for (int i = 0; i < keys.Count; i++) {
62 CheckServerKey (keys [i]);
63 atts_hash.Add (keys [i], values [i]);
70 public bool IsRunAtServer ()
75 public void Add (object key, object value)
77 if (key != null && value != null &&
78 0 == String.Compare ((string) key, "runat", true)) {
79 if (0 != String.Compare ((string) value, "server", true))
80 throw new HttpException ("runat attribute must have a 'server' value");
83 return; // ignore duplicate runat="server"
89 value = HttpUtility.HtmlDecode (value.ToString ());
93 if (atts_hash.ContainsKey (key))
94 throw new HttpException ("Tag contains duplicated '" + key +
96 atts_hash.Add (key, value);
103 public ICollection Keys
105 get { return (got_hashed ? atts_hash.Keys : keys); }
108 public ICollection Values
110 get { return (got_hashed ? atts_hash.Values : values); }
113 int CaseInsensitiveSearch (string key)
115 // Hope not to have many attributes when the tag is not a server tag...
116 for (int i = 0; i < keys.Count; i++){
117 if (0 == String.Compare ((string) keys [i], key, true))
123 public object this [object key]
127 return atts_hash [key];
129 int idx = CaseInsensitiveSearch ((string) key);
138 CheckServerKey (key);
139 atts_hash [key] = value;
141 int idx = CaseInsensitiveSearch ((string) key);
149 get { return (got_hashed ? atts_hash.Count : keys.Count);}
152 public bool IsDataBound (string att)
154 if (att == null || !got_hashed)
157 return (StrUtils.StartsWith (att, "<%#") && StrUtils.EndsWith (att, "%>"));
160 public Hashtable GetDictionary (string key)
165 if (tmp_hash == null)
167 tmp_hash = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
169 tmp_hash = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
170 CaseInsensitiveComparer.DefaultInvariant);
174 for (int i = keys.Count - 1; i >= 0; i--)
175 if (key == null || String.Compare (key, (string) keys [i], true) == 0)
176 tmp_hash [keys [i]] = values [i];
181 public override string ToString ()
183 StringBuilder result = new StringBuilder ();
185 foreach (string key in Keys){
187 value = this [key] as string;
189 result.AppendFormat ("=\"{0}\"", value);
194 if (result.Length > 0 && result [result.Length - 1] == ' ')
197 return result.ToString ();
200 void CheckServerKey (object key)
202 if (key == null || ((string)key).Length == 0)
203 throw new HttpException ("The server tag is not well formed.");