portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r884255 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/selector/ java/org/apache/jetspeed/portlets/spaces/ webapp/WEB-INF/view/selectors/
Date Wed, 25 Nov 2009 20:36:43 GMT
Author: taylor
Date: Wed Nov 25 20:36:43 2009
New Revision: 884255

URL: http://svn.apache.org/viewvc?rev=884255&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-1085
A Bug surfaced in Category Portlet Selector when storing defaults, the selector threw an NPE
during store to persistent preferences. Discovered that the selector was still coded against
2.1.3 apis, and needed to be updated. Then discovered the PortletDefinitionImpl never keeps
a copy of the Preferences collection, but always delegates to the Preferences Provider to
retrieve preferences, and then wrappers the result from the provider with every accessor call.
The selector was often dereferencing the prefs collection. This should not be a problem in
a normal transactional environment... For now, the problem can be avoided by only dereferencing
once, making manipulations to the held Preferences, and then 'committing' with a new storeDefaults
api which takes a second Preferences handle. Also got bogged down in an OJB debugging session
that turned out to be a simple typo in the OJB mapping file (username is not a primary key(!)).


Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/BreadcrumbMenu.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/selectors/category-edit-selector.vm

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java?rev=884255&r1=884254&r2=884255&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
Wed Nov 25 20:36:43 2009
@@ -43,6 +43,8 @@
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
+import org.apache.jetspeed.components.portletregistry.FailedToStorePortletDefinitionException;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.headerresource.HeaderResource;
 import org.apache.jetspeed.layout.PageLayoutComponent;
@@ -53,6 +55,7 @@
 import org.apache.jetspeed.om.portlet.PortletApplication;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.om.portlet.Preference;
+import org.apache.jetspeed.om.portlet.Preferences;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.portlets.CategoryInfo;
 import org.apache.jetspeed.portlets.PortletInfo;
@@ -97,6 +100,7 @@
 	private final String PAGENUMNER = "pageNumber";
 	private final String FILTER = "filter";
     
+    protected PortletPreferencesProvider preferenceService;	
     protected PortletRegistry registry;
     protected SearchEngine searchEngine;
     protected Profiler profiler;
@@ -134,6 +138,11 @@
         {
             throw new PortletException("Failed to find the PageLayoutComponent on portlet
initialization");
         }        
+        preferenceService = (PortletPreferencesProvider)context.getAttribute(CommonPortletServices.CPS_PORTLET_PREFERENCES_PROVIDER);
+        if (null == preferenceService)
+        {
+            throw new PortletException("Failed to find the Prefs Service on portlet initialization");
+        }
         rand = new Random( 19580427 );
     }
     
@@ -476,8 +485,9 @@
             PortletApplication pa = registry.getPortletApplication("j2-admin");
             String portletName = this.getPortletName();
             PortletDefinition portlet = (PortletDefinition) pa.getPortlet(portletName);
-            boolean updated = updateNumericPref("Columns", columns, 10, portlet);
-            updated = updated | updateNumericPref("Rows", rows, 100, portlet);
+            Preferences prefs = portlet.getPortletPreferences();
+            boolean updated = updateNumericPref("Columns", columns, 10, prefs);
+            updated = updated | updateNumericPref("Rows", rows, 100, prefs);
                         
             // process removes first
             if (!isEmpty(removes))
@@ -486,7 +496,7 @@
                 while (tokenizer.hasMoreTokens())
                 {
                     String name = tokenizer.nextToken().trim();
-                    updated = updated | removePref("Keywords:" + name, portlet);
+                    updated = updated | removePref("Keywords:" + name, prefs);
                 }                
             }
             
@@ -499,7 +509,7 @@
                 {
                     String name = tokenizer.nextToken().trim();
                     String keys = keyTokenizer.nextToken().trim();
-                    updated = updated | addPref("Keywords:" + name, keys, portlet);
+                    updated = updated | addPref("Keywords:" + name, keys, prefs);
                 }                
             }
             
@@ -512,7 +522,7 @@
                 {
                     String name = tokenizer.nextToken().trim();
                     String keys = keyTokenizer.nextToken().trim();                    
-                    updated = updated | modifyPref("Keywords:" + name, keys, portlet);
+                    updated = updated | modifyPref("Keywords:" + name, keys, prefs);
                 }                
             }
                                     
@@ -544,10 +554,11 @@
                         count++;
                     }
                     cats = temp.toString();
-                    modifyPref("Categories", cats, portlet);
+                    modifyPref("Categories", cats, prefs);
                     
                     // finally save it all
-                    registry.savePortletDefinition(portlet);
+                    //registry.savePortletDefinition(portlet);
+                    preferenceService.storeDefaults(portlet, prefs);                    
                 }
             }
             catch (Exception e)
@@ -584,50 +595,56 @@
         }
     }
 
