Mercurial > repos > IBBoard
changeset 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 | 2baf3f949cfb |
children | 7b6d1feb6e03 |
files | IBBoard.csproj IBBoard.csproj.user Xml/CustomXmlResolver.cs |
diffstat | 3 files changed, 35 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.csproj Sun Oct 04 09:47:16 2009 +0000 +++ b/IBBoard.csproj Sun Oct 04 15:50:58 2009 +0000 @@ -115,6 +115,7 @@ <Compile Include="UnixTimestamp.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Xml\CustomXmlResolver.cs" /> <Compile Include="Xml\IBBXmlResolver.cs"> <SubType>Code</SubType> </Compile>
--- a/IBBoard.csproj.user Sun Oct 04 09:47:16 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <LastOpenVersion>7.10.3077</LastOpenVersion> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ReferencePath>C:\Documents and Settings\Stu\My Documents\Visual Studio Projects\IBBoard.Graphics.OpenILPort\bin\Debug\</ReferencePath> - <CopyProjectDestinationFolder> - </CopyProjectDestinationFolder> - <CopyProjectUncPath> - </CopyProjectUncPath> - <CopyProjectOption>0</CopyProjectOption> - <ProjectView>ProjectFiles</ProjectView> - <ProjectTrust>0</ProjectTrust> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <EnableASPDebugging>false</EnableASPDebugging> - <EnableASPXDebugging>false</EnableASPXDebugging> - <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging> - <EnableSQLServerDebugging>false</EnableSQLServerDebugging> - <RemoteDebugEnabled>false</RemoteDebugEnabled> - <RemoteDebugMachine> - </RemoteDebugMachine> - <StartAction>Project</StartAction> - <StartArguments> - </StartArguments> - <StartPage> - </StartPage> - <StartProgram> - </StartProgram> - <StartURL> - </StartURL> - <StartWorkingDirectory> - </StartWorkingDirectory> - <StartWithIE>true</StartWithIE> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <EnableASPDebugging>false</EnableASPDebugging> - <EnableASPXDebugging>false</EnableASPXDebugging> - <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging> - <EnableSQLServerDebugging>false</EnableSQLServerDebugging> - <RemoteDebugEnabled>false</RemoteDebugEnabled> - <RemoteDebugMachine> - </RemoteDebugMachine> - <StartAction>Project</StartAction> - <StartArguments> - </StartArguments> - <StartPage> - </StartPage> - <StartProgram> - </StartProgram> - <StartURL> - </StartURL> - <StartWorkingDirectory> - </StartWorkingDirectory> - <StartWithIE>true</StartWithIE> - </PropertyGroup> -</Project> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Xml/CustomXmlResolver.cs Sun Oct 04 15:50:58 2009 +0000 @@ -0,0 +1,34 @@ +// This file (CustomXmlResolver.cs) is a part of the IBBoard library and is copyright 2009 IBBoard. +// +// 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. + +using System; +using System.Collections.Generic; +using System.Xml; + +namespace IBBoard.Xml +{ + /// <summary> + /// A custom XML resolver that lets developers specify their own mappings of relative URIs to file locations. + /// </summary> + public class CustomXmlResolver : XmlUrlResolver + { + private Dictionary<string, Uri> relativeToUriMap = new Dictionary<string, Uri>(); + + /// <summary> + /// Adds a custom mapping of relative URI string to actual URI that will be returned by <code>ResolveUri(Uri, string)</code> + /// </summary> + /// <param name="relativeURI">the relative URI string</param> + /// <param name="resolvedUri">the <code>Uri</code> that <code>ResolveUri(Uri, string)</code> should return for <paramref name="relativeURI"/> </param> + public void AddMapping(string relativeURI, Uri resolvedUri) + { + relativeToUriMap.Add(relativeURI, resolvedUri); + } + + public override Uri ResolveUri(Uri baseUri, string relativeUri) + { + Uri uri = DictionaryUtils.GetValue(relativeToUriMap, relativeUri); + return (uri == null) ? base.ResolveUri(baseUri, relativeUri) : uri; + } + } +}