You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2006/01/10 13:45:48 UTC

svn commit: r367588 - in /portals/pluto/trunk: pluto-container/src/main/java/org/apache/pluto/ pluto-container/src/main/java/org/apache/pluto/core/impl/ pluto-container/src/test/java/org/apache/pluto/core/impl/ pluto-descriptor-api/src/main/java/org/ap...

Author: ddewolf
Date: Tue Jan 10 04:45:28 2006
New Revision: 367588

URL: http://svn.apache.org/viewcvs?rev=367588&view=rev
Log:
Spec bug fixes.  GetResourceBundle now merges inline properties with resource props.  Preferences null pointers removed

Added:
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/CombinedPortletResourceBundle.java
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/InlinePortletResourceBundle.java
Modified:
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/Constants.java
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletConfigImpl.java
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/ResourceBundleFactory.java
    portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/core/impl/ResourceBundleFactoryTest.java
    portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletDD.java
    portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferenceDD.java
    portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferencesDD.java
    portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/classes/simplelog.properties

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/Constants.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/Constants.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/Constants.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/Constants.java Tue Jan 10 04:45:28 2006
@@ -45,6 +45,21 @@
     public final static String PORTLET_CONFIG = "javax.portlet.config";
 
     /**
+     *
+     */
+    public final static String TITLE_KEY = "javax.portlet.title";
+
+    /**
+     *
+     */
+    public final static String SHORT_TITLE_KEY = "javax.portlet.short-title";
+
+    /**
+     * 
+     */
+    public final static String KEYWORDS_KEY = "javax.portlet.keywords";
+
+    /**
      * The key used to bind the method of processing being requested by the
      * container to the underlying <code>PortletRquest</code>.
      */
@@ -73,5 +88,6 @@
      * method.
      */
     public final static Integer METHOD_NOOP = new Integer(5);
+
 
 }

Added: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/CombinedPortletResourceBundle.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/CombinedPortletResourceBundle.java?rev=367588&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/CombinedPortletResourceBundle.java (added)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/CombinedPortletResourceBundle.java Tue Jan 10 04:45:28 2006
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.pluto.core.impl;
+
+import org.apache.pluto.util.StringManager;
+
+import java.util.ResourceBundle;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Vector;
+
+/**
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Jan 9, 2006
+ */
+class CombinedPortletResourceBundle extends ResourceBundle {
+
+    private static final StringManager EXCEPTIONS =
+        StringManager.getManager(CombinedPortletResourceBundle.class.getPackage().getName());
+
+    private HashMap contents = new HashMap();
+
+    public CombinedPortletResourceBundle(InlinePortletResourceBundle inlineBundle, ResourceBundle resourceBundle) {
+       dump(inlineBundle);
+       dump(resourceBundle);
+    }
+
+    protected Object handleGetObject(String key) {
+        if(key == null) {
+            throw new NullPointerException(EXCEPTIONS.getString("error.null"));
+        }
+        return contents.get(key);
+    }
+
+    public Enumeration getKeys() {
+       return new Vector(contents.keySet()).elements();
+    }
+
+    private void dump(ResourceBundle bundle) {
+        Enumeration e = bundle.getKeys();
+        while(e.hasMoreElements()) {
+            String value = e.nextElement().toString();
+            contents.put(value, bundle.getObject(value));
+        }
+    }
+}

