diff --git a/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs b/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs
index 8bfbf5d6..fb74d81f 100644
--- a/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs
+++ b/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs
@@ -25,6 +25,11 @@ using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Web;
+using System.Web.Compilation;
+using System.Web.UI;
+using Spring.Expressions;
+using Spring.Globalization;
+using Spring.Reflection.Dynamic;
using Spring.Util;
#endregion
@@ -35,78 +40,178 @@ namespace Spring.Web.Support
{
///
/// This ResourceManager implementation swallows s and
- /// simply returns null from if no resource is found.
+ /// simply returns null from if no resource is found.
///
/// Erich Eichinger
- internal class LocalResourceManager : ResourceManager
+ internal abstract class LocalResourceManager : ResourceManager
{
- private string _virtualPath;
- private bool _isMissingManifest = false;
+ private delegate IResourceProvider GetResourceProviderDelegate( TemplateControl control );
+ private static readonly GetResourceProviderDelegate getLocalResourceProvider = (GetResourceProviderDelegate)Delegate.CreateDelegate( typeof( GetResourceProviderDelegate ), typeof( ResourceExpressionBuilder ).GetMethod( "GetLocalResourceProvider", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof( TemplateControl ) }, null ) );
+ private static readonly Type LocalResXResourceProviderFactoryType = typeof( IResourceProvider ).Assembly.GetType( "System.Web.Compilation.ResXResourceProviderFactory", true );
+ private static readonly Type LocalResXResourceProviderType = typeof( IResourceProvider ).Assembly.GetType( "System.Web.Compilation.LocalResXResourceProvider", true );
+ private static readonly ResourceProviderFactory LocalResXResourceProviderFactory = (ResourceProviderFactory)Activator.CreateInstance( LocalResXResourceProviderFactoryType, true );
+ private static readonly SafeMethod fnGetLocalResourceAssembly = new SafeMethod( LocalResXResourceProviderType.GetMethod( "GetLocalResourceAssembly", BindingFlags.Instance | BindingFlags.NonPublic ) );
- public LocalResourceManager(string virtualPath) : base()
+ ///
+ /// Avoid beforeFieldInit
+ ///
+ static LocalResourceManager()
+ { }
+
+ internal static ResourceManager GetLocalResourceManager( TemplateControl control )
{
- AssertUtils.ArgumentNotNull(virtualPath, "virtualPath");
- _virtualPath = virtualPath;
- }
-
-// public LocalResourceManager(string baseName, Assembly assembly) : base(baseName, assembly)
-// {}
-
- ///
- ///Returns the value of the specified resource.
- ///
- ///
- ///The value of the resource localized for the caller's current culture settings. If a match is not possible, null is returned. The resource value can be null.
- ///
- ///The name of the resource to get.
- ///The name parameter is null.
- public override object GetObject( string name )
- {
- return this.GetObject( name, null );
- }
-
- ///
- ///Gets the value of the resource localized for the specified culture.
- ///
- ///
- ///The value of the resource, localized for the specified culture. If a "best match" is not possible, null is returned.
- ///
- ///The object that represents the culture for which the resource is localized. Note that if the resource is not localized for this culture, the lookup will fall back using the culture's property, stopping after checking in the neutral culture.If this value is null, the is obtained using the culture's property.
- ///The name of the resource to get.
- ///The name parameter is null.
- public override object GetObject( string name, CultureInfo culture )
- {
- if (_isMissingManifest) return null;
-
- try
+ IResourceProvider localResourceProvider = GetLocalResourceProvider( control );
+ if (localResourceProvider == null)
{
- return HttpContext.GetLocalResourceObject(_virtualPath, name, culture);
- //return base.GetObject( name, culture );
+ return null;
}
- catch (MissingManifestResourceException)
- {
- _isMissingManifest = true;
+
+ if (localResourceProvider.GetType() == LocalResXResourceProviderType)
+ {
+ Assembly localResourceAssembly = GetLocalResourceAssembly( control );
+ if (localResourceAssembly != null)
+ {
+ return new LocalResXAssemblyResourceManager(control, localResourceAssembly);
+ }
+ else
+ {
+ return null;
+ }
}
- return null;
+
+ return new ResourceProviderResourceManager(localResourceProvider);
}
- ///
- ///Provides the implementation for finding a .
- ///
- ///
- ///
- ///The specified .
- ///
- ///
- ///The to look for.
- ///If the cannot be loaded, try parent objects to see if they exist.
- ///If true and if the has not been loaded yet, load it.
- ///The main assembly does not contain a .resources file and it is required to look up a resource.
- protected override ResourceSet InternalGetResourceSet( CultureInfo culture, bool createIfNotExists, bool tryParents )
+ internal static IResourceProvider GetLocalResourceProvider( TemplateControl templateControl )
{
- //return base.InternalGetResourceSet( culture, createIfNotExists, tryParents );
- return null;
+ IResourceProvider localResourceProvider = getLocalResourceProvider( templateControl );
+ return localResourceProvider;
}
+
+ internal static Assembly GetLocalResourceAssembly( TemplateControl control )
+ {
+ object localResXResourceProvider = LocalResXResourceProviderFactory.CreateLocalResourceProvider( control.AppRelativeVirtualPath );
+ Assembly localResourceAssembly = (Assembly)fnGetLocalResourceAssembly.Invoke( localResXResourceProvider, null );
+ return localResourceAssembly;
+ }
+
+ #region ResourceProviderResourceManager
+
+ private class ResourceProviderResourceManager : ResourceManager
+ {
+ private bool _hasException;
+ private readonly IResourceProvider _resourceProvider;
+
+ public ResourceProviderResourceManager(IResourceProvider resourceProvider)
+ {
+ _resourceProvider = resourceProvider;
+ }
+
+ ///
+ ///Returns the value of the specified resource.
+ ///
+ ///
+ ///The value of the resource localized for the caller's current culture settings. If a match is not possible, null is returned. The resource value can be null.
+ ///
+ ///The name of the resource to get.
+ ///The name parameter is null.
+ public override object GetObject( string name )
+ {
+ return this.GetObject( name, null );
+ }
+
+ ///
+ ///Gets the value of the resource localized for the specified culture.
+ ///
+ ///
+ ///The value of the resource, localized for the specified culture. If a "best match" is not possible, null is returned.
+ ///
+ ///The object that represents the culture for which the resource is localized. Note that if the resource is not localized for this culture, the lookup will fall back using the culture's property, stopping after checking in the neutral culture.If this value is null, the is obtained using the culture's property.
+ ///The name of the resource to get.
+ ///The name parameter is null.
+ public override object GetObject( string name, CultureInfo culture )
+ {
+ if (_hasException)
+ return null;
+
+ try
+ {
+ return _resourceProvider.GetObject(name, culture);
+ }
+ catch (Exception)
+ {
+ _hasException = true;
+ }
+ return null;
+ }
+
+ public override ResourceSet GetResourceSet( CultureInfo culture, bool createIfNotExists, bool tryParents )
+ {
+ ResourceSet resourceSet = null;
+ if (culture == CultureInfo.InvariantCulture)
+ {
+ resourceSet = new ResourceSet(_resourceProvider.ResourceReader);
+ }
+ return resourceSet;
+ }
+ }
+
+ #endregion
+
+ #region LocalResXAssemblyResourceManager
+
+ private class LocalResXAssemblyResourceManager : ResourceManager
+ {
+ private bool _isMissingManifest = false;
+
+ public LocalResXAssemblyResourceManager( TemplateControl templateControl, Assembly localResourceAssembly )
+ : base(
+ VirtualPathUtility.GetFileName( templateControl.AppRelativeVirtualPath ), localResourceAssembly )
+ {
+ AssertUtils.ArgumentNotNull( templateControl, "templateControl" );
+ AssertUtils.ArgumentNotNull( localResourceAssembly, "localResourceAssembly" );
+ }
+
+ ///
+ ///Returns the value of the specified resource.
+ ///
+ ///
+ ///The value of the resource localized for the caller's current culture settings. If a match is not possible, null is returned. The resource value can be null.
+ ///
+ ///The name of the resource to get.
+ ///The name parameter is null.
+ public override object GetObject( string name )
+ {
+ return this.GetObject( name, null );
+ }
+
+ ///
+ ///Gets the value of the resource localized for the specified culture.
+ ///
+ ///
+ ///The value of the resource, localized for the specified culture. If a "best match" is not possible, null is returned.
+ ///
+ ///The object that represents the culture for which the resource is localized. Note that if the resource is not localized for this culture, the lookup will fall back using the culture's property, stopping after checking in the neutral culture.If this value is null, the is obtained using the culture's property.
+ ///The name of the resource to get.
+ ///The name parameter is null.
+ public override object GetObject( string name, CultureInfo culture )
+ {
+ if (_isMissingManifest)
+ return null;
+
+ try
+ {
+ return base.GetObject( name, culture );
+ }
+ catch (MissingManifestResourceException)
+ {
+ _isMissingManifest = true;
+ }
+ return null;
+ }
+ }
+
+ #endregion
}
}
diff --git a/src/Spring/Spring.Web/Web/UI/MasterPage.cs b/src/Spring/Spring.Web/Web/UI/MasterPage.cs
index 5429671f..6e13d56b 100644
--- a/src/Spring/Spring.Web/Web/UI/MasterPage.cs
+++ b/src/Spring/Spring.Web/Web/UI/MasterPage.cs
@@ -371,16 +371,7 @@ namespace Spring.Web.UI
/// Local ResourceManager instance.
private ResourceManager GetLocalResourceManager()
{
-// object resourceProvider = Page.GetLocalResourceProvider.Invoke(typeof(ResourceExpressionBuilder), new object[] {this});
-// MethodInfo GetLocalResourceAssembly =
-// resourceProvider.GetType().GetMethod("GetLocalResourceAssembly", BindingFlags.NonPublic | BindingFlags.Instance);
-// Assembly localResourceAssembly = (Assembly) GetLocalResourceAssembly.Invoke(resourceProvider, null);
-// if (localResourceAssembly != null)
-// {
-// return new ResourceManager(VirtualPathUtility.GetFileName(this.AppRelativeVirtualPath), localResourceAssembly);
-// }
-// return null;
- return new LocalResourceManager( this.AppRelativeVirtualPath );
+ return LocalResourceManager.GetLocalResourceManager(this);
}
///
diff --git a/src/Spring/Spring.Web/Web/UI/Page.cs b/src/Spring/Spring.Web/Web/UI/Page.cs
index f08a359b..a8b8c315 100644
--- a/src/Spring/Spring.Web/Web/UI/Page.cs
+++ b/src/Spring/Spring.Web/Web/UI/Page.cs
@@ -1613,17 +1613,7 @@ namespace Spring.Web.UI
#if !NET_2_0
return new ResourceManager(GetType().BaseType);
#else
-// object resourceProvider = GetLocalResourceProvider.Invoke( typeof( ResourceExpressionBuilder ), new object[] { this } );
-// MethodInfo GetLocalResourceAssembly =
-// resourceProvider.GetType().GetMethod( "GetLocalResourceAssembly", BindingFlags.NonPublic | BindingFlags.Instance );
-// Assembly localResourceAssembly = (Assembly)GetLocalResourceAssembly.Invoke( resourceProvider, null );
-// if (localResourceAssembly != null)
-// {
-// return new LocalResourceManager( VirtualPathUtility.GetFileName( this.AppRelativeVirtualPath ), localResourceAssembly );
-// }
-// return null;
-
- return new LocalResourceManager( this.AppRelativeVirtualPath );
+ return LocalResourceManager.GetLocalResourceManager(this);
#endif
}
diff --git a/src/Spring/Spring.Web/Web/UI/UserControl.cs b/src/Spring/Spring.Web/Web/UI/UserControl.cs
index 6e0806ac..a9f3f591 100644
--- a/src/Spring/Spring.Web/Web/UI/UserControl.cs
+++ b/src/Spring/Spring.Web/Web/UI/UserControl.cs
@@ -1044,17 +1044,7 @@ namespace Spring.Web.UI
#if !NET_2_0
return new ResourceManager(GetType().BaseType);
#else
-// object resourceProvider = Page.GetLocalResourceProvider.Invoke( typeof( ResourceExpressionBuilder ), new object[] { this } );
-// MethodInfo GetLocalResourceAssembly =
-// resourceProvider.GetType().GetMethod( "GetLocalResourceAssembly", BindingFlags.NonPublic | BindingFlags.Instance );
-// Assembly localResourceAssembly = (Assembly)GetLocalResourceAssembly.Invoke( resourceProvider, null );
-// if (localResourceAssembly != null)
-// {
-// return new LocalResourceManager( VirtualPathUtility.GetFileName( this.AppRelativeVirtualPath ), localResourceAssembly );
-// }
-// return null;
-
- return new LocalResourceManager( this.AppRelativeVirtualPath );
+ return LocalResourceManager.GetLocalResourceManager(this);
#endif
}
diff --git a/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/Web.Config b/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/Web.Config
index 383a9f40..4b30b738 100644
--- a/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/Web.Config
+++ b/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/Web.Config
@@ -24,7 +24,9 @@
-
+
@@ -51,13 +53,13 @@
-
+
-
+
-
+
diff --git a/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/WithoutResources.aspx b/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/WithoutResources.aspx
index e792a0ac..b223f099 100644
--- a/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/WithoutResources.aspx
+++ b/test/Spring/Spring.Web.Tests/Data/Spring/Web/Support/LocalResourceManagerTests/WithoutResources.aspx
@@ -1,2 +1,2 @@
<%@ Page language="c#" EnableSessionState="ReadOnly" AutoEventWireup="false" Inherits="Spring.Web.UI.Page" %>
-<%="OK"%>
\ No newline at end of file
+<%=this.GetMessage("OK")%>
\ No newline at end of file
diff --git a/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs b/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs
index 4936c40a..10e58b0b 100644
--- a/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs
+++ b/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs
@@ -21,6 +21,7 @@
#region Imports
using System;
+using System.Diagnostics;
using NUnit.Framework;
using NUnitAspEx;
@@ -42,7 +43,8 @@ namespace Spring.Web.Support
{
AspTestClient client = new AspTestClient();
string result = client.GetPage("WithResources.aspx");
- Assert.AreEqual("", result);
+ Trace.Write(result);
+ Assert.AreEqual("FromResource", result);
}
[Test]