fix for SPRNET-1022

fixed Page/UserControl SharedState bug
This commit is contained in:
eeichinger
2008-10-19 00:43:47 +00:00
parent ed1c1216cc
commit 05e241cb8f
8 changed files with 167 additions and 24 deletions

View File

@@ -40,7 +40,7 @@
<call target="set-build-namespaces-all"/>
</if>
<call target="set-framework-configuration"/>
<!-- call target="set-framework-configuration"/ -->
<call target="set-user-overrides"/>
<!-- Targets that check settings -->

View File

@@ -130,6 +130,7 @@
<Compile Include="Web\Support\HandlerMapEntry.cs" />
<Compile Include="Web\Support\IResult.cs" />
<Compile Include="Web\Support\IResultFactory.cs" />
<Compile Include="Web\Support\LocalResourceManager.cs" />
<Compile Include="Web\Support\MappingHandlerFactory.cs" />
<Compile Include="Web\Support\MappingHandlerFactoryConfigurer.cs" />
<Compile Include="Web\Support\ResultFactoryRegistry.cs" />

View File

@@ -0,0 +1,91 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Web;
using Spring.Util;
#endregion
namespace Spring.Web.Support
{
/// <summary>
/// This ResourceManager implementation swallows <see cref="MissingManifestResourceException"/>s and
/// simply returns <c>null</c> from <see cref="GetObject(string,CultureInfo"/> if no resource is found.
/// </summary>
/// <author>Erich Eichinger</author>
internal class LocalResourceManager : ResourceManager
{
private string _virtualPath;
private bool _isMissingManifest = false;
public LocalResourceManager(string virtualPath) : base()
{
AssertUtils.ArgumentNotNull(virtualPath, "virtualPath");
_virtualPath = virtualPath;
}
// public LocalResourceManager(string baseName, Assembly assembly) : base(baseName, assembly)
// {}
///<summary>
///Returns the value of the specified <see cref="T:System.Object"></see> resource.
///</summary>
///<returns>
///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.
///</returns>
///<param name="name">The name of the resource to get. </param>
///<exception cref="T:System.ArgumentNullException">The name parameter is null. </exception>
public override object GetObject( string name )
{
return this.GetObject( name, null );
}
///<summary>
///Gets the value of the <see cref="T:System.Object"></see> resource localized for the specified culture.
///</summary>
///<returns>
///The value of the resource, localized for the specified culture. If a "best match" is not possible, null is returned.
///</returns>
///<param name="culture">The <see cref="T:System.Globalization.CultureInfo"></see> 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 <see cref="P:System.Globalization.CultureInfo.Parent"></see> property, stopping after checking in the neutral culture.If this value is null, the <see cref="T:System.Globalization.CultureInfo"></see> is obtained using the culture's <see cref="P:System.Globalization.CultureInfo.CurrentUICulture"></see> property. </param>
///<param name="name">The name of the resource to get. </param>
///<exception cref="T:System.ArgumentNullException">The name parameter is null. </exception>
public override object GetObject( string name, CultureInfo culture )
{
if (_isMissingManifest) return null;
try
{
return HttpContext.GetLocalResourceObject(_virtualPath, name, culture);
//return base.GetObject( name, culture );
}
catch (MissingManifestResourceException ex)
{
_isMissingManifest = true;
}
return null;
}
}
}

View File

@@ -112,7 +112,7 @@ namespace Spring.Web.UI
private String masterPageFile;
#endif
private object controller;
private IDictionary sharedState = new CaseInsensitiveHashtable();
private IDictionary sharedState;
private ILocalizer localizer;
private ICultureResolver cultureResolver = new DefaultWebCultureResolver();
@@ -214,6 +214,10 @@ namespace Spring.Web.UI
protected override void OnPreInit( EventArgs e )
#endif
{
if (SharedState == null)
{
SharedState = new CaseInsensitiveHashtable();
}
InitializeCulture();
InitializeMessageSource();
#if !NET_2_0
@@ -1589,15 +1593,17 @@ 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 ResourceManager( VirtualPathUtility.GetFileName( this.AppRelativeVirtualPath ), localResourceAssembly );
}
// 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 new LocalResourceManager( this.AppRelativeVirtualPath );
// TODO: investigate HttpContext.GetLocalResourceObject()
return null;
#endif
}

View File

@@ -68,7 +68,7 @@ namespace Spring.Web.UI
private object controller;
private ILocalizer localizer;
private IMessageSource messageSource;
private IDictionary sharedState = new CaseInsensitiveHashtable();
private IDictionary sharedState;
private IBindingContainer bindingManager;
private IValidationErrors validationErrors = new ValidationErrors();
private IWebNavigator webNavigator;
@@ -1020,23 +1020,23 @@ namespace Spring.Web.UI
/// </remarks>
/// <returns>Local ResourceManager instance.</returns>
private ResourceManager GetLocalResourceManager()
{
#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 ResourceManager( VirtualPathUtility.GetFileName( this.AppRelativeVirtualPath ), localResourceAssembly );
}
return null;
}
// 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 );
#endif
}
/// <summary>
/// Returns message for the specified resource name.

View File

@@ -123,6 +123,7 @@
</Compile>
<Compile Include="Web\Services\WebServiceExporterTests.cs" />
<Compile Include="Web\Support\AbstractHandlerFactoryTests.cs" />
<Compile Include="Web\Support\LocalResourceManagerTests.cs" />
<Compile Include="Web\Support\MimeMediaTypeTests.cs" />
<Compile Include="Web\Support\PageHandlerFactoryTests.cs" />
<Compile Include="Web\Support\ResultFactoryRegistryTests.cs" />

View File

@@ -0,0 +1,37 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Web.Support
{
/// <summary>
///
/// </summary>
/// <author>Erich Eichinger</author>
public class LocalResourceManagerTests
{
}
}

View File

@@ -46,6 +46,13 @@ namespace Spring.Web.UI
[TestFixture]
public class PageTests : TestWebContextTests
{
[Test]
public void NoSharedStateAtConstruction()
{
Page page = new Page();
Assert.IsNull(page.SharedState);
}
[Test]
public void Validate()
{