Added: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/InlinePortletResourceBundle.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/InlinePortletResourceBundle.java?rev=367588&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/InlinePortletResourceBundle.java (added)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/InlinePortletResourceBundle.java Tue Jan 10 04:45:28 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.pluto.core.impl;
+
+import org.apache.pluto.Constants;
+
+import java.util.ListResourceBundle;
+import java.util.ArrayList;
+
+/**
+ * InlinePortletResourceBundle implementation which provides the
+ * inline title, short-title, and keywords as properties from the
+ * bundle.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
+ * @version 1.0
+ * @since Jan 9, 2006
+ */
+class InlinePortletResourceBundle extends ListResourceBundle {
+
+    private Object[][] contents;
+
+    public InlinePortletResourceBundle(Object[][] contents) {
+        this.contents = contents;
+    }
+
+    public InlinePortletResourceBundle(String title, String shortTitle, String keywords) {
+        ArrayList temp = new ArrayList();
+        if(title != null)
+            temp.add(new Object[] {Constants.TITLE_KEY, title});
+
+        if(shortTitle != null)
+            temp.add(new Object[] {Constants.SHORT_TITLE_KEY, shortTitle});
+
+        if(keywords != null)
+            temp.add(new Object[] {Constants.KEYWORDS_KEY, keywords});
+
+        contents = (Object[][])temp.toArray(new Object[temp.size()][]);
+    }
+
+    protected Object[][] getContents() {
+        return contents;
+    }
+}

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletConfigImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletConfigImpl.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletConfigImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/PortletConfigImpl.java Tue Jan 10 04:45:28 2006
@@ -22,18 +22,31 @@
 import org.apache.pluto.core.InternalPortletConfig;
 import org.apache.pluto.descriptors.common.InitParamDD;
 import org.apache.pluto.descriptors.portlet.PortletDD;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.servlet.ServletConfig;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.ResourceBundle;
+import java.util.*;
 
 public class PortletConfigImpl implements PortletConfig, InternalPortletConfig {
+
+    private static final Log LOG = LogFactory.getLog(PortletConfigImpl.class);
+
+    /**
+     * The servlet config for which we exist.
+     */
     private ServletConfig servletConfig;
+
+    /**
+     * The Portlet Application Context within which we exist.
+     */
     private PortletContext portletContext;
+
+    /**
+     * The portlet descriptor.
+     */
     protected PortletDD portletDD;
 
     private ResourceBundleFactory bundles;
@@ -54,7 +67,10 @@
         return portletContext;
     }
 
