Author: ate
Date: Fri Feb 26 01:21:40 2010
New Revision: 916524

URL: http://svn.apache.org/viewvc?rev=916524&view=rev
Log:
JS2-887: Jetspeed writes information to database when storing preferences in 
edit_defaults custom portlet mode
See: http://issues.apache.org/jira/browse/JS2-887

Fix completely prehibits the creation of default entity preferences in the 
preferences tables, only the fragment preferences are modified now. 

Added:
    
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
   (with props)
    
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
   (with props)
Modified:
    
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
    
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/
   (props changed)
    
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
    
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/
   (props changed)

Modified: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java?rev=916524&r1=916523&r2=916524&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
 (original)
+++ 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
 Fri Feb 26 01:21:40 2010
@@ -42,9 +42,11 @@
 import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.common.portlet.PrincipalAware;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.portlet.impl.FragmentPortletDefinition;
 import org.apache.jetspeed.om.preference.FragmentPreference;
+import org.apache.jetspeed.om.preference.impl.FragmentPreferenceSet;
 import org.apache.jetspeed.om.preference.impl.PrefsPreference;
 import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
 import org.apache.jetspeed.om.window.impl.PortletWindowListImpl;
@@ -78,7 +80,7 @@
     protected static RequestContextComponent rcc;
     protected static PageManager pm;
     
-    protected PrefsPreferenceSetImpl pagePreferenceSet;
+    protected PreferenceSetComposite pagePreferenceSet;
     protected Map perPrincipalPrefs = Collections.synchronizedMap(new 
HashMap());
     private PortletApplicationEntity applicationEntity = null;
     private PortletWindowList portletWindows = new PortletWindowListImpl();
@@ -172,39 +174,14 @@
     
     private PreferenceSet getPreferenceSetFromPage()
     {
-        PrefsPreferenceSetImpl preferenceSet = this.pagePreferenceSet;
+        PreferenceSetComposite preferenceSet = this.pagePreferenceSet;
         
-        try
-        {
-            if (preferenceSet == null || !dirty)
-            {
-                String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT 
+ "/" + 
-                                            getId() +"/"+ 
PrefsPreference.PORTLET_PREFERENCES_ROOT;
-
-                Preferences prefNode = 
Preferences.systemRoot().node(prefNodePath);
-                preferenceSet = new PrefsPreferenceSetImpl(prefNode);
-                this.pagePreferenceSet = preferenceSet;
-                
-                List fragmentPreferences = this.fragment.getPreferences();
-                
-                if (fragmentPreferences != null)
-                {
-                    for (Iterator it = fragmentPreferences.iterator(); 
it.hasNext(); )
-                    {
-                        FragmentPreference preference = (FragmentPreference) 
it.next();
-                        List preferenceValues = preference.getValueList();
-                        preferenceSet.add(preference.getName(), 
preferenceValues);
-                    }
-                }
-                dirty = true;
-            }
-        }
-        catch (BackingStoreException e)
+        if (preferenceSet == null || !dirty)
         {
-            String msg = "Preference backing store failed: " + e.toString();
-            IllegalStateException ise = new IllegalStateException(msg);
-            ise.initCause(e);
-            throw ise;
+            preferenceSet = new FragmentPreferenceSet(fragment, pm);
+            
+            this.pagePreferenceSet = preferenceSet;
+            dirty = true;
         }
         return preferenceSet;
     }
@@ -370,7 +347,7 @@
 
     public void reset() throws IOException
     {
-        dirty = true;
+        dirty = false;
         getPreferenceSet(getPrincipal());        
     }
 

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Feb 26 01:21:40 2010
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties

Added: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java?rev=916524&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
 (added)
+++ 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
 Fri Feb 26 01:21:40 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.om.preference.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PreferencesValidator;
+
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.preference.FragmentPreference;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.pluto.om.common.Preference;
+
+/**
+ * This is a per-request wrapper for a PreferenceSet that allows 
+ * editing the fragment-specified Preferences within a portlet instance
+ * in a page without need for database persistent preferences.
+ * 
+ * @version $Id$
+ */
+public class FragmentPreferenceSet implements PreferenceSetComposite
+{
+    private final Map prefs = new HashMap();
+    private final PageManager pm;
+    
+    public FragmentPreferenceSet(Fragment fragment, PageManager pm)
+    {
+        this.pm = pm;
+        
+        if (fragment != null && fragment.getPreferences() != null)
+        {
+            Iterator itr = fragment.getPreferences().iterator();        
+            while(itr.hasNext())
+            {
+                Preference pref = (Preference) itr.next();
+                prefs.put(pref.getName(), pref);
+            }
+        }
+    }
+
+    public Preference add(String name, List values)
+    {                
+        FragmentPreference preference = pm.newFragmentPreference();
+        preference.setName(name);
+        preference.setValueList(values);
+        prefs.put(name, preference);
+        return (Preference)preference;
+    }
+
+    public Preference get(String name)
+    {
+        return (Preference) prefs.get(name);
+    }
+
+    public Set getNames()
+    {
+        return prefs.keySet();
+    }
+
+    public PreferencesValidator getPreferencesValidator()
+    {
+        // never called by Pluto 1.0.1 container so no need to provide it here.
+        // Pluto only uses 
PortletDefinition.getPreferencesSet().getPreferencesValidator()      
+        return null;
+    }
+
+    public Iterator iterator()
+    {
+        return prefs.values().iterator();
+    }
+
+    public void remove(Preference pref)
+    {
+        prefs.remove(pref.getName());
+    }
+
+    public Preference remove(String name)
+    {
+        Preference pref = (Preference) prefs.remove(name);
+        return pref;
+    }
+
+    public int size()
+    {
+        return prefs.size();
+    }
+}

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java?rev=916524&r1=916523&r2=916524&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
 (original)
