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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.IdentityModel
{
using System;
using System.IO;
using System.Xml;
/// <summary>
/// Class wraps a given writer and delegates all XmlDictionaryWriter calls
/// to the inner wrapped writer.
/// </summary>
public class DelegatingXmlDictionaryWriter : XmlDictionaryWriter
{
XmlDictionaryWriter _innerWriter;
// this writer is used to echo un-canonicalized bytes
XmlWriter _tracingWriter;
/// <summary>
/// Initializes a new instance of <see cref="DelegatingXmlDictionaryWriter"/>
/// </summary>
protected DelegatingXmlDictionaryWriter()
{
}
/// <summary>
/// Initializes the inner writer that this instance wraps.
/// </summary>
/// <param name="innerWriter">XmlDictionaryWriter to wrap.</param>
protected void InitializeInnerWriter(XmlDictionaryWriter innerWriter)
{
if (innerWriter == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerWriter");
}
_innerWriter = innerWriter;
}
/// <summary>
/// Initializes a writer that will write the un-canonicalize xml.
/// If this agrument is not null, all calls will be echoed to this writer.
/// </summary>
/// <param name="tracingWriter">XmlTextWriter to echo .</param>
protected void InitializeTracingWriter(XmlWriter tracingWriter)
{
_tracingWriter = tracingWriter;
}
/// <summary>
/// Gets the wrapped writer.
/// </summary>
protected XmlDictionaryWriter InnerWriter
{
get
{
return _innerWriter;
}
}
/// <summary>
/// Closes the underlying stream.
/// </summary>
public override void Close()
{
_innerWriter.Close();
if (_tracingWriter != null)
{
_tracingWriter.Close();
}
}
/// <summary>
/// Flushes the underlying stream.
/// </summary>
public override void Flush()
{
_innerWriter.Flush();
if (_tracingWriter != null)
{
_tracingWriter.Flush();
}
}
/// <summary>
/// Encodes the specified binary bytes as Base64 and writes out the resulting text.
/// </summary>
/// <param name="buffer">Byte array to encode.</param>
/// <param name="index">The position in the buffer indicating the start of the bytes to write.</param>
/// <param name="count">The number of bytes to write.</param>
public override void WriteBase64(byte[] buffer, int index, int count)
{
_innerWriter.WriteBase64(buffer, index, count);
if (_tracingWriter != null)
{
_tracingWriter.WriteBase64(buffer, index, count);
}
}
/// <summary>
/// Writes out a CDATA block containing the specified text.
/// </summary>
/// <param name="text">The text to place inside the CDATA block.</param>
public override void WriteCData(string text)
{
_innerWriter.WriteCData(text);
if (_tracingWriter != null)
{
_tracingWriter.WriteCData(text);
}
}
/// <summary>
/// Forces the generation of a character entity for the specified Unicode character value.
/// </summary>
/// <param name="ch">The Unicode character for which to generate a character entity.</param>
public override void WriteCharEntity(char ch)
{
_innerWriter.WriteCharEntity(ch);
if (_tracingWriter != null)
{
_tracingWriter.WriteCharEntity(ch);
}
}
/// <summary>
/// When overridden in a derived class, writes text one buffer at a time.
/// </summary>
/// <param name="buffer">Character array containing the text to write.</param>
/// <param name="index">The position in the buffer indicating the start of the text to write.</param>
/// <param name="count">The number of characters to write.</param>
public override void WriteChars(char[] buffer, int index, int count)
{
_innerWriter.WriteChars(buffer, index, count);
if (_tracingWriter != null)
{
_tracingWriter.WriteChars(buffer, index, count);
}
}
/// <summary>
/// Writes out a comment containing the specified text.
/// </summary>
/// <param name="text">Text to place inside the comment.</param>
public override void WriteComment(string text)
{
_innerWriter.WriteComment(text);
if (_tracingWriter != null)
{
_tracingWriter.WriteComment(text);
}
}
/// <summary>
/// Writes the DOCTYPE declaration with the specified name and optional attributes.
/// </summary>
/// <param name="name">The name of the DOCTYPE. This must be non-empty.</param>
/// <param name="pubid">If non-null it also writes PUBLIC "pubid" "sysid" where pubid and sysid are
/// replaced with the value of the given arguments.</param>
/// <param name="sysid">If pubid is null and sysid is non-null it writes SYSTEM "sysid" where sysid
/// is replaced with the value of this argument.</param>
/// <param name="subset">If non-null it writes [subset] where subset is replaced with the value of
/// this argument.</param>
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
_innerWriter.WriteDocType(name, pubid, sysid, subset);
if (_tracingWriter != null)
{
_tracingWriter.WriteDocType(name, pubid, sysid, subset);
}
}
/// <summary>
/// Closes the previous System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String) call.
/// </summary>
public override void WriteEndAttribute()
{
_innerWriter.WriteEndAttribute();
if (_tracingWriter != null)
{
_tracingWriter.WriteEndAttribute();
}
}
/// <summary>
/// Closes any open elements or attributes and puts the writer back in the Start state.
/// </summary>
public override void WriteEndDocument()
{
_innerWriter.WriteEndDocument();
if (_tracingWriter != null)
{
_tracingWriter.WriteEndDocument();
}
}
/// <summary>
/// Closes one element and pops the corresponding namespace scope.
/// </summary>
public override void WriteEndElement()
{
_innerWriter.WriteEndElement();
if (_tracingWriter != null)
{
_tracingWriter.WriteEndElement();
}
}
/// <summary>
/// Writes out an entity reference as name.
/// </summary>
/// <param name="name">The name of the entity reference.</param>
public override void WriteEntityRef(string name)
{
_innerWriter.WriteEntityRef(name);
if (_tracingWriter != null)
{
_tracingWriter.WriteEntityRef(name);
}
}
/// <summary>
/// Closes one element and pops the corresponding namespace scope.
/// </summary>
public override void WriteFullEndElement()
{
_innerWriter.WriteFullEndElement();
if (_tracingWriter != null)
{
_tracingWriter.WriteFullEndElement();
}
}
/// <summary>
/// Writes out a processing instruction with a space between the name and text as follows: <?name text?>.
/// </summary>
/// <param name="name">The name of the processing instruction.</param>
/// <param name="text">The text to include in the processing instruction.</param>
public override void WriteProcessingInstruction(string name, string text)
{
_innerWriter.WriteProcessingInstruction(name, text);
if (_tracingWriter != null)
{
_tracingWriter.WriteProcessingInstruction(name, text);
}
}
/// <summary>
/// When overridden in a derived class, writes raw markup manually from a character buffer.
/// </summary>
/// <param name="buffer">Character array containing the text to write.</param>
/// <param name="index">The position within the buffer indicating the start of the text to write.</param>
/// <param name="count">The number of characters to write.</param>
public override void WriteRaw(char[] buffer, int index, int count)
{
_innerWriter.WriteRaw(buffer, index, count);
if (_tracingWriter != null)
{
_tracingWriter.WriteRaw(buffer, index, count);
}
}
/// <summary>
/// Writes raw markup manually from a string.
/// </summary>
/// <param name="data">String containing the text to write.</param>
public override void WriteRaw(string data)
{
_innerWriter.WriteRaw(data);
if (_tracingWriter != null)
{
_tracingWriter.WriteRaw(data);
}
}
/// <summary>
/// Writes the start of an attribute with the specified local name and namespace URI.
/// </summary>
/// <param name="prefix">The namespace prefix of the attribute.</param>
/// <param name="localName">The local name of the attribute.</param>
/// <param name="ns">The namespace URI for the attribute.</param>
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
_innerWriter.WriteStartAttribute(prefix, localName, ns);
if (_tracingWriter != null)
{
_tracingWriter.WriteStartAttribute(prefix, localName, ns);
}
}
/// <summary>
/// When overridden in a derived class, writes the XML declaration with the version "1.0".
/// </summary>
public override void WriteStartDocument()
{
_innerWriter.WriteStartDocument();
if (_tracingWriter != null)
{
_tracingWriter.WriteStartDocument();
}
}
/// <summary>
/// When overridden in a derived class, writes the XML declaration with the version
/// "1.0" and the standalone attribute.
/// </summary>
/// <param name="standalone">If true, it writes "standalone=yes"; if false, it writes "standalone=no".</param>
public override void WriteStartDocument(bool standalone)
{
_innerWriter.WriteStartDocument(standalone);
if (_tracingWriter != null)
{
_tracingWriter.WriteStartDocument(standalone);
}
}
/// <summary>
/// When overridden in a derived class, writes the specified start tag and associates
/// it with the given namespace and prefix.
/// </summary>
/// <param name="prefix">The namespace prefix of the element.</param>
/// <param name="localName">The local name of the element.</param>
/// <param name="ns">The namespace URI to associate with the element.</param>
public override void WriteStartElement(string prefix, string localName, string ns)
{
_innerWriter.WriteStartElement(prefix, localName, ns);
if (_tracingWriter != null)
{
_tracingWriter.WriteStartElement(prefix, localName, ns);
}
}
/// <summary>
/// When overridden in a derived class, gets the state of the writer.
/// </summary>
public override WriteState WriteState
{
get { return _innerWriter.WriteState; }
}
/// <summary>
/// Writes the given text content.
/// </summary>
/// <param name="text">The text to write.</param>
public override void WriteString(string text)
{
_innerWriter.WriteString(text);
if (_tracingWriter != null)
{
_tracingWriter.WriteString(text);
}
}
/// <summary>
/// Generates and writes the surrogate character entity for the surrogate character pair.
/// </summary>
/// <param name="lowChar">The low surrogate. This must be a value between 0xDC00 and 0xDFFF.</param>
/// <param name="highChar">The high surrogate. This must be a value between 0xD800 and 0xDBFF.</param>
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
_innerWriter.WriteSurrogateCharEntity(lowChar, highChar);
if (_tracingWriter != null)
{
_tracingWriter.WriteSurrogateCharEntity(lowChar, highChar);
}
}
/// <summary>
/// Writes out the given white space.
/// </summary>
/// <param name="ws">The string of white space characters.</param>
public override void WriteWhitespace(string ws)
{
_innerWriter.WriteWhitespace(ws);
if (_tracingWriter != null)
{
_tracingWriter.WriteWhitespace(ws);
}
}
/// <summary>
/// Writes an attribute as a xml attribute with the prefix 'xml:'.
/// </summary>
/// <param name="localName">Localname of the attribute.</param>
/// <param name="value">Attribute value.</param>
public override void WriteXmlAttribute(string localName, string value)
{
_innerWriter.WriteXmlAttribute(localName, value);
if (_tracingWriter != null)
{
_tracingWriter.WriteAttributeString(localName, value);
}
}
/// <summary>
/// Writes an xmlns namespace declaration.
/// </summary>
/// <param name="prefix">The prefix of the namespace declaration.</param>
/// <param name="namespaceUri">The namespace Uri itself.</param>
public override void WriteXmlnsAttribute(string prefix, string namespaceUri)
{
_innerWriter.WriteXmlnsAttribute(prefix, namespaceUri);
if (_tracingWriter != null)
{
_tracingWriter.WriteAttributeString(prefix, String.Empty, namespaceUri, String.Empty);
}
}
/// <summary>
/// Returns the closest prefix defined in the current namespace scope for the namespace URI.
/// </summary>
/// <param name="ns">The namespace URI whose prefix you want to find.</param>
/// <returns>The matching prefix or null if no matching namespace URI is found in the
/// current scope.</returns>
public override string LookupPrefix(string ns)
{
return _innerWriter.LookupPrefix(ns);
}
/// <summary>
/// Returns a value indicating if the reader is capable of Canonicalization.
/// </summary>
public override bool CanCanonicalize
{
get
{
return _innerWriter.CanCanonicalize;
}
}
/// <summary>
/// Indicates the start of Canonicalization. Any write operatation following this will canonicalize the data
/// and will wirte it to the given stream.
/// </summary>
/// <param name="stream">Stream to which the canonical stream should be written.</param>
/// <param name="includeComments">The value indicates if comments written should be canonicalized as well.</param>
/// <param name="inclusivePrefixes">Set of prefixes that needs to be included into the canonical stream. The prefixes are defined at
/// the first element that is written to the canonical stream.</param>
public override void StartCanonicalization(Stream stream, bool includeComments, string[] inclusivePrefixes)
{
_innerWriter.StartCanonicalization(stream, includeComments, inclusivePrefixes);
}
/// <summary>
/// Closes a previous Start canonicalization operation. The stream given to the StartCanonicalization is flushed
/// and any data written after this call will not be written to the canonical stream.
/// </summary>
public override void EndCanonicalization()
{
_innerWriter.EndCanonicalization();
}
}
}
|