-    public ResourceBundle getResourceBundle(java.util.Locale locale) {
+    public ResourceBundle getResourceBundle(Locale locale) {
+        if(LOG.isDebugEnabled()) {
+            LOG.debug("Resource Bundle requested: "+locale);
+        }
         if (bundles == null) {
             bundles = new ResourceBundleFactory(portletDD);
         }

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/ResourceBundleFactory.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/ResourceBundleFactory.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/ResourceBundleFactory.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/impl/ResourceBundleFactory.java Tue Jan 10 04:45:28 2006
@@ -38,30 +38,15 @@
         StringManager.getManager(ResourceBundleFactory.class.getPackage().getName());
 
     /**
-     * The String value utilized for missing keys.
-     * Specifically, whenever <code>javax.portlet.title</code>,
-     * <code>javax.portlet.shorttitle</code>, or <code>javax.portlet.keywords</code>
-     * are null, this value will be returned.
-     */
-    private static final String NA = "N/A";
-
-    /**
-     * The default resource bundle which is utilized when
-     * the info is not set in the PortletInfo OR in the
-     * actual resource bundle.
-     */
-    private static final ResourceBundle EMPTY_BUNDLE = createDefaultBundle(null, null, null);
-
-    /**
      * The default (no local) resources bundle for
      * this bundle.
      */
-    private ResourceBundle defaultBundle;
+    private InlinePortletResourceBundle defaultBundle;
 
     /**
      * All of the previously loaded bundles.
      */
-    private Map bundles = new java.util.HashMap();
+    private Map bundles = new HashMap();
 
     /**
      * The name of the bundle.
@@ -70,21 +55,25 @@
 
     public ResourceBundleFactory(PortletDD dd) {
         bundleName = dd.getResourceBundle();
+        if(LOG.isDebugEnabled()) {
+            LOG.debug("Resource Bundle Created: "+bundleName);
+        }
 
         PortletInfoDD info = dd.getPortletInfo();
         if(info != null) {
-            defaultBundle = createDefaultBundle(
-                    info.getTitle(),
-                    info.getShortTitle(),
-                    info.getKeywords()
+            defaultBundle = new InlinePortletResourceBundle(
+                info.getTitle(), info.getShortTitle(), info.getKeywords()
             );
         }
         else {
-            defaultBundle = EMPTY_BUNDLE;
+            defaultBundle = new InlinePortletResourceBundle(new Object[][] { {"a", "b"} });
         }
-    }
+   }
 
     public ResourceBundle getResourceBundle(Locale locale) {
+        if(LOG.isDebugEnabled()) {
+            LOG.debug("Resource Bundle: "+bundleName+" : "+locale+" requested. ");
+        }
 
         // If allready loaded for this local, return immediately!
         if (bundles.containsKey(locale)) {
@@ -92,44 +81,25 @@
         }
 
         try {
-            if (bundleName != null) {
-                ClassLoader loader = Thread.currentThread()
-                    .getContextClassLoader();
-                ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
-                                                                 locale,
-                                                                 loader);
-                if (bundle != null) {
-                    bundles.put(locale, bundle);
-                    return bundle;
-                }
+            ResourceBundle bundle = null;
+            if(bundleName != null) {
+                ClassLoader loader =
+                        Thread.currentThread().getContextClassLoader();
+                bundle = ResourceBundle.getBundle(bundleName, locale, loader);
+                bundles.put(locale, new CombinedPortletResourceBundle(defaultBundle, bundle));
             }
-        } catch (MissingResourceException mre) {
-            LOG.info(
-                EXCEPTIONS.getString("warning.resourcebundle.notfound",bundleName, mre.getMessage())
-            );
-            // intentionally swallow.  Allow the default Bundle.
-        }
-
-        bundles.put(locale, defaultBundle);
-        return defaultBundle;
-    }
-
-    private static ResourceBundle createDefaultBundle(String title, String shortTitle, String keywords) {
-        String titleValue = title == null ? NA : title;
-        String shortValue = shortTitle == null ? NA : shortTitle;
-        String keysValue = keywords == null ? NA : keywords;
-
-        final String[] a = new String[] {"javax.portlet.title", titleValue};
-        final String[] b = new String[] {"javax.portlet.shorttitle", shortValue};
-        final String[] c = new String[] {"javax.portlet.keywords", keysValue };
-
-        ResourceBundle defaultBundle = new ListResourceBundle() {
-            Object[][] contents =  new String[][]{a, b, c};
-            public Object[][] getContents() {
-                return contents;
+            else {
+                bundles.put(locale, defaultBundle);
             }
-        };
-
-        return defaultBundle;
+       } catch (MissingResourceException mre) {
+            if(bundleName != null && LOG.isWarnEnabled()) {
+                LOG.info(EXCEPTIONS.getString("warning.resourcebundle.notfound",bundleName, mre.getMessage()));
+            }
+            if(LOG.isDebugEnabled()) {
+                LOG.debug("Using default bundle for locale ("+locale+").");
+            }
+            bundles.put(locale, defaultBundle);
+        }
+       return (ResourceBundle)bundles.get(locale);
     }
 }

Modified: portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/core/impl/ResourceBundleFactoryTest.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/core/impl/ResourceBundleFactoryTest.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/core/impl/ResourceBundleFactoryTest.java (original)
+++ portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/core/impl/ResourceBundleFactoryTest.java Tue Jan 10 04:45:28 2006
@@ -58,7 +58,7 @@
         ResourceBundle bundle = factory.getResourceBundle(Locale.getDefault());
 
         Assert.assertEquals("Bundle Title", bundle.getString("javax.portlet.title"));
-        Assert.assertEquals("Bundle Short Title", bundle.getString("javax.portlet.shorttitle"));
+        Assert.assertEquals("Bundle Short Title", bundle.getString("javax.portlet.short-title"));
         Assert.assertEquals("Bundle Keywords", bundle.getString("javax.portlet.keywords"));
     }
 
@@ -68,7 +68,7 @@
         ResourceBundle bundle = factory.getResourceBundle(Locale.getDefault());
 
         Assert.assertEquals("Info Title", bundle.getString("javax.portlet.title"));
-        Assert.assertEquals("Info Short Title", bundle.getString("javax.portlet.shorttitle"));
+        Assert.assertEquals("Info Short Title", bundle.getString("javax.portlet.short-title"));
         Assert.assertEquals("Info Keywords", bundle.getString("javax.portlet.keywords"));
     }
 
@@ -78,7 +78,7 @@
         ResourceBundle bundle = factory.getResourceBundle(Locale.getDefault());
 
         Assert.assertEquals("Bundle Title", bundle.getString("javax.portlet.title"));
-        Assert.assertEquals("Bundle Short Title", bundle.getString("javax.portlet.shorttitle"));
+        Assert.assertEquals("Bundle Short Title", bundle.getString("javax.portlet.short-title"));
         Assert.assertEquals("Bundle Keywords", bundle.getString("javax.portlet.keywords"));
     }
 
@@ -90,9 +90,29 @@
         ResourceBundleFactory factory = new ResourceBundleFactory(validDD);
         ResourceBundle bundle = factory.getResourceBundle(Locale.getDefault());
 
-        Assert.assertEquals("N/A", bundle.getString("javax.portlet.title"));
-        Assert.assertEquals("N/A", bundle.getString("javax.portlet.shorttitle"));
-        Assert.assertEquals("N/A", bundle.getString("javax.portlet.keywords"));
+        try {
+            Assert.assertEquals(null, bundle.getString("javax.portlet.title"));
+            fail("Exception should have been thrown.");
+        }
+        catch(Throwable t) {
+
+        }
+
+        try {
+            Assert.assertEquals(null, bundle.getString("javax.portlet.short-title"));
+            fail("Exception should have been throw.");
+        }
+        catch(Throwable t) {
+
+        }
+
+        try {
+            Assert.assertEquals(null, bundle.getString("javax.portlet.keywords"));
+            fail("Exception should have been thrown.");
+        }
+        catch(Throwable t) {
+
+        }
     }
 
 
@@ -100,7 +120,7 @@
         
         private Object[][] contents = {
             {"javax.portlet.title", "Bundle Title"},
-            {"javax.portlet.shorttitle", "Bundle Short Title"},
+            {"javax.portlet.short-title", "Bundle Short Title"},
             {"javax.portlet.keywords", "Bundle Keywords"}
         };
 

Modified: portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletDD.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletDD.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletDD.java (original)
+++ portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletDD.java Tue Jan 10 04:45:28 2006
@@ -39,7 +39,7 @@
 
     private PortletInfoDD portletInfo;
 
-    private PortletPreferencesDD portletPreferences;
+    private PortletPreferencesDD portletPreferences = new PortletPreferencesDD();
 
     private List initParams = new ArrayList();
 

Modified: portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferenceDD.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferenceDD.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferenceDD.java (original)
+++ portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferenceDD.java Tue Jan 10 04:45:28 2006
@@ -17,6 +17,7 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * <B>TODO:</B> Document
@@ -27,7 +28,7 @@
 public class PortletPreferenceDD {
 
     private String name;
-    private List values;
+    private List values = new ArrayList();
 
     public String getName() {
         return name;

Modified: portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferencesDD.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferencesDD.java?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferencesDD.java (original)
+++ portals/pluto/trunk/pluto-descriptor-api/src/main/java/org/apache/pluto/descriptors/portlet/PortletPreferencesDD.java Tue Jan 10 04:45:28 2006
@@ -16,6 +16,7 @@
 package org.apache.pluto.descriptors.portlet;
 
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * <B>TODO:</B> Document
@@ -25,7 +26,7 @@
  */
 public class PortletPreferencesDD {
 
-    private List portletPreferences;
+    private List portletPreferences = new ArrayList();
     private String preferencesValidator;
 
     public List getPortletPreferences() {

Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/classes/simplelog.properties
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/classes/simplelog.properties?rev=367588&r1=367587&r2=367588&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/classes/simplelog.properties (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/classes/simplelog.properties Tue Jan 10 04:45:28 2006
@@ -9,4 +9,5 @@
 org.apache.commons.logging.simplelog.log.org.apache.pluto.core.PortletContainerImpl=DEBUG
 org.apache.commons.logging.simplelog.log.org.apache.pluto.driver.PortalStartupListener=DEBUG
 org.apache.commons.logging.simplelog.log.org.apache.pluto.driver.core.PortalUrlParser=DEBUG
+org.apache.commons.logging.simplelog.log.org.apache.pluto.driver.core.impl.ResourceBundleFactory=DEBUG
 org.apache.commons.logging.simplelog.log.org.apache.pluto.driver.config.DriverConfigurationFactory=ERROR