changeset 118:e53bf3356914

Re #49: XmlResourceResolver fails with HTML DTD on Windows * Make sure that we're always using a conventional format URI
author IBBoard <dev@ibboard.co.uk>
date Fri, 31 Aug 2012 20:40:30 +0100
parents e9f3a4ddf772
children 645e71b9a809
files Xml/XmlResourceResolver.cs
diffstat 1 files changed, 42 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/Xml/XmlResourceResolver.cs	Sat Jul 14 15:24:17 2012 +0100
     1.2 +++ b/Xml/XmlResourceResolver.cs	Fri Aug 31 20:40:30 2012 +0100
     1.3 @@ -19,16 +19,56 @@
     1.4  
     1.5  		public void AddMapping(string relativeURI, string resourceName)
     1.6  		{
     1.7 -			relativeToUriMap[relativeURI] = resourceName;
     1.8 +			string key = MakeKey(relativeURI);
     1.9 +			relativeToUriMap[key] = resourceName;
    1.10 +		}
    1.11 +
    1.12 +		private string MakeKey(string uri)
    1.13 +		{
    1.14 +			return "resource:///" + Uri.EscapeUriString(uri);
    1.15 +		}
    1.16 +
    1.17 +		public override Uri ResolveUri(Uri baseUri, string relativeUri)
    1.18 +		{
    1.19 +			Uri resolved;
    1.20 +			if (relativeToUriMap.ContainsKey(relativeUri))
    1.21 +			{
    1.22 +				resolved = new Uri(MakeKey(relativeUri));
    1.23 +			}
    1.24 +			else if (relativeToUriMap.ContainsKey(MakeKey(relativeUri)))
    1.25 +			{
    1.26 +				resolved = new Uri(relativeUri);
    1.27 +			}
    1.28 +			else
    1.29 +			{
    1.30 +				resolved = base.ResolveUri(baseUri, relativeUri);
    1.31 +			}
    1.32 +
    1.33 +			return resolved;
    1.34  		}
    1.35  
    1.36  		public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
    1.37  		{
    1.38  			string absoluteUriString = absoluteUri.ToString();
    1.39 +			string key = null;
    1.40  
    1.41  			if (relativeToUriMap.ContainsKey(absoluteUriString))
    1.42  			{
    1.43 -				string file = relativeToUriMap[absoluteUriString];
    1.44 +				key = absoluteUriString;
    1.45 +			}
    1.46 +			else
    1.47 +			{
    1.48 +				string createdKey = MakeKey(absoluteUriString);
    1.49 +
    1.50 +				if (relativeToUriMap.ContainsKey(createdKey))
    1.51 +				{
    1.52 +					key = createdKey;
    1.53 +				}
    1.54 +			}
    1.55 +
    1.56 +			if (key != null)
    1.57 +			{
    1.58 +				string file = relativeToUriMap[key];
    1.59  				Stream stream = assm.GetManifestResourceStream(file);
    1.60  				return stream;
    1.61  			}