diff --git a/Spring.build b/Spring.build index df73e619..1dede09b 100644 --- a/Spring.build +++ b/Spring.build @@ -40,7 +40,7 @@ - + diff --git a/src/Spring/Spring.Web/Spring.Web.2008.csproj b/src/Spring/Spring.Web/Spring.Web.2008.csproj index 95da6b69..57ba07ea 100644 --- a/src/Spring/Spring.Web/Spring.Web.2008.csproj +++ b/src/Spring/Spring.Web/Spring.Web.2008.csproj @@ -130,6 +130,7 @@ + diff --git a/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs b/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs new file mode 100644 index 00000000..01b05dd6 --- /dev/null +++ b/src/Spring/Spring.Web/Web/Support/LocalResourceManager.cs @@ -0,0 +1,91 @@ +#region License + +/* + * Copyright © 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 +{ + /// + /// This ResourceManager implementation swallows s and + /// simply returns null from if no resource is found. + /// + /// Erich Eichinger + 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) +// {} + + /// + ///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 HttpContext.GetLocalResourceObject(_virtualPath, name, culture); + //return base.GetObject( name, culture ); + } + catch (MissingManifestResourceException ex) + { + _isMissingManifest = true; + } + return null; + } + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Web/Web/UI/Page.cs b/src/Spring/Spring.Web/Web/UI/Page.cs index c6cbb611..083eac96 100644 --- a/src/Spring/Spring.Web/Web/UI/Page.cs +++ b/src/Spring/Spring.Web/Web/UI/Page.cs @@ -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 } diff --git a/src/Spring/Spring.Web/Web/UI/UserControl.cs b/src/Spring/Spring.Web/Web/UI/UserControl.cs index add41135..2fec016a 100644 --- a/src/Spring/Spring.Web/Web/UI/UserControl.cs +++ b/src/Spring/Spring.Web/Web/UI/UserControl.cs @@ -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 /// /// Local ResourceManager instance. 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 + } /// /// Returns message for the specified resource name. diff --git a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj index 8d816897..9feff1eb 100644 --- a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj +++ b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj @@ -123,6 +123,7 @@ + diff --git a/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs b/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs new file mode 100644 index 00000000..df2e14d6 --- /dev/null +++ b/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs @@ -0,0 +1,37 @@ +#region License + +/* + * Copyright © 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 +{ + /// + /// + /// + /// Erich Eichinger + public class LocalResourceManagerTests + { + + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Web.Tests/Web/UI/PageTests.cs b/test/Spring/Spring.Web.Tests/Web/UI/PageTests.cs index 3bc85a14..8afd089f 100644 --- a/test/Spring/Spring.Web.Tests/Web/UI/PageTests.cs +++ b/test/Spring/Spring.Web.Tests/Web/UI/PageTests.cs @@ -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() {