XmlUrlResolver.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // System.Xml.XmlUrlResolver.cs
  2. //
  3. // Author: Duncan Mak ([email protected])
  4. // Atsushi Enomoto ([email protected])
  5. //
  6. // (C) Ximian, Inc.
  7. //
  8. using System.Net;
  9. using System.IO;
  10. namespace System.Xml
  11. {
  12. public class XmlUrlResolver : XmlResolver
  13. {
  14. // Field
  15. ICredentials credential;
  16. WebClient webClientInternal;
  17. WebClient webClient {
  18. get {
  19. if (webClientInternal == null)
  20. webClientInternal = new WebClient ();
  21. return webClientInternal;
  22. }
  23. }
  24. // Constructor
  25. public XmlUrlResolver ()
  26. : base ()
  27. {
  28. }
  29. // Properties
  30. public override ICredentials Credentials
  31. {
  32. set { credential = value; }
  33. }
  34. // Methods
  35. [MonoTODO("Use Credentials; Uri must be absolute.")]
  36. public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
  37. {
  38. // (MS documentation says) parameter role isn't used yet.
  39. Stream s = null;
  40. // webClient.Credentials = credential;
  41. s = new XmlInputStream (webClient.OpenRead (absoluteUri.ToString ()));
  42. if (s.GetType ().IsSubclassOf (ofObjectToReturn))
  43. return s;
  44. s.Close ();
  45. return null;
  46. }
  47. public override Uri ResolveUri (Uri baseUri, string relativeUri)
  48. {
  49. return new Uri (baseUri, relativeUri);
  50. }
  51. }
  52. }