portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1090149 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/clone/PortletCloneManagerPortlet.java
Date Fri, 08 Apr 2011 07:37:13 GMT
Author: woonsan
Date: Fri Apr  8 07:37:13 2011
New Revision: 1090149

URL: http://svn.apache.org/viewvc?rev=1090149&view=rev
Log:
JS2-1247: saving default preferences as well during cloning.
TODO: Use this cloning popup in the toolbox portlet.

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/clone/PortletCloneManagerPortlet.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/clone/PortletCloneManagerPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/clone/PortletCloneManagerPortlet.java?rev=1090149&r1=1090148&r2=1090149&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/clone/PortletCloneManagerPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/clone/PortletCloneManagerPortlet.java
Fri Apr  8 07:37:13 2011
@@ -35,9 +35,12 @@ import javax.portlet.RenderResponse;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.om.portlet.DisplayName;
 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.request.RequestContext;
 import org.apache.portals.bridges.common.GenericServletPortlet;
 import org.slf4j.Logger;
@@ -53,12 +56,15 @@ public class PortletCloneManagerPortlet 
     private static Logger log = LoggerFactory.getLogger(PortletCloneManagerPortlet.class);
     
     private PortletRegistry registry;
+    private PortletPreferencesProvider prefProvider;
     
     @Override
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
         registry = (PortletRegistry) config.getPortletContext().getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT);
+        prefProvider = (PortletPreferencesProvider) config.getPortletContext().getAttribute(CommonPortletServices.CPS_PORTLET_PREFERENCES_PROVIDER);
+
     }
     
     @Override
@@ -132,7 +138,45 @@ public class PortletCloneManagerPortlet 
             clone.getPortletInfo().setTitle(StringUtils.defaultString(clonePortletInfo.getPortletTitle()));
             clone.getPortletInfo().setShortTitle(StringUtils.defaultString(clonePortletInfo.getPortletShortTitle()));
             clone.getPortletInfo().setKeywords(StringUtils.defaultString(clonePortletInfo.getPortletKeywords()));
-            // TODO displayName, preferences..
+            
+            Locale defaultLocale = Locale.getDefault();
+            DisplayName defaultDisplayName = null;
+            
+            for (DisplayName displayName : clone.getDisplayNames())
+            {
+                if (displayName.getLocale().equals(defaultLocale))
+                {
+                    defaultDisplayName = displayName;
+                    break;
+                }
+            }
+            
+            if (defaultDisplayName == null)
+            {
+                defaultDisplayName = clone.addDisplayName(defaultLocale.toString());
+            }
+            
+            defaultDisplayName.setDisplayName(StringUtils.defaultString(clonePortletInfo.getPortletDisplayName()));
+            
+            for (Map.Entry<String, List<String>> entry : clonePortletInfo.getPortletPreferences().entrySet())
+            {
+                String prefName = entry.getKey();
+                List<String> prefValues = entry.getValue();
+                Preferences prefs = clone.getPortletPreferences();
+                Preference pref = prefs.getPortletPreference(prefName);
+                
+                if (pref == null)
+                {
+                    pref = prefs.addPreference(prefName);
+                }
+                
+                List<String> values = pref.getValues();
+                values.clear();
+                values.addAll(prefValues);
+                
+                prefProvider.storeDefaults(clone, pref);
+            }
+            
             registry.savePortletDefinition(clone);
             status = "success";
         }



---------------------------------------------------------------------
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