XmlUrlResolver.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. using Mono.Xml.Native;
  11. namespace System.Xml
  12. {
  13. public class XmlUrlResolver : XmlResolver
  14. {
  15. // Field
  16. ICredentials credential;
  17. WebClient webClientInternal;
  18. WebClient webClient {
  19. get {
  20. if (webClientInternal == null)
  21. webClientInternal = new WebClient ();
  22. return webClientInternal;
  23. }
  24. }
  25. // Constructor
  26. public XmlUrlResolver ()
  27. : base ()
  28. {
  29. }
  30. // Properties
  31. public override ICredentials Credentials
  32. {
  33. set { credential = value; }
  34. }
  35. // Methods
  36. [MonoTODO("Use Credentials; Uri must be absolute.")]
  37. public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
  38. {
  39. // (MS documentation says) parameter role isn't used yet.
  40. Stream s = null;
  41. // webClient.Credentials = credential;
  42. s = new XmlInputStream (webClient.OpenRead (absoluteUri.ToString ()));
  43. if (s.GetType ().IsSubclassOf (ofObjectToReturn))
  44. return s;
  45. s.Close ();
  46. return null;
  47. }
  48. public override Uri ResolveUri (Uri baseUri, string relativeUri)
  49. {
  50. return new Uri (baseUri, relativeUri);
  51. }
  52. }
  53. }