Author: cziegeler Date: Thu Aug 18 15:53:35 2011 New Revision: 1159287 URL: http://svn.apache.org/viewvc?rev=1159287&view=rev Log: SLING-2180 : Provide a resource bundle for all requests
Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java?rev=1159287&r1=1159286&r2=1159287&view=diff ============================================================================== --- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java (original) +++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/I18NFilter.java Thu Aug 18 15:53:35 2011 @@ -100,11 +100,13 @@ public class I18NFilter implements Filte throws IOException, ServletException { final boolean runGlobal = this.initCount == 2; if ( request instanceof SlingHttpServletRequest ) { - // check if we have to wrap + // check if we can use the simple version to wrap if ( !runGlobal || this.requestLocaleResolver == DEFAULT_LOCALE_RESOLVER ) { // wrap with our ResourceBundle provisioning request = new I18NSlingHttpServletRequest(request, resourceBundleProvider, localeResolver); + } else { + request = new BaseI18NSlingHttpServletRequest(request, resourceBundleProvider); } } else { request = new I18NHttpServletRequest(request, @@ -208,23 +210,15 @@ public class I18NFilter implements Filte } - private static class I18NSlingHttpServletRequest + private static class BaseI18NSlingHttpServletRequest extends SlingHttpServletRequestWrapper { - private final ResourceBundleProvider bundleProvider; - - private final LocaleResolver localeResolver; - - private Locale locale; - - private List<Locale> localeList; + protected final ResourceBundleProvider bundleProvider; - I18NSlingHttpServletRequest(final ServletRequest delegatee, - final ResourceBundleProvider bundleProvider, - final LocaleResolver localeResolver) { + BaseI18NSlingHttpServletRequest(final ServletRequest delegatee, + final ResourceBundleProvider bundleProvider) { super((SlingHttpServletRequest) delegatee); this.bundleProvider = bundleProvider; - this.localeResolver = localeResolver; } @Override @@ -233,15 +227,6 @@ public class I18NFilter implements Filte } @Override - public Object getAttribute(final String name) { - if ( ResourceBundleProvider.BUNDLE_REQ_ATTR.equals(name) ) { - final Object superValue = super.getAttribute(name); - return (superValue != null ? superValue : this.getResourceBundle(null)); - } - return super.getAttribute(name); - } - - @Override public ResourceBundle getResourceBundle(String baseName, Locale locale) { if (bundleProvider != null) { if (locale == null) { @@ -261,6 +246,32 @@ public class I18NFilter implements Filte return super.getResourceBundle(baseName, locale); } + } + + private static class I18NSlingHttpServletRequest + extends BaseI18NSlingHttpServletRequest { + + private final LocaleResolver localeResolver; + + private Locale locale; + + private List<Locale> localeList; + + I18NSlingHttpServletRequest(final ServletRequest delegatee, + final ResourceBundleProvider bundleProvider, + final LocaleResolver localeResolver) { + super(delegatee, bundleProvider); + this.localeResolver = localeResolver; + } + + @Override + public Object getAttribute(final String name) { + if ( ResourceBundleProvider.BUNDLE_REQ_ATTR.equals(name) ) { + final Object superValue = super.getAttribute(name); + return (superValue != null ? superValue : this.getResourceBundle(null)); + } + return super.getAttribute(name); + } @Override public Locale getLocale() {