Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XmlStoredResolver.cs « Mono.Xml « Mono.Xml.Ext « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8464e32d5f312624385f2562ddab1b0906cbb92b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// XmlStoredResolver.cs
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// This code is too short to have "creativity". (thus, there must be no 
// copyright on this code). Feel free to use anywhere.
//
// Use like this:
//
//	XmlDocument doc = new XmlDocument ();
//	XmlStoredResolver r = new XmlStoredResolver (new XmlUrlResolver ());
//	r.Add ("http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd",
//		"svg10.dtd");
//	doc.XmlResolver = r;
//
using System;
using System.Collections;
using System.Net;
using System.Xml;

namespace Mono.Xml
{
	public class XmlStoredResolver : XmlResolver
	{
		XmlResolver external;
		XmlResolver local;
		IDictionary uriTable;

		public XmlStoredResolver (XmlResolver resolver)
			: this (resolver, resolver, new Hashtable ())
		{
		}

		public XmlStoredResolver (XmlResolver resolver, IDictionary uriTable)
			: this (resolver, resolver, uriTable)
		{
		}

		public XmlStoredResolver (XmlResolver external, XmlResolver local)
			: this (external, local, new Hashtable ())
		{
		}
		
		public XmlStoredResolver (XmlResolver external, XmlResolver local, IDictionary uriTable)
		{
			this.external = external;
			this.local = local;
			this.uriTable = uriTable;
		}

		public override ICredentials Credentials {
			set {
				external.Credentials = value;
				if (local != external)
					local.Credentials = value;
			}
		}

		public IDictionary Mapping {
			get { return uriTable; }
		}

		public void Add (string nominalUri, string actualLocation)
		{
			uriTable.Add (
				external.ResolveUri (null, nominalUri).ToString (),
				local.ResolveUri (null, actualLocation).ToString ());
		}

		public override object GetEntity (Uri uri, string role, Type returnType)
		{
			string uriString = uri.ToString ();
			string actualLocation = (string) uriTable [uriString];
			if (actualLocation == null)
				return external.GetEntity (uri, role, returnType);
			else
				return local.GetEntity (local.ResolveUri (null, actualLocation), role, returnType);
		}
	}
}