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