Author: hoang_to
Date: 2010-11-23 02:35:23 -0500 (Tue, 23 Nov 2010)
New Revision: 5211
Added:
exo/portal/branches/3.1.x/component/resources/src/test/java/locale/portlet_en.properties
Modified:
exo/portal/branches/3.1.x/component/resources/src/main/java/org/exoplatform/services/resources/impl/BaseResourceBundleService.java
exo/portal/branches/3.1.x/component/resources/src/test/java/org/exoplatform/services/resources/test/TestResourceBundleService.java
Log:
EXOGTN-131: Apply ECM-validated patch and JUnit test
Modified:
exo/portal/branches/3.1.x/component/resources/src/main/java/org/exoplatform/services/resources/impl/BaseResourceBundleService.java
===================================================================
---
exo/portal/branches/3.1.x/component/resources/src/main/java/org/exoplatform/services/resources/impl/BaseResourceBundleService.java 2010-11-23
04:07:49 UTC (rev 5210)
+++
exo/portal/branches/3.1.x/component/resources/src/main/java/org/exoplatform/services/resources/impl/BaseResourceBundleService.java 2010-11-23
07:35:23 UTC (rev 5211)
@@ -22,6 +22,7 @@
import org.exoplatform.commons.utils.IOUtil;
import org.exoplatform.commons.utils.MapResourceBundle;
import org.exoplatform.commons.utils.PageList;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.services.log.Log;
@@ -42,12 +43,10 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
-import java.util.Set;
/**
* Created by The eXo Platform SAS Mar 9, 2007
@@ -383,11 +382,6 @@
return IdentityResourceBundle.getInstance();
}
- // Case 1: ResourceBundle of portlets, standard java API is used
- if (isClasspathResource(name))
- return ResourceBundleLoader.load(name, locale, cl);
-
- // Case 2: ResourceBundle of portal
String country = locale.getCountry();
String id;
if (country != null && country.length() > 0)
@@ -399,18 +393,39 @@
id = name + "_" + locale.getLanguage();
}
- try
+ boolean isClasspathResource = isClasspathResource(name);
+ boolean isCacheable = !isClasspathResource || !PropertyManager.isDevelopping();
+ if (isCacheable)
{
- ResourceBundle rb = cache_.get(id);
- if (rb != null)
+ if (isClasspathResource)
{
- return rb;
+ // Avoid naming collision
+ id += "_" + cl.getClass() + "_" + cl.hashCode();
}
+ try
+ {
+ ResourceBundle rb = cache_.get(id);
+ if (rb != null)
+ {
+ return rb;
+ }
+ }
+ catch (Exception ex)
+ {
+ }
}
- catch (Exception ex)
+
+ // Case 1: ResourceBundle of portlets, standard java API is used
+ if (isClasspathResource)
{
+ ResourceBundle res = ResourceBundleLoader.load(name, locale, cl);
+ //Cache classpath resource bundle while running portal in non-dev mode
+ if (isCacheable)
+ cache_.put(id, res);
+ return res;
}
+ // Case 2: ResourceBundle of portal
try
{
ResourceBundle res = null;
Added:
exo/portal/branches/3.1.x/component/resources/src/test/java/locale/portlet_en.properties
===================================================================
---
exo/portal/branches/3.1.x/component/resources/src/test/java/locale/portlet_en.properties
(rev 0)
+++
exo/portal/branches/3.1.x/component/resources/src/test/java/locale/portlet_en.properties 2010-11-23
07:35:23 UTC (rev 5211)
@@ -0,0 +1,20 @@
+#
+# Copyright (C) 2009 eXo Platform SAS.
+#
+# 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.
+#
+
+language.language=English
Modified:
exo/portal/branches/3.1.x/component/resources/src/test/java/org/exoplatform/services/resources/test/TestResourceBundleService.java
===================================================================
---
exo/portal/branches/3.1.x/component/resources/src/test/java/org/exoplatform/services/resources/test/TestResourceBundleService.java 2010-11-23
04:07:49 UTC (rev 5210)
+++
exo/portal/branches/3.1.x/component/resources/src/test/java/org/exoplatform/services/resources/test/TestResourceBundleService.java 2010-11-23
07:35:23 UTC (rev 5211)
@@ -19,8 +19,13 @@
package org.exoplatform.services.resources.test;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.PortalContainer;
-import org.exoplatform.services.resources.*;
+import org.exoplatform.services.resources.AbstractResourceBundleTest;
+import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.Query;
+import org.exoplatform.services.resources.ResourceBundleData;
+import org.exoplatform.services.resources.ResourceBundleService;
import java.util.List;
import java.util.Locale;
@@ -178,4 +183,33 @@
{
return "Test Resource Bundle Service";
}
+
+ public void testClasspathResourceCache()
+ {
+ String oldValue = PropertyManager.getProperty(PropertyManager.DEVELOPING);
+ try
+ {
+ PropertyManager.setProperty(PropertyManager.DEVELOPING, "false");
+ assertFalse(PropertyManager.isDevelopping());
+ MyClassLoader cl1 = new MyClassLoader();
+ ResourceBundle res = service_.getResourceBundle("locale.portlet",
Locale.ENGLISH, cl1);
+ assertNotNull(res);
+ assertTrue(res == service_.getResourceBundle("locale.portlet",
Locale.ENGLISH, cl1));
+ assertFalse(res == service_.getResourceBundle("locale.portlet",
Locale.ENGLISH, new MyClassLoader()));
+ }
+ finally
+ {
+ PropertyManager.setProperty(PropertyManager.DEVELOPING, oldValue);
+ }
+ }
+
+ private static class MyClassLoader extends ClassLoader
+ {
+
+ @Override
+ public String toString()
+ {
+ return "MyClassLoader";
+ }
+ }
}