Author: julien(a)jboss.com
Date: 2007-03-24 18:32:21 -0400 (Sat, 24 Mar 2007)
New Revision: 6817
Added:
trunk/common/src/main/org/jboss/portal/common/i18n/
trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleFactory.java
trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleManager.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletResourceBundleFactory.java
Removed:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/PortletResourceBundleManager.java
Modified:
trunk/common/src/main/org/jboss/portal/common/util/EmptyResourceBundle.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/InternalPortletContentProvider.java
trunk/core/src/main/org/jboss/portal/test/core/I18nELTestCase.java
trunk/core/src/main/org/jboss/portal/test/core/I18nOutELTestCase.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletContainerImpl.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletConfigImpl.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerCapabilities.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerMetaInfo.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPortletInfo.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPreferencesInfo.java
Log:
extracted ResourceBundleManager in common package from portlet module
Added: trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleFactory.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleFactory.java
(rev 0)
+++
trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleFactory.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import java.util.ResourceBundle;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ResourceBundleFactory
+{
+ /**
+ * Returns a resource bundle for the specified locale, it may be an expensive
operation.
+ *
+ * @param locale the locale for the resource bundle
+ * @return a resource bundle for the locale or null if no such bundle can be obtained
+ * @throws IllegalArgumentException if the locale is null
+ */
+ ResourceBundle getBundle(Locale locale) throws IllegalArgumentException;
+}
Added: trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleManager.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleManager.java
(rev 0)
+++
trunk/common/src/main/org/jboss/portal/common/i18n/ResourceBundleManager.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -0,0 +1,152 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.i18n;
+
+import org.apache.log4j.Logger;
+import org.jboss.portal.common.util.LocalizedString;
+
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.MissingResourceException;
+
+/**
+ * Manage a set of resource bundles.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision: 6697 $
+ */
+public class ResourceBundleManager
+{
+
+ /** */
+ private Logger log = Logger.getLogger(getClass());
+
+ /** */
+ private volatile Map localeBundles;
+
+ /** */
+ private ResourceBundle defaultBundle;
+
+ /** */
+ private ResourceBundleFactory resourceBundleFactory;
+
+ public ResourceBundleManager(ResourceBundle defaultBundle, ResourceBundleFactory
resourceBundleFactory)
+ {
+ this.localeBundles = new HashMap();
+ this.defaultBundle = defaultBundle;
+ this.resourceBundleFactory = resourceBundleFactory;
+ }
+
+ /**
+ * Return a localized value constructed from the various resource bundles. The
supported locales of the manager are
+ * used in combination with the specified key. The default value is used if no value
is found for the
+ * <code>Locale.ENGLISH</code>.
+ *
+ * @param key the key to lookup in the bundles
+ * @param defaultValue the default value
+ * @return the localized string
+ * @throws IllegalArgumentException if the key of the default value is null
+ */
+ public LocalizedString getLocalizedValue(String key, String defaultValue) throws
IllegalArgumentException
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("No null key accepted");
+ }
+ if (defaultValue == null)
+ {
+ throw new IllegalArgumentException("No null default value accepted");
+ }
+ Map m = new HashMap();
+ for (Iterator j = localeBundles.entrySet().iterator(); j.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)j.next();
+ try
+ {
+ Locale locale = (Locale)entry.getKey();
+ ResourceBundle bundle = (ResourceBundle)entry.getValue();
+ String localizedDisplayName = bundle.getString(key);
+ m.put(locale, localizedDisplayName);
+ }
+ catch (MissingResourceException ignore)
+ {
+ }
+ }
+ if (!m.containsKey(Locale.ENGLISH))
+ {
+ m.put(Locale.ENGLISH, defaultValue);
+ }
+ return new LocalizedString(m, Locale.ENGLISH);
+ }
+
+ /**
+ * Return a bundle for the given locale. If the complete locale (language + country +
variant) does not exist then it
+ * falls back to (language + country) or (language) or the default file.
+ * <p/>
+ * When the resource bundle object is found and was not in the global map, it put it
in that map with a copy on
+ * write.
+ *
+ * @throws IllegalArgumentException if the locale is null
+ */
+ public ResourceBundle getResourceBundle(Locale locale) throws
IllegalArgumentException
+ {
+ // Arg check
+ if (locale == null)
+ {
+ throw new IllegalArgumentException("Locale cannot be null");
+ }
+
+ // Try to get the bundle if the map
+ ResourceBundle bundle = (ResourceBundle)localeBundles.get(locale);
+ if (bundle != null)
+ {
+ return bundle;
+ }
+
+ //
+ log.debug("Want to load bundle for locale " + locale);
+ bundle = resourceBundleFactory.getBundle(locale);
+
+ //
+ if (bundle != null)
+ {
+ log.debug("Obtained bundle " + bundle + " for locale " +
locale);
+ }
+ else
+ {
+ log.debug("No bundle obtained for locale " + locale + " will use
default bundle " + defaultBundle + "instead");
+ }
+
+ // Cache the bundle
+ Map copy = new HashMap(localeBundles);
+ copy.put(locale, bundle);
+ localeBundles = copy;
+
+ //
+ return bundle;
+ }
+}
Modified: trunk/common/src/main/org/jboss/portal/common/util/EmptyResourceBundle.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/EmptyResourceBundle.java 2007-03-24
10:27:17 UTC (rev 6816)
+++ trunk/common/src/main/org/jboss/portal/common/util/EmptyResourceBundle.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -31,6 +31,10 @@
*/
public class EmptyResourceBundle extends ResourceBundle
{
+
+ /** . */
+ public static final EmptyResourceBundle INSTANCE = new EmptyResourceBundle();
+
protected Object handleGetObject(String key)
{
if (key == null)
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/InternalPortletContentProvider.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/InternalPortletContentProvider.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/InternalPortletContentProvider.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -39,6 +39,9 @@
import org.jboss.portal.Mode;
import org.jboss.portal.common.util.LocalizedString;
+import java.util.ResourceBundle;
+import java.util.Locale;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -52,6 +55,15 @@
/** . */
private CustomizationManager customizationManager;
+ /** . */
+ private ResourceBundle bundle;
+
+ /** . */
+ private LocalizedString displayName;
+
+ /** . */
+ private LocalizedString description;
+
public InstanceContainer getInstanceContainer()
{
return instanceContainer;
@@ -72,6 +84,25 @@
this.customizationManager = customizationManager;
}
+ public void start() throws Exception
+ {
+ bundle = ResourceBundle.getBundle("conf/bundles/PortletContent",
Locale.ENGLISH, Thread.currentThread().getContextClassLoader());
+
+ // displayName = new LocalizedString();
+
+ //
+ super.start();
+ }
+
+
+ public void stop()
+ {
+ super.stop();
+
+ //
+ bundle = null;
+ }
+
protected ContentProvider createProvider()
{
return new ContentProvider()
Modified: trunk/core/src/main/org/jboss/portal/test/core/I18nELTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/I18nELTestCase.java 2007-03-24 10:27:17
UTC (rev 6816)
+++ trunk/core/src/main/org/jboss/portal/test/core/I18nELTestCase.java 2007-03-24 22:32:21
UTC (rev 6817)
@@ -25,7 +25,7 @@
import org.apache.cactus.JspTestCase;
import org.jboss.portal.core.servlet.jsp.PortalJsp;
import org.jboss.portal.core.servlet.jsp.taglib.PortalLib;
-import org.jboss.portal.portlet.impl.jsr168.info.PortletResourceBundleManager;
+import org.jboss.portal.portlet.impl.jsr168.PortletResourceBundleFactory;
import org.jboss.portal.portlet.impl.jsr168.api.PortletConfigImpl;
import org.jboss.portal.portlet.impl.jsr168.metadata.LanguagesMetaData;
@@ -69,10 +69,10 @@
languagesMD.setResourceBundle(RESOURCE_BUNDLE_NAME);
// Build the bundle
- PortletResourceBundleManager rbs = new PortletResourceBundleManager(loader,
languagesMD);
+ PortletResourceBundleFactory rbs = new PortletResourceBundleFactory(loader,
languagesMD);
- PortletConfig portletConfig = new PortletConfigImpl("testPortlet", null,
null, rbs);
- request.setAttribute("javax.portlet.config", portletConfig);
+// PortletConfig portletConfig = new PortletConfigImpl("testPortlet",
null, null, rbs);
+// request.setAttribute("javax.portlet.config", portletConfig);
HttpServletRequestWrapperImpl requestWrapper = new
HttpServletRequestWrapperImpl(request);
requestWrapper.setLocale(Locale.FRENCH);
Modified: trunk/core/src/main/org/jboss/portal/test/core/I18nOutELTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/I18nOutELTestCase.java 2007-03-24
10:27:17 UTC (rev 6816)
+++ trunk/core/src/main/org/jboss/portal/test/core/I18nOutELTestCase.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -27,11 +27,9 @@
import org.jboss.portal.core.servlet.jsp.taglib.PortalLib;
import org.jboss.portal.core.servlet.jsp.taglib.context.Context;
import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
-import org.jboss.portal.portlet.impl.jsr168.info.PortletResourceBundleManager;
-import org.jboss.portal.portlet.impl.jsr168.api.PortletConfigImpl;
+import org.jboss.portal.portlet.impl.jsr168.PortletResourceBundleFactory;
import org.jboss.portal.portlet.impl.jsr168.metadata.LanguagesMetaData;
-import javax.portlet.PortletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -71,10 +69,10 @@
languagesMD.setResourceBundle(RESOURCE_BUNDLE_NAME);
// Build the bundle
- PortletResourceBundleManager rbs = new PortletResourceBundleManager(loader,
languagesMD);
+ PortletResourceBundleFactory rbs = new PortletResourceBundleFactory(loader,
languagesMD);
- PortletConfig portletConfig = new PortletConfigImpl("testPortlet", null,
null, rbs);
- request.setAttribute("javax.portlet.config", portletConfig);
+// PortletConfig portletConfig = new PortletConfigImpl("testPortlet",
null, null, rbs);
+// request.setAttribute("javax.portlet.config", portletConfig);
HttpServletRequestWrapperImpl requestWrapper = new
HttpServletRequestWrapperImpl(request);
requestWrapper.setLocale(Locale.FRENCH);
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletContainerImpl.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletContainerImpl.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletContainerImpl.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -28,7 +28,7 @@
import org.jboss.portal.portlet.impl.jsr168.api.RenderResponseImpl;
import org.jboss.portal.portlet.impl.jsr168.api.RenderRequestImpl;
import org.jboss.portal.portlet.impl.jsr168.api.ActionRequestImpl;
-import org.jboss.portal.portlet.impl.jsr168.info.PortletResourceBundleManager;
+import org.jboss.portal.portlet.impl.jsr168.PortletResourceBundleFactory;
import org.jboss.portal.portlet.container.PortletInitializationException;
import org.jboss.portal.portlet.container.PortletApplication;
import org.jboss.portal.portlet.container.PortletContainer;
@@ -51,6 +51,7 @@
import org.jboss.portal.portlet.aspects.portlet.ContextDispatcherInterceptor;
import org.jboss.portal.common.concurrent.Valve;
import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
import javax.portlet.PortletConfig;
import javax.portlet.Portlet;
@@ -98,7 +99,7 @@
protected ContentTypes contentTypes;
/** . */
- protected PortletResourceBundleManager bundleMgr;
+ protected ResourceBundleManager bundleMgr;
/** The invocation valve. */
protected final Valve valve;
@@ -211,7 +212,7 @@
}
// Portlet config object
- PortletResourceBundleManager bundleMgr = new
PortletResourceBundleManager(application.getContext().getClassLoader(),
metaData.getLanguages());
+ ResourceBundleManager bundleMgr =
PortletResourceBundleFactory.createResourceBundleManager(application.getContext().getClassLoader(),
metaData.getLanguages());
//
PortletConfig config = new PortletConfigImpl(
Copied:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletResourceBundleFactory.java
(from rev 6805,
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/PortletResourceBundleManager.java)
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletResourceBundleFactory.java
(rev 0)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletResourceBundleFactory.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -0,0 +1,145 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.impl.jsr168;
+
+import org.jboss.portal.common.util.EmptyResourceBundle;
+import org.jboss.portal.common.util.ParentChildResourceBundle;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
+import org.jboss.portal.common.i18n.ResourceBundleFactory;
+import org.jboss.portal.portlet.impl.jsr168.metadata.LanguagesMetaData;
+import org.jboss.portal.portlet.impl.jsr168.info.InfoBundle;
+
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Manage resource bundles for a portlet.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class PortletResourceBundleFactory implements ResourceBundleFactory
+{
+
+ public static ResourceBundleManager createResourceBundleManager(ClassLoader
classLoader, LanguagesMetaData metaData)
+ {
+ if (classLoader == null)
+ {
+ throw new IllegalArgumentException("Need a non null classloader");
+ }
+ if (metaData == null)
+ {
+ throw new IllegalArgumentException("Need non null meta data");
+ }
+
+ // Create factory
+ PortletResourceBundleFactory factory = new
PortletResourceBundleFactory(classLoader, metaData);
+
+ // Create manager
+ ResourceBundleManager manager = new
ResourceBundleManager(EmptyResourceBundle.INSTANCE, factory);
+
+ // Preload declared locales
+ for (Iterator i = metaData.getSupportedLocales().iterator();i.hasNext();)
+ {
+ Locale locale = (Locale)i.next();
+ manager.getResourceBundle(locale);
+ }
+
+ //
+ return manager;
+ }
+
+ /** The class loader to load resource bundle from. */
+ private final ClassLoader classLoader;
+
+ /** The base name of the resource bundle. */
+ private final String baseName;
+
+ /** */
+ private ResourceBundle infoBundle;
+
+ public PortletResourceBundleFactory(ClassLoader classLoader, LanguagesMetaData
metaData)
+ {
+ if (classLoader == null)
+ {
+ throw new IllegalArgumentException("Need a non null classloader");
+ }
+ if (metaData == null)
+ {
+ throw new IllegalArgumentException("Need non null meta data");
+ }
+ this.classLoader = classLoader;
+ this.baseName = metaData.getResourceBundle();
+
+ // Get the resource bundle containing the portlet info
+ LanguagesMetaData.InfoMetaData infoMD = metaData.getInfo();
+ if (infoMD != null)
+ {
+ infoBundle = new InfoBundle(infoMD);
+ }
+ else
+ {
+ infoBundle = EmptyResourceBundle.INSTANCE;
+ }
+ }
+
+ public ResourceBundle getBundle(Locale locale)
+ {
+ if (locale == null)
+ {
+ throw new IllegalArgumentException("Locale cannot be null");
+ }
+
+ //
+ ResourceBundle bundle;
+
+ //
+ if (baseName == null)
+ {
+ bundle = infoBundle;
+ }
+ else
+ {
+ try
+ {
+ bundle = ResourceBundle.getBundle(baseName, locale, classLoader);
+ if (infoBundle != null)
+ {
+ bundle = new ParentChildResourceBundle(infoBundle, bundle);
+ }
+ // log.debug("Created bundle " + baseName + " for locale
" + locale);
+ }
+ catch (MissingResourceException e)
+ {
+ // log.warn("Bundle " + baseName + " for locale " +
locale + " not found");
+ bundle = infoBundle;
+ }
+ }
+
+ //
+ return bundle;
+ }
+}
Property changes on:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/PortletResourceBundleFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletConfigImpl.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletConfigImpl.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletConfigImpl.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.portlet.impl.jsr168.api;
-import org.jboss.portal.portlet.impl.jsr168.info.PortletResourceBundleManager;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
@@ -42,12 +42,12 @@
private String portletName;
private PortletContext portletContext;
private Map initParameters;
- private PortletResourceBundleManager bundleMgr;
+ private ResourceBundleManager bundleMgr;
public PortletConfigImpl(String portletName,
PortletContext portletContext,
Map initParameters,
- PortletResourceBundleManager bundleMgr)
+ ResourceBundleManager bundleMgr)
{
this.portletName = portletName;
this.portletContext = portletContext;
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerCapabilities.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerCapabilities.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerCapabilities.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -24,6 +24,7 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
import java.util.Collections;
@@ -50,9 +51,9 @@
private Set supportedLocales;
private ContentTypes contentTypes;
- private PortletResourceBundleManager bundleMgr;
+ private ResourceBundleManager bundleMgr;
- public ContainerCapabilities(Set supportedLocales, PortletResourceBundleManager
bundleMgr, ContentTypes contentTypes)
+ public ContainerCapabilities(Set supportedLocales, ResourceBundleManager bundleMgr,
ContentTypes contentTypes)
{
this.supportedLocales = supportedLocales;
this.contentTypes = contentTypes;
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerMetaInfo.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerMetaInfo.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerMetaInfo.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -23,6 +23,7 @@
package org.jboss.portal.portlet.impl.jsr168.info;
import org.jboss.portal.common.util.LocalizedString;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
import org.jboss.portal.portlet.impl.jsr168.metadata.PortletMetaData;
import org.jboss.portal.portlet.info.MetaInfo;
@@ -47,7 +48,7 @@
private static final String[] KEYS = {TITLE, SHORT_TITLE, KEYWORDS};
private static final String[] BUNDLE_KEYS = {JAVAX_PORTLET + TITLE, JAVAX_PORTLET +
SHORT_TITLE, JAVAX_PORTLET + KEYWORDS};
- public ContainerMetaInfo(PortletMetaData metadata, PortletResourceBundleManager rb)
+ public ContainerMetaInfo(PortletMetaData metadata, ResourceBundleManager rb)
{
this.values = new HashMap();
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPortletInfo.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPortletInfo.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPortletInfo.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -35,6 +35,7 @@
import org.jboss.portal.portlet.info.SessionInfo;
import org.jboss.portal.portlet.metadata.JBossApplicationMetaData;
import org.jboss.portal.portlet.metadata.JBossPortletMetaData;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
import java.util.HashSet;
import java.util.Locale;
@@ -60,7 +61,7 @@
public ContainerPortletInfo(
PortletContainerImpl container,
- PortletResourceBundleManager bundleMgr,
+ ResourceBundleManager bundleMgr,
ContentTypes contentTypes)
{
PortletMetaData portletMD = container.getMetaData();
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPreferencesInfo.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPreferencesInfo.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/ContainerPreferencesInfo.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -25,6 +25,7 @@
import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.common.value.Value;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
import org.jboss.portal.portlet.impl.jsr168.metadata.PortletMetaData;
import org.jboss.portal.portlet.impl.jsr168.metadata.PreferenceMetaData;
import org.jboss.portal.portlet.info.PreferenceInfo;
@@ -52,7 +53,7 @@
content = new HashMap();
}
- public ContainerPreferencesInfo(PortletMetaData portletMD,
PortletResourceBundleManager bundleMgr)
+ public ContainerPreferencesInfo(PortletMetaData portletMD, ResourceBundleManager
bundleMgr)
{
content = new HashMap();
Deleted:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/PortletResourceBundleManager.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/PortletResourceBundleManager.java 2007-03-24
10:27:17 UTC (rev 6816)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/info/PortletResourceBundleManager.java 2007-03-24
22:32:21 UTC (rev 6817)
@@ -1,194 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.impl.jsr168.info;
-
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.util.EmptyResourceBundle;
-import org.jboss.portal.common.util.LocalizedString;
-import org.jboss.portal.common.util.ParentChildResourceBundle;
-import org.jboss.portal.portlet.impl.jsr168.metadata.LanguagesMetaData;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * Manage resource bundles for a portlet.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class PortletResourceBundleManager
-{
-
- private Logger log = Logger.getLogger(PortletResourceBundleManager.class);
-
- /** */
- private Map localeBundles;
-
- /** */
- private String baseName;
-
- /** */
- private ClassLoader classLoader;
-
- /** */
- private ResourceBundle infoBundle;
-
- /** */
- private Collection supportedLocales;
-
- public PortletResourceBundleManager(ClassLoader classLoader, LanguagesMetaData
metaData)
- {
- if (classLoader == null)
- {
- throw new IllegalArgumentException("Need a non null classloader");
- }
- if (metaData == null)
- {
- throw new IllegalArgumentException("Need non null meta data");
- }
- this.classLoader = classLoader;
- this.baseName = metaData.getResourceBundle();
- this.localeBundles = new HashMap();
- this.supportedLocales = metaData.getSupportedLocales();
-
- // Get the resource bundle containing the portlet info
- LanguagesMetaData.InfoMetaData infoMD = metaData.getInfo();
- if (infoMD != null)
- {
- infoBundle = new InfoBundle(infoMD);
- }
- else
- {
- infoBundle = new EmptyResourceBundle();
- }
- }
-
- /**
- * Return a localized value constructed from the various resource bundles. The
supported locales of the manager are
- * used in combination with the specified key. The default value is used if no value
is found for the
- * <code>Locale.ENGLISH</code>.
- *
- * @param key the key to lookup in the bundles
- * @param defaultValue
- * @return the localized string
- * @throws IllegalArgumentException if the key of the default value is null
- */
- public LocalizedString getLocalizedValue(String key, String defaultValue) throws
IllegalArgumentException
- {
- if (key == null)
- {
- throw new IllegalArgumentException("No null key accepted");
- }
- if (defaultValue == null)
- {
- throw new IllegalArgumentException("No null default value accepted");
- }
- Map m = new HashMap();
- for (Iterator j = supportedLocales.iterator(); j.hasNext();)
- {
- try
- {
- Locale locale = (Locale)j.next();
- ResourceBundle bundle = getResourceBundle(locale);
- String localizedDisplayName = bundle.getString(key);
- m.put(locale, localizedDisplayName);
- }
- catch (MissingResourceException ignore)
- {
- }
- }
- if (!m.containsKey(Locale.ENGLISH))
- {
- m.put(Locale.ENGLISH, defaultValue);
- }
- return new LocalizedString(m, Locale.ENGLISH);
- }
-
- /**
- * Return a bundle for the given locale. If the complete locale (language + country +
variant) does not exist then it
- * falls back to (language + country) or (language) or the default file.
- * <p/>
- * When the resource bundle object is found and was not in the global map, it put it
in that map with a copy on
- * write.
- *
- * @throws IllegalArgumentException if the locale is null
- */
- public ResourceBundle getResourceBundle(Locale locale) throws
IllegalArgumentException
- {
- // Arg check
- if (locale == null)
- {
- throw new IllegalArgumentException("Locale cannot be null");
- }
-
- // Try to get the bundle if the map
- ResourceBundle bundle = (ResourceBundle)localeBundles.get(locale);
- if (bundle != null)
- {
- return bundle;
- }
-
- //
- log.debug("Want to load bundle " + baseName + " for locale " +
locale);
-
- if (baseName == null)
- {
- bundle = infoBundle;
- }
- else
- {
- try
- {
- bundle = ResourceBundle.getBundle(baseName, locale, classLoader);
- if (infoBundle != null)
- {
- bundle = new ParentChildResourceBundle(infoBundle, bundle);
- }
- log.debug("Created bundle " + baseName + " for locale " +
locale);
- }
- catch (MissingResourceException e)
- {
- log.warn("Bundle " + baseName + " for locale " + locale +
" not found");
- bundle = infoBundle;
- }
- }
-
- // Cache the bundle
- if (bundle != null)
- {
- Map copy = new HashMap(localeBundles);
- copy.put(locale, bundle);
- localeBundles = copy;
- }
-
- //
- return bundle;
- }
-}