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