+++ 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
 Fri Feb 26 01:21:40 2010
@@ -42,9 +42,11 @@
 import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.common.portlet.PrincipalAware;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.portlet.impl.FragmentPortletDefinition;
 import org.apache.jetspeed.om.preference.FragmentPreference;
+import org.apache.jetspeed.om.preference.impl.FragmentPreferenceSet;
 import org.apache.jetspeed.om.preference.impl.PrefsPreference;
 import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
 import org.apache.jetspeed.om.window.impl.PortletWindowListImpl;
@@ -78,7 +80,7 @@
     protected static RequestContextComponent rcc;
     protected static PageManager pm;
     
-    protected PrefsPreferenceSetImpl pagePreferenceSet;
+    protected PreferenceSetComposite pagePreferenceSet;
     protected Map perPrincipalPrefs = Collections.synchronizedMap(new 
HashMap());
     private PortletApplicationEntity applicationEntity = null;
     private PortletWindowList portletWindows = new PortletWindowListImpl();
@@ -172,39 +174,14 @@
     
     private PreferenceSet getPreferenceSetFromPage()
     {
-        PrefsPreferenceSetImpl preferenceSet = this.pagePreferenceSet;
+        PreferenceSetComposite preferenceSet = this.pagePreferenceSet;
         
-        try
-        {
-            if (preferenceSet == null || !dirty)
-            {
-                String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT 
+ "/" + 
-                                            getId() +"/"+ 
PrefsPreference.PORTLET_PREFERENCES_ROOT;
-
-                Preferences prefNode = 
Preferences.systemRoot().node(prefNodePath);
-                preferenceSet = new PrefsPreferenceSetImpl(prefNode);
-                this.pagePreferenceSet = preferenceSet;
-                
-                List fragmentPreferences = this.fragment.getPreferences();
-                
-                if (fragmentPreferences != null)
-                {
-                    for (Iterator it = fragmentPreferences.iterator(); 
it.hasNext(); )
-                    {
-                        FragmentPreference preference = (FragmentPreference) 
it.next();
-                        List preferenceValues = preference.getValueList();
-                        preferenceSet.add(preference.getName(), 
preferenceValues);
-                    }
-                }
-                dirty = true;
-            }
-        }
-        catch (BackingStoreException e)
+        if (preferenceSet == null || !dirty)
         {
-            String msg = "Preference backing store failed: " + e.toString();
-            IllegalStateException ise = new IllegalStateException(msg);
-            ise.initCause(e);
-            throw ise;
+            preferenceSet = new FragmentPreferenceSet(fragment, pm);
+            
+            this.pagePreferenceSet = preferenceSet;
+            dirty = true;
         }
         return preferenceSet;
     }
@@ -370,7 +347,7 @@
 
     public void reset() throws IOException
     {
-        dirty = true;
+        dirty = false;
         getPreferenceSet(getPrincipal());        
     }
 
@@ -567,7 +544,7 @@
      * <p>
      * preRemoval
      * </p>
-     * not implemented.
+     *  not implemented.
      *
      * @see 
org.apache.jetspeed.components.persistence.store.RemovalAware#preRemoval(org.apache.jetspeed.components.persistence.store.PersistenceStore)
      * @param store

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Feb 26 01:21:40 2010
@@ -1,2 +1,2 @@
-target
+target
 surefire*.properties

Added: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java?rev=916524&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
 (added)
+++ 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
 Fri Feb 26 01:21:40 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.om.preference.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PreferencesValidator;
+
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.preference.FragmentPreference;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.pluto.om.common.Preference;
+
+/**
+ * This is a per-request wrapper for a PreferenceSet that allows 
+ * editing the fragment-specified Preferences within a portlet instance
+ * in a page without need for database persistent preferences.
+ * 
+ * @version $Id$
+ */
+public class FragmentPreferenceSet implements PreferenceSetComposite
+{
+    private final Map prefs = new HashMap();
+    private final PageManager pm;
+    
+    public FragmentPreferenceSet(Fragment fragment, PageManager pm)
+    {
+        this.pm = pm;
+        
+        if (fragment != null && fragment.getPreferences() != null)
+        {
+            Iterator itr = fragment.getPreferences().iterator();        
+            while(itr.hasNext())
+            {
+                Preference pref = (Preference) itr.next();
+                prefs.put(pref.getName(), pref);
+            }
+        }
+    }
+
+    public Preference add(String name, List values)
+    {                
+        FragmentPreference preference = pm.newFragmentPreference();
+        preference.setName(name);
+        preference.setValueList(values);
+        prefs.put(name, preference);
+        return (Preference)preference;
+    }
+
+    public Preference get(String name)
+    {
+        return (Preference) prefs.get(name);
+    }
+
+    public Set getNames()
+    {
+        return prefs.keySet();
+    }
+
+    public PreferencesValidator getPreferencesValidator()
+    {
+        // never called by Pluto 1.0.1 container so no need to provide it here.
+        // Pluto only uses 
PortletDefinition.getPreferencesSet().getPreferencesValidator()      
+        return null;
+    }
+
+    public Iterator iterator()
+    {
+        return prefs.values().iterator();
+    }
+
+    public void remove(Preference pref)
+    {
+        prefs.remove(pref.getName());
+    }
+
+    public Preference remove(String name)
+    {
+        Preference pref = (Preference) prefs.remove(name);
+        return pref;
+    }
+
+    public int size()
+    {
+        return prefs.size();
+    }
+}

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: 
portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPreferenceSet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to