| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Xml; |
| | | 5 | | using System; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.IdentityModel |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Class wraps a given reader and delegates all XmlDictionaryReader calls |
| | | 11 | | /// to the inner wrapped reader. |
| | | 12 | | /// </summary> |
| | | 13 | | public class DelegatingXmlDictionaryReader : XmlDictionaryReader |
| | | 14 | | { |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Initializes a new instance of <see cref="DelegatingXmlDictionaryWriter" /> |
| | | 18 | | /// </summary> |
| | 0 | 19 | | protected DelegatingXmlDictionaryReader() |
| | | 20 | | { |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes the Inner reader that this instance wraps. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="innerReader">XmlDictionaryReader to wrap.</param> |
| | | 27 | | protected void InitializeInnerReader(XmlDictionaryReader innerReader) |
| | | 28 | | { |
| | 0 | 29 | | if (innerReader == null) |
| | | 30 | | { |
| | 0 | 31 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(innerReader)); |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | InnerReader = innerReader; |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the wrapped inner reader. |
| | | 39 | | /// </summary> |
| | 0 | 40 | | protected XmlDictionaryReader InnerReader { get; private set; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets the value of the attribute with the specified index. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="i">index of the attribute.</param> |
| | | 46 | | /// <returns>Attribute value at the specified index.</returns> |
| | | 47 | | public override string this[int i] |
| | | 48 | | { |
| | 0 | 49 | | get { return InnerReader[i]; } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets the value of the attribute with the specified System.Xml.XmlReader.Name. |
| | | 54 | | /// </summary> |
| | | 55 | | /// <param name="name">The qualified name of the attribute.</param> |
| | | 56 | | /// <returns>The value of the specified attribute. If the attribute is not found, |
| | | 57 | | /// null is returned.</returns> |
| | | 58 | | public override string this[string name] |
| | | 59 | | { |
| | 0 | 60 | | get { return InnerReader[name]; } |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Gets the value of the attribute with the specified System.Xml.XmlReader.LocalName and |
| | | 65 | | /// System.Xml.XmlReader.NamespaceURI from the wrapped reader. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <param name="name">The local name of the attribute.</param> |
| | | 68 | | /// <param name="namespaceURI">The namespace URI of the attribute.</param> |
| | | 69 | | /// <returns>The value of the specified attribute. If the attribute is not found, |
| | | 70 | | /// null is returned.</returns> |
| | | 71 | | public override string this[string name, string namespaceURI] |
| | | 72 | | { |
| | 0 | 73 | | get { return InnerReader[name, namespaceURI]; } |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Gets the number of Attributes at the current reader position. |
| | | 78 | | /// </summary> |
| | | 79 | | public override int AttributeCount |
| | | 80 | | { |
| | 0 | 81 | | get { return InnerReader.AttributeCount; } |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Gets the base Uri of the current node. |
| | | 86 | | /// </summary> |
| | | 87 | | public override string BaseURI |
| | | 88 | | { |
| | 0 | 89 | | get { return InnerReader.BaseURI; } |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | /// <summary> |
| | | 93 | | /// Gets the Depth of the current node. |
| | | 94 | | /// </summary> |
| | | 95 | | public override int Depth |
| | | 96 | | { |
| | 0 | 97 | | get { return InnerReader.Depth; } |
| | | 98 | | } |
| | | 99 | | |
| | | 100 | | /// <summary> |
| | | 101 | | /// Gets a value indicating if reader is positioned at the end of the stream. |
| | | 102 | | /// </summary> |
| | | 103 | | public override bool EOF |
| | | 104 | | { |
| | 0 | 105 | | get { return InnerReader.EOF; } |
| | | 106 | | } |
| | | 107 | | |
| | | 108 | | /// <summary> |
| | | 109 | | /// Gets a value indicating if the current node can have a |
| | | 110 | | /// System.Xml.XmlReader.Value. |
| | | 111 | | /// </summary> |
| | | 112 | | public override bool HasValue |
| | | 113 | | { |
| | 0 | 114 | | get { return InnerReader.HasValue; } |
| | | 115 | | } |
| | | 116 | | |
| | | 117 | | /// <summary> |
| | | 118 | | /// Gets a value indicating if the current node is an attribute that |
| | | 119 | | /// was generated from the default value defined in the DTD or Schema. |
| | | 120 | | /// </summary> |
| | | 121 | | public override bool IsDefault |
| | | 122 | | { |
| | 0 | 123 | | get { return InnerReader.IsDefault; } |
| | | 124 | | } |
| | | 125 | | |
| | | 126 | | /// <summary> |
| | | 127 | | /// Gets a value indicating if the current node. |
| | | 128 | | /// </summary> |
| | | 129 | | public override bool IsEmptyElement |
| | | 130 | | { |
| | 0 | 131 | | get { return InnerReader.IsEmptyElement; } |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | /// <summary> |
| | | 135 | | /// Gets the local name of the current node. |
| | | 136 | | /// </summary> |
| | | 137 | | public override string LocalName |
| | | 138 | | { |
| | 0 | 139 | | get { return InnerReader.LocalName; } |
| | | 140 | | } |
| | | 141 | | |
| | | 142 | | /// <summary> |
| | | 143 | | /// Gets the qualified name of the current node. |
| | | 144 | | /// </summary> |
| | | 145 | | public override string Name |
| | | 146 | | { |
| | 0 | 147 | | get { return InnerReader.Name; } |
| | | 148 | | } |
| | | 149 | | |
| | | 150 | | /// <summary> |
| | | 151 | | /// Gets the namespace URI of the current node. |
| | | 152 | | /// </summary> |
| | | 153 | | public override string NamespaceURI |
| | | 154 | | { |
| | 0 | 155 | | get { return InnerReader.NamespaceURI; } |
| | | 156 | | } |
| | | 157 | | |
| | | 158 | | /// <summary> |
| | | 159 | | /// Gets the System.Xml.XmlNameTable associated with this instance. |
| | | 160 | | /// </summary> |
| | | 161 | | public override XmlNameTable NameTable |
| | | 162 | | { |
| | 0 | 163 | | get { return InnerReader.NameTable; } |
| | | 164 | | } |
| | | 165 | | |
| | | 166 | | /// <summary> |
| | | 167 | | /// Gets the type of the current node. |
| | | 168 | | /// </summary> |
| | | 169 | | public override XmlNodeType NodeType |
| | | 170 | | { |
| | 0 | 171 | | get { return InnerReader.NodeType; } |
| | | 172 | | } |
| | | 173 | | |
| | | 174 | | /// <summary> |
| | | 175 | | /// Gets the prefix of the current node. |
| | | 176 | | /// </summary> |
| | | 177 | | public override string Prefix |
| | | 178 | | { |
| | 0 | 179 | | get { return InnerReader.Prefix; } |
| | | 180 | | } |
| | | 181 | | |
| | | 182 | | /// <summary> |
| | | 183 | | /// Gets the quotation mark character used to enclose the attribute node. (" or ') |
| | | 184 | | /// </summary> |
| | | 185 | | public override char QuoteChar |
| | | 186 | | { |
| | 0 | 187 | | get { return InnerReader.QuoteChar; } |
| | | 188 | | } |
| | | 189 | | |
| | | 190 | | /// <summary> |
| | | 191 | | /// Gets the System.Xml.ReadState of the reader. |
| | | 192 | | /// </summary> |
| | | 193 | | public override ReadState ReadState |
| | | 194 | | { |
| | 0 | 195 | | get { return InnerReader.ReadState; } |
| | | 196 | | } |
| | | 197 | | |
| | | 198 | | /// <summary> |
| | | 199 | | /// Gets the text value of the current node. |
| | | 200 | | /// </summary> |
| | | 201 | | public override string Value |
| | | 202 | | { |
| | 0 | 203 | | get { return InnerReader.Value; } |
| | | 204 | | } |
| | | 205 | | |
| | | 206 | | /// <summary> |
| | | 207 | | /// Gets the Common Language Runtime (CLR) type of the curent node. |
| | | 208 | | /// </summary> |
| | | 209 | | public override Type ValueType |
| | | 210 | | { |
| | 0 | 211 | | get { return InnerReader.ValueType; } |
| | | 212 | | } |
| | | 213 | | |
| | | 214 | | /// <summary> |
| | | 215 | | /// Gets the xml:lang scope. |
| | | 216 | | /// </summary> |
| | | 217 | | public override string XmlLang |
| | | 218 | | { |
| | 0 | 219 | | get { return InnerReader.XmlLang; } |
| | | 220 | | } |
| | | 221 | | |
| | | 222 | | /// <summary> |
| | | 223 | | /// Gets the current xml:space scope. If no xml:space scope exists, this property |
| | | 224 | | /// defaults to XmlSpace.None. |
| | | 225 | | /// </summary> |
| | | 226 | | public override XmlSpace XmlSpace |
| | | 227 | | { |
| | 0 | 228 | | get { return InnerReader.XmlSpace; } |
| | | 229 | | } |
| | | 230 | | |
| | | 231 | | /// <summary> |
| | | 232 | | /// Closes the reader and changes the System.Xml.XmlReader.ReadState |
| | | 233 | | /// to Closed. |
| | | 234 | | /// </summary> |
| | | 235 | | public override void Close() |
| | | 236 | | { |
| | 0 | 237 | | InnerReader.Close(); |
| | 0 | 238 | | } |
| | | 239 | | |
| | | 240 | | /// <summary> |
| | | 241 | | /// Gets the value of the attribute at the given index. |
| | | 242 | | /// </summary> |
| | | 243 | | /// <param name="i">The index of the attribute. The index is 0 based index.</param> |
| | | 244 | | /// <returns>The value of the attribute at the specified index.</returns> |
| | | 245 | | /// <remarks>The method does not move the reader position.</remarks> |
| | | 246 | | public override string GetAttribute(int i) |
| | | 247 | | { |
| | 0 | 248 | | return InnerReader.GetAttribute(i); |
| | | 249 | | } |
| | | 250 | | |
| | | 251 | | /// <summary> |
| | | 252 | | /// Gets the value of the attribute with the given name. |
| | | 253 | | /// </summary> |
| | | 254 | | /// <param name="name">The qualified name of the attribute.</param> |
| | | 255 | | /// <returns>The value of the attribute. If the attribute is not found null |
| | | 256 | | /// is returned.</returns> |
| | | 257 | | /// <remarks>The method does not move the reader position.</remarks> |
| | | 258 | | public override string GetAttribute(string name) |
| | | 259 | | { |
| | 0 | 260 | | return InnerReader.GetAttribute(name); |
| | | 261 | | } |
| | | 262 | | |
| | | 263 | | /// <summary> |
| | | 264 | | /// Gets the value of the attribute with the given name and namespace Uri. |
| | | 265 | | /// </summary> |
| | | 266 | | /// <param name="name">The local name of the attribute.</param> |
| | | 267 | | /// <param name="namespaceURI">The namespace of the attribute.</param> |
| | | 268 | | /// <returns>The value of the attribute. If the attribute is not found |
| | | 269 | | /// null is returned.</returns> |
| | | 270 | | /// <remarks>The method does not move the reader.</remarks> |
| | | 271 | | public override string GetAttribute(string name, string namespaceURI) |
| | | 272 | | { |
| | 0 | 273 | | return InnerReader.GetAttribute(name, namespaceURI); |
| | | 274 | | } |
| | | 275 | | |
| | | 276 | | /// <summary> |
| | | 277 | | /// Resolves a namespace prefix in the current element scope. |
| | | 278 | | /// </summary> |
| | | 279 | | /// <param name="prefix">Prefix whose namespace Uri to be resolved.</param> |
| | | 280 | | /// <returns>The namespace Uri to which the prefix matches or null if no matching |
| | | 281 | | /// prefix is found.</returns> |
| | | 282 | | public override string LookupNamespace(string prefix) |
| | | 283 | | { |
| | 0 | 284 | | return InnerReader.LookupNamespace(prefix); |
| | | 285 | | } |
| | | 286 | | |
| | | 287 | | /// <summary> |
| | | 288 | | /// Moves to the attribute with the specified index. |
| | | 289 | | /// </summary> |
| | | 290 | | /// <param name="i">The index of the attribute.</param> |
| | | 291 | | public override void MoveToAttribute(int i) |
| | | 292 | | { |
| | 0 | 293 | | InnerReader.MoveToAttribute(i); |
| | 0 | 294 | | } |
| | | 295 | | |
| | | 296 | | /// <summary> |
| | | 297 | | /// Moves to the attribute with the given local name. |
| | | 298 | | /// </summary> |
| | | 299 | | /// <param name="name">The qualified name of the attribute.</param> |
| | | 300 | | /// <returns>true if the attribute is found; otherwise, false.</returns> |
| | | 301 | | public override bool MoveToAttribute(string name) |
| | | 302 | | { |
| | 0 | 303 | | return InnerReader.MoveToAttribute(name); |
| | | 304 | | } |
| | | 305 | | |
| | | 306 | | /// <summary> |
| | | 307 | | /// Moves to the attribute with the specified System.Xml.XmlReader.LocalName and |
| | | 308 | | /// System.Xml.XmlReader.NamespaceURI. |
| | | 309 | | /// </summary> |
| | | 310 | | /// <param name="name">The local name of the attribute.</param> |
| | | 311 | | /// <param name="ns">The namespace URI of the attribute.</param> |
| | | 312 | | /// <returns>true if the attribute is found; otherwise, false.</returns> |
| | | 313 | | public override bool MoveToAttribute(string name, string ns) |
| | | 314 | | { |
| | 0 | 315 | | return InnerReader.MoveToAttribute(name, ns); |
| | | 316 | | } |
| | | 317 | | |
| | | 318 | | /// <summary> |
| | | 319 | | /// Moves to a node of type Element. |
| | | 320 | | /// </summary> |
| | | 321 | | /// <returns>true if the reader is positioned on an element else false</returns> |
| | | 322 | | public override bool MoveToElement() |
| | | 323 | | { |
| | 0 | 324 | | return InnerReader.MoveToElement(); |
| | | 325 | | } |
| | | 326 | | |
| | | 327 | | /// <summary> |
| | | 328 | | /// Moves to the first attribute. |
| | | 329 | | /// </summary> |
| | | 330 | | /// <returns>Returns true if the reader is positioned at a attribute else false.</returns> |
| | | 331 | | /// <remarks>When returning false the reader position will not be changed.</remarks> |
| | | 332 | | public override bool MoveToFirstAttribute() |
| | | 333 | | { |
| | 0 | 334 | | return InnerReader.MoveToFirstAttribute(); |
| | | 335 | | } |
| | | 336 | | |
| | | 337 | | /// <summary> |
| | | 338 | | /// Moves the reader to the next attribute. |
| | | 339 | | /// </summary> |
| | | 340 | | /// <returns>Returns true if the reader is positioned at an attribute else false.</returns> |
| | | 341 | | /// <remarks>When returning false the reader position will not be changed.</remarks> |
| | | 342 | | public override bool MoveToNextAttribute() |
| | | 343 | | { |
| | 0 | 344 | | return InnerReader.MoveToNextAttribute(); |
| | | 345 | | } |
| | | 346 | | |
| | | 347 | | /// <summary> |
| | | 348 | | /// Reads the next node from the stream. |
| | | 349 | | /// </summary> |
| | | 350 | | /// <returns>true if the next node was read successfully.</returns> |
| | | 351 | | public override bool Read() |
| | | 352 | | { |
| | 0 | 353 | | return InnerReader.Read(); |
| | | 354 | | } |
| | | 355 | | |
| | | 356 | | /// <summary> |
| | | 357 | | /// Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes. |
| | | 358 | | /// </summary> |
| | | 359 | | /// <returns>true if there are nodes to return.false if the reader is not positioned on |
| | | 360 | | /// an attribute node when the initial call is made or if all the attribute values |
| | | 361 | | /// have been read.</returns> |
| | | 362 | | public override bool ReadAttributeValue() |
| | | 363 | | { |
| | 0 | 364 | | return InnerReader.ReadAttributeValue(); |
| | | 365 | | } |
| | | 366 | | |
| | | 367 | | /// <summary> |
| | | 368 | | /// Reads the content and returns the Base64 decoded binary bytes. |
| | | 369 | | /// </summary> |
| | | 370 | | /// <param name="buffer">The buffer into which to copy the resulting text. This value cannot be null.</param> |
| | | 371 | | /// <param name="index">The offset into the buffer where to start copying the result.</param> |
| | | 372 | | /// <param name="count">The maximum number of bytes to copy into the buffer.</param> |
| | | 373 | | /// <returns>The number of bytes written to the buffer.</returns> |
| | | 374 | | public override int ReadContentAsBase64(byte[] buffer, int index, int count) |
| | | 375 | | { |
| | 0 | 376 | | return InnerReader.ReadContentAsBase64(buffer, index, count); |
| | | 377 | | } |
| | | 378 | | |
| | | 379 | | /// <summary> |
| | | 380 | | /// Reads the content and returns the BinHex decoded binary bytes. |
| | | 381 | | /// </summary> |
| | | 382 | | /// <param name="buffer">The buffer into which to copy the resulting text. This value cannot be null.</param> |
| | | 383 | | /// <param name="index">The offset into the buffer where to start copying the result.</param> |
| | | 384 | | /// <param name="count">The maximum number of bytes to copy into the buffer.</param> |
| | | 385 | | /// <returns>The number of bytes written to the buffer.</returns> |
| | | 386 | | public override int ReadContentAsBinHex(byte[] buffer, int index, int count) |
| | | 387 | | { |
| | 0 | 388 | | return InnerReader.ReadContentAsBinHex(buffer, index, count); |
| | | 389 | | } |
| | | 390 | | |
| | | 391 | | /// <summary> |
| | | 392 | | /// Reads the content and returns the contained string. |
| | | 393 | | /// </summary> |
| | | 394 | | public override System.Xml.UniqueId ReadContentAsUniqueId() |
| | | 395 | | { |
| | 0 | 396 | | return InnerReader.ReadContentAsUniqueId(); |
| | | 397 | | } |
| | | 398 | | |
| | | 399 | | /// <summary> |
| | | 400 | | /// Reads large streams of text embedded in an XML document. |
| | | 401 | | /// </summary> |
| | | 402 | | /// <param name="buffer">The array of characters that serves as the buffer to which the text contents |
| | | 403 | | /// are written. This value cannot be null.</param> |
| | | 404 | | /// <param name="index">The offset within the buffer where the System.Xml.XmlReader can start to |
| | | 405 | | /// copy the results.</param> |
| | | 406 | | /// <param name="count">The maximum number of characters to copy into the buffer. The actual number |
| | | 407 | | /// of characters copied is returned from this method.</param> |
| | | 408 | | /// <returns>The number of characters read into the buffer. The value zero is returned |
| | | 409 | | /// when there is no more text content.</returns> |
| | | 410 | | public override int ReadValueChunk(char[] buffer, int index, int count) |
| | | 411 | | { |
| | 0 | 412 | | return InnerReader.ReadValueChunk(buffer, index, count); |
| | | 413 | | } |
| | | 414 | | |
| | | 415 | | /// <summary> |
| | | 416 | | /// Resolves the entity reference for EntityReference nodes. |
| | | 417 | | /// </summary> |
| | | 418 | | public override void ResolveEntity() |
| | | 419 | | { |
| | 0 | 420 | | InnerReader.ResolveEntity(); |
| | 0 | 421 | | } |
| | | 422 | | } |
| | | 423 | | } |