annotate Xml/CustomXmlResolver.cs @ 44:8725c5440606

* Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch) Required for warfoundry:#144 no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Oct 2009 15:50:58 +0000
parents
children 7b6d1feb6e03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (CustomXmlResolver.cs) is a part of the IBBoard library and is copyright 2009 IBBoard.
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Xml;
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 namespace IBBoard.Xml
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// <summary>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// A custom XML resolver that lets developers specify their own mappings of relative URIs to file locations.
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// </summary>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class CustomXmlResolver : XmlUrlResolver
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 private Dictionary<string, Uri> relativeToUriMap = new Dictionary<string, Uri>();
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// <summary>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 /// Adds a custom mapping of relative URI string to actual URI that will be returned by <code>ResolveUri(Uri, string)</code>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 /// </summary>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 /// <param name="relativeURI">the relative URI string</param>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 /// <param name="resolvedUri">the <code>Uri</code> that <code>ResolveUri(Uri, string)</code> should return for <paramref name="relativeURI"/> </param>
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 public void AddMapping(string relativeURI, Uri resolvedUri)
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 {
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 relativeToUriMap.Add(relativeURI, resolvedUri);
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 }
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 public override Uri ResolveUri(Uri baseUri, string relativeUri)
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 Uri uri = DictionaryUtils.GetValue(relativeToUriMap, relativeUri);
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 return (uri == null) ? base.ResolveUri(baseUri, relativeUri) : uri;
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }
8725c5440606 * Add custom XMLResolver that lets developers map relative URIs to actual URIs (e.g. for mapping XHTML DTD to local file to stop remote fetch)
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 }