2 // XmlStoredResolver.cs
4 // Author: Atsushi Enomoto <atsushi@ximian.com>
6 // This code is too short to have "creativity". (thus, there must be no
7 // copyright on this code). Feel free to use anywhere.
11 // XmlDocument doc = new XmlDocument ();
12 // XmlStoredResolver r = new XmlStoredResolver (new XmlUrlResolver ());
13 // r.Add ("http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd",
15 // doc.XmlResolver = r;
18 using System
.Collections
;
24 public class XmlStoredResolver
: XmlResolver
30 public XmlStoredResolver (XmlResolver resolver
)
31 : this (resolver
, resolver
, new Hashtable ())
35 public XmlStoredResolver (XmlResolver resolver
, IDictionary uriTable
)
36 : this (resolver
, resolver
, uriTable
)
40 public XmlStoredResolver (XmlResolver external
, XmlResolver local
)
41 : this (external
, local
, new Hashtable ())
45 public XmlStoredResolver (XmlResolver external
, XmlResolver local
, IDictionary uriTable
)
47 this.external
= external
;
49 this.uriTable
= uriTable
;
52 public override ICredentials Credentials
{
54 external
.Credentials
= value;
55 if (local
!= external
)
56 local
.Credentials
= value;
60 public IDictionary Mapping
{
61 get { return uriTable; }
64 public void Add (string nominalUri
, string actualLocation
)
67 external
.ResolveUri (null, nominalUri
).ToString (),
68 local
.ResolveUri (null, actualLocation
).ToString ());
71 public override object GetEntity (Uri uri
, string role
, Type returnType
)
73 string uriString
= uri
.ToString ();
74 string actualLocation
= (string) uriTable
[uriString
];
75 if (actualLocation
== null)
76 return external
.GetEntity (uri
, role
, returnType
);
78 return local
.GetEntity (local
.ResolveUri (null, actualLocation
), role
, returnType
);