The Labs \ Source Viewer \ SSCLI \ System.Xml \ XmlUrlResolver

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlUrlResolver.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Xml
  16. {
  17.     using System;
  18.     using System.IO;
  19.     using System.Net;
  20.     using System.Threading;
  21.     using System.Security.Permissions;
  22.     using System.Security.Policy;
  23.     using System.Security;
  24.    
  25.     /// <include file='doc\XmlUrlResolver.uex' path='docs/doc[@for="XmlUrlResolver"]/*' />
  26.     /// <devdoc>
  27.     /// <para>Resolves external XML resources named by a
  28.     /// Uniform Resource Identifier (URI).</para>
  29.     /// </devdoc>
  30.     public class XmlUrlResolver : XmlResolver
  31.     {
  32.         static object s_DownloadManager;
  33.         ICredentials _credentials;
  34.        
  35.         static XmlDownloadManager DownloadManager {
  36.             get {
  37.                 if (s_DownloadManager == null) {
  38.                     object dm = new XmlDownloadManager();
  39.                     Interlocked.CompareExchange(ref s_DownloadManager, dm, null);
  40.                 }
  41.                 return (XmlDownloadManager)s_DownloadManager;
  42.             }
  43.         }
  44.        
  45.         // Construction
  46.        
  47.         /// <include file='doc\XmlUrlResolver.uex' path='docs/doc[@for="XmlUrlResolver.XmlUrlResolver"]/*' />
  48.         /// <devdoc>
  49.         /// <para>
  50.         /// Creates a new instance of the XmlUrlResolver class.
  51.         /// </para>
  52.         /// </devdoc>
  53.         public XmlUrlResolver()
  54.         {
  55.         }
  56.        
  57.         //UE attension
  58.         /// <include file='doc\XmlUrlResolver.uex' path='docs/doc[@for="XmlUrlResolver.Credentials"]/*' />
  59.         /// <devdoc>
  60.         /// <para>[To be supplied.]</para>
  61.         /// </devdoc>
  62.         public override ICredentials Credentials {
  63.             set { _credentials = value; }
  64.         }
  65.        
  66.         // Resource resolution
  67.        
  68.         /// <include file='doc\XmlUrlResolver.uex' path='docs/doc[@for="XmlUrlResolver.GetEntity"]/*' />
  69.         /// <devdoc>
  70.         /// <para>Maps a
  71.         /// URI to an Object containing the actual resource.</para>
  72.         /// </devdoc>
  73.         public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
  74.         {
  75.             if (ofObjectToReturn == null || ofObjectToReturn == typeof(System.IO.Stream)) {
  76.                 return DownloadManager.GetStream(absoluteUri, _credentials);
  77.             }
  78.             else {
  79.                 throw new XmlException(Res.Xml_UnsupportedClass, string.Empty);
  80.             }
  81.         }
  82.        
  83.         /// <include file='doc\XmlUrlResolver.uex' path='docs/doc[@for="XmlUrlResolver.ResolveUri"]/*' />
  84.         /// <devdoc>
  85.         /// <para>[To be supplied.]</para>
  86.         /// </devdoc>
  87.         [PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
  88.         public override Uri ResolveUri(Uri baseUri, string relativeUri)
  89.         {
  90.             return base.ResolveUri(baseUri, relativeUri);
  91.         }
  92.     }
  93. }

Developer Fusion