File: ParsedAttributeCollection.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (323 lines) | stat: -rw-r--r-- 10,493 bytes parent folder | download | duplicates (7)
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//------------------------------------------------------------------------------
// <copyright file="ParsedAttributeCollection.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI {
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Globalization;
    using System.Web.Util;


    /// <devdoc>
    /// Contains parsed attributes organized by filter.
    /// The IDictionary implementation uses the combination of all filters using filter:attrName as the attribute names
    /// </devdoc>
    internal sealed class ParsedAttributeCollection : IDictionary {
        private IDictionary _filterTable;
        private IDictionary _allFiltersDictionary;
        private IDictionary<String, Pair> _attributeValuePositionInfo;

        internal ParsedAttributeCollection() {
            _filterTable = new ListDictionary(StringComparer.OrdinalIgnoreCase);
        }

        /// <devdoc>
        /// Returns the combination of all filters using filter:attrName as the attribute names
        /// </devdoc>
        private IDictionary AllFiltersDictionary {
            get {
                if (_allFiltersDictionary == null) {
                    _allFiltersDictionary = new ListDictionary(StringComparer.OrdinalIgnoreCase);
                    foreach (FilteredAttributeDictionary fac in _filterTable.Values) {
                        foreach (DictionaryEntry entry in fac) {
                            Debug.Assert(entry.Key != null);
                            _allFiltersDictionary[Util.CreateFilteredName(fac.Filter, entry.Key.ToString())] = entry.Value;
                        }
                    }
                }

                return _allFiltersDictionary;
            }
        }


        /// <devdoc>
        /// Adds a filtered attribute
        /// </devdoc>
        public void AddFilteredAttribute(string filter, string name, string value) {
            if (String.IsNullOrEmpty(name)) {
                throw ExceptionUtil.ParameterNullOrEmpty("name");
            }

            if (value == null) {
                throw new ArgumentNullException("value");
            }

            if (filter == null) {
                filter = String.Empty;
            }

            if (_allFiltersDictionary != null) {
                _allFiltersDictionary.Add(Util.CreateFilteredName(filter, name), value);
            }

            FilteredAttributeDictionary filteredAttributes = (FilteredAttributeDictionary)_filterTable[filter];
            if (filteredAttributes == null) {
                filteredAttributes = new FilteredAttributeDictionary(this, filter);
                _filterTable[filter] = filteredAttributes;
            }
            filteredAttributes.Data.Add(name, value);
        }

        /// <summary>
        /// This adds an entry for the attribute name and the starting column of attribute value within the text.
        /// This information is later used for generating line pragmas for intellisense to work.
        /// </summary>
        /// <param name="name">Name of the attribute.</param>
        /// <param name="line">The line number where the attribute value expression is present.</param>
        /// <param name="column">The column value where the attribute value expression begins. Note that this is actually after the attribute name itself.</param>
        public void AddAttributeValuePositionInformation(string name, int line, int column) {
            Debug.Assert(!String.IsNullOrEmpty(name));
            Pair pair = new Pair(line, column);
            AttributeValuePositionsDictionary[name] = pair;
        }

        public IDictionary<String, Pair> AttributeValuePositionsDictionary {
            get {
                if (_attributeValuePositionInfo == null) {
                    _attributeValuePositionInfo = new Dictionary<String, Pair>(StringComparer.OrdinalIgnoreCase);
                }
                return _attributeValuePositionInfo;
            }
        }



        /// <devdoc>
        /// Clears all attributes from the specified filter
        /// </devdoc>
        public void ClearFilter(string filter) {
            if (filter == null) {
                filter = String.Empty;
            }

            if (_allFiltersDictionary != null) {
                ArrayList removeList = new ArrayList();
                foreach (string key in _allFiltersDictionary.Keys) {
                    string attrName;
                    string currentFilter = Util.ParsePropertyDeviceFilter(key, out attrName);
                    if (StringUtil.EqualsIgnoreCase(currentFilter, filter)) {
                        removeList.Add(key);
                    }
                }

                foreach (string key in removeList) {
                    _allFiltersDictionary.Remove(key);
                }
            }

            _filterTable.Remove(filter);
        }


        /// <devdoc>
        /// Gets the collection of FilteredAttributeDictionaries used by this collection.
        /// </devdoc>
        public ICollection GetFilteredAttributeDictionaries() {
            return _filterTable.Values;
        }


        /// <devdoc>
        /// Removes the specified attribute from the specified filter.
        /// </devdoc>
        public void RemoveFilteredAttribute(string filter, string name) {
            if (String.IsNullOrEmpty(name)) {
                throw ExceptionUtil.ParameterNullOrEmpty("name");
            }

            if (filter == null) {
                filter = String.Empty;
            }

            if (_allFiltersDictionary != null) {
                _allFiltersDictionary.Remove(Util.CreateFilteredName(filter, name));
            }

            FilteredAttributeDictionary filteredAttributes = (FilteredAttributeDictionary)_filterTable[filter];
            if (filteredAttributes != null) {
                filteredAttributes.Data.Remove(name);
            }
        }


        /// <devdoc>
        /// Replaces the specified attribute's value from the specified filter.
        /// </devdoc>
        public void ReplaceFilteredAttribute(string filter, string name, string value) {
            if (String.IsNullOrEmpty(name)) {
                throw ExceptionUtil.ParameterNullOrEmpty("name");
            }

            if (filter == null) {
                filter = String.Empty;
            }

            if (_allFiltersDictionary != null) {
                _allFiltersDictionary[Util.CreateFilteredName(filter, name)] = value;
            }

            FilteredAttributeDictionary filteredAttributes = (FilteredAttributeDictionary)_filterTable[filter];
            if (filteredAttributes == null) {
                filteredAttributes = new FilteredAttributeDictionary(this, filter);
                _filterTable[filter] = filteredAttributes;
            }
            filteredAttributes.Data[name] = value;
        }

        #region IDictionary implementation

        /// <internalonly/>
        bool IDictionary.IsFixedSize {
            get {
                return false;
            }
        }


        /// <internalonly/>
        bool IDictionary.IsReadOnly {
            get {
                return false;
            }
        }


        /// <internalonly/>
        object IDictionary.this[object key] {
            get {
                return AllFiltersDictionary[key];
            }
            set {
                if (key == null) {
                    throw new ArgumentNullException("key");
                }

                string attrName;
                string filter = Util.ParsePropertyDeviceFilter(key.ToString(), out attrName);

                ReplaceFilteredAttribute(filter, attrName, value.ToString());
            }
        }


        /// <internalonly/>
        ICollection IDictionary.Keys {
            get {
                return AllFiltersDictionary.Keys;
            }
        }


        /// <internalonly/>
        ICollection IDictionary.Values {
            get {
                return AllFiltersDictionary.Values;
            }
        }


        /// <internalonly/>
        void IDictionary.Add(object key, object value) {
            if (key == null) {
                throw new ArgumentNullException("key");
            }

            if (value == null) {
                value = String.Empty;
            }

            string attrName;
            string filter = Util.ParsePropertyDeviceFilter(key.ToString(), out attrName);

            AddFilteredAttribute(filter, attrName, value.ToString());
        }


        /// <internalonly/>
        bool IDictionary.Contains(object key) {
            return AllFiltersDictionary.Contains(key);
        }


        /// <internalonly/>
        void IDictionary.Clear() {
            AllFiltersDictionary.Clear();
            _filterTable.Clear();
        }


        /// <internalonly/>
        IDictionaryEnumerator IDictionary.GetEnumerator() {
            return AllFiltersDictionary.GetEnumerator();
        }


        /// <internalonly/>
        void IDictionary.Remove(object key) {
            if (key == null) {
                throw new ArgumentNullException("key");
            }

            string attrName;
            string filter = Util.ParsePropertyDeviceFilter(key.ToString(), out attrName);

            RemoveFilteredAttribute(filter, attrName);
        }
        #endregion IDictionary implementation

        #region ICollection implementation

        /// <internalonly/>
        int ICollection.Count {
            get {
                return AllFiltersDictionary.Count;
            }
        }


        /// <internalonly/>
        bool ICollection.IsSynchronized {
            get {
                return ((ICollection)AllFiltersDictionary).IsSynchronized;
            }
        }


        /// <internalonly/>
        object ICollection.SyncRoot {
            get {
                return AllFiltersDictionary.SyncRoot;
            }
        }


        /// <internalonly/>
        void ICollection.CopyTo(Array array, int index) {
            AllFiltersDictionary.CopyTo(array, index);
        }


        /// <internalonly/>
        IEnumerator IEnumerable.GetEnumerator() {
            return AllFiltersDictionary.GetEnumerator();
        }
        #endregion ICollection implementation
    }
}