-    private boolean addPref(String prefName, String keywords, PortletDefinition portlet)
+    private boolean addPref(String prefName, String keywords, Preferences prefs)
     {
-        Preference pref = portlet.getPortletPreferences().getPortletPreference(prefName);
       
+        Preference pref = prefs.getPortletPreference(prefName);
         if (pref == null)
         {
-            portlet.getPortletPreferences().addPreference(prefName);
-            pref = portlet.getPortletPreferences().getPortletPreference(prefName);
-            pref.addValue(keywords);
+            pref = prefs.addPreference(prefName);
+            pref.setReadOnly(false);
+            pref.addValue(keywords);            
         }
         else
         {
-            return modifyPref(prefName, keywords, portlet);           
+            return modifyPref(prefName, keywords, prefs);           
         }        
         return true;
     }
     
-    private boolean modifyPref(String prefName, String keywords, PortletDefinition portlet)
+    private boolean modifyPref(String prefName, String keywords, Preferences prefs)
     {
-        Preference prefComp =  portlet.getPortletPreferences().getPortletPreference(prefName);
-        List<String> values = prefComp.getValues();
-        if(!values.get(0).equals(keywords))
+        Preference pref = prefs.getPortletPreference(prefName);
+        if (pref == null)
         {
-            values.set(0, keywords);
-            return true;
+            return addPref(prefName, keywords, prefs);
+        }
+        else
+        {
+            List<String> values = pref.getValues();
+            if (!values.get(0).equals(keywords))
+            {
+                values.set(0, keywords);
+                return true;
+            }
         }
         return false;
     }
     
-    private boolean removePref(String prefName, PortletDefinition portlet)
+    private boolean removePref(String prefName, Preferences prefs)
     {
-        List<Preference> preferences = portlet.getPortletPreferences().getPortletPreferences();
-        
-        for(Preference pref : preferences)
+        List<Preference> prefs2 = prefs.getPortletPreferences();
+        for(Preference pref : prefs2)
         {
-            if(pref.getName().equals(prefName))
+            if (pref.getName().equals(prefName))
             {
-                preferences.remove(pref);
+                prefs2.remove(pref);
                 return true;
             }
         }
         return false;
     }
     
-    private boolean updateNumericPref(String prefName, String param, int max, PortletDefinition
portlet)
+    private boolean updateNumericPref(String prefName, String param, int max, Preferences
prefs)
     {
         if (!isEmpty(param))
         {
@@ -642,7 +659,7 @@
             }
             if (val > max)
                 return false;
-            Preference pref = (Preference) portlet.getPortletPreferences().getPortletPreference(prefName);
+            Preference pref = (Preference) prefs.getPortletPreference(prefName);
             List<String> values = pref.getValues();
             if(!values.get(0).equals(param))
             {

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/BreadcrumbMenu.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/BreadcrumbMenu.java?rev=884255&r1=884254&r2=884255&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/BreadcrumbMenu.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/BreadcrumbMenu.java
Wed Nov 25 20:36:43 2009
@@ -79,15 +79,18 @@
             Locale preferredLocale = rc.getLocale();
             PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)rc.getAttribute(PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
             Menu breadcrumbsMenu = siteRequestContext.getMenu("breadcrumbs");
-            List<MenuElement> breadcrumbsMenuElements = breadcrumbsMenu.getElements();
-            for (MenuElement breadcrumbMenuElement : breadcrumbsMenuElements)
+            if (breadcrumbsMenu != null)
             {
-                if (breadcrumbMenuElement instanceof MenuOption)
+                List<MenuElement> breadcrumbsMenuElements = breadcrumbsMenu.getElements();
+                for (MenuElement breadcrumbMenuElement : breadcrumbsMenuElements)
                 {
-                    MenuOption breadcrumbMenuOption = (MenuOption)breadcrumbMenuElement;
-                    String title = breadcrumbMenuOption.getTitle(preferredLocale);
-                    String url = admin.getPortalURL(request, response, breadcrumbMenuOption.getUrl());
-                    breadcrumbs.add(new BreadcrumbMenuItem(title, url));
+                    if (breadcrumbMenuElement instanceof MenuOption)
+                    {
+                        MenuOption breadcrumbMenuOption = (MenuOption)breadcrumbMenuElement;
+                        String title = breadcrumbMenuOption.getTitle(preferredLocale);
+                        String url = admin.getPortalURL(request, response, breadcrumbMenuOption.getUrl());
+                        breadcrumbs.add(new BreadcrumbMenuItem(title, url));
+                    }
                 }
             }
         }

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/selectors/category-edit-selector.vm
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/selectors/category-edit-selector.vm?rev=884255&r1=884254&r2=884255&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/selectors/category-edit-selector.vm
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/selectors/category-edit-selector.vm
Wed Nov 25 20:36:43 2009
@@ -183,7 +183,7 @@
         }
         //delete jsCategories;
         jsCategories = temp;
-        catList.remove(catList.selectedIndex);
+        catList.remove(catList.selectedIndex);        
     }
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message