portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r371848 - in /portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page: impl/FilteredFragmentList.java impl/FragmentImpl.java impl/PageImpl.java psml/FilteredFragmentList.java psml/FragmentImpl.java
Date Tue, 24 Jan 2006 07:01:47 GMT
Author: rwatler
Date: Mon Jan 23 23:01:45 2006
New Revision: 371848

URL: http://svn.apache.org/viewcvs?rev=371848&view=rev
Log:
ensure Fragment fragments lists always immutable: see JS2-473

Added:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FilteredFragmentList.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FilteredFragmentList.java
Modified:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FragmentImpl.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/PageImpl.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java

Added: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FilteredFragmentList.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FilteredFragmentList.java?rev=371848&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FilteredFragmentList.java
(added)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FilteredFragmentList.java
Mon Jan 23 23:01:45 2006
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2005 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.jetspeed.om.page.impl;
+
+import java.util.AbstractList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * FragmentList
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+class FilteredFragmentList extends AbstractList
+{
+    private FragmentImpl fragment;
+    private List filteredList;
+
+    FilteredFragmentList(FragmentImpl fragment, List filteredList)
+    {
+        super();
+        this.fragment = fragment;
+        this.filteredList = filteredList;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#add(int,java.lang.Object)
+     */
+    public void add(int index, Object element)
+    {
+        // implement for modifiable AbstractList
+        filteredList.add(index, element);
+        // add object to persistent list
+        fragment.accessFragments().add(element);
+        // maintain page implementation reference
+        if ((fragment.getPage() != null) && (element instanceof FragmentImpl))
+        {
+            ((FragmentImpl)element).setPage(fragment.getPage());
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#get(int)
+     */
+    public Object get(int index)
+    {
+        // implement for modifiable AbstractList
+        return filteredList.get(index);
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#remove(int)
+     */
+    public Object remove(int index)
+    {
+        // implement for modifiable AbstractList
+        Object o = filteredList.remove(index);
+        // remove removed object from persistent list
+        if (o != null)
+        {
+            ListIterator iter = fragment.accessFragments().listIterator();
+            while (iter.hasNext())
+            {
+                if (iter.next() == o)
+                {
+                    iter.remove();
+                    break;
+                }
+            }
+        }
+        return o;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#set(int,java.lang.Object)
+     */
+    public Object set(int index, Object element)
+    {
+        // implement for modifiable AbstractList
+        Object o = filteredList.set(index, element);
+        // replace replaced object in persistent list
+        if (o != null)
+        {
+            ListIterator iter = fragment.accessFragments().listIterator();
+            while (iter.hasNext())
+            {
+                if (iter.next() == o)
+                {
+                    iter.set(element);
+                    break;
+                }
+            }
+        }
+        // maintain page implementation reference
+        if ((fragment.getPage() != null) && (element instanceof FragmentImpl))
+        {
+            ((FragmentImpl)element).setPage(fragment.getPage());
+        }
+        return o;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#size()
+     */
+    public int size()
+    {
+        // implement for modifiable AbstractList
+        return filteredList.size();
+    }
+}

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FragmentImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FragmentImpl.java?rev=371848&r1=371847&r2=371848&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FragmentImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/FragmentImpl.java
Mon Jan 23 23:01:45 2006
@@ -556,16 +556,13 @@
      */
     public List getFragments()
     {
-        // mutable fragments collection must be defined... note
-        // that this collection is only mutable if user has full
-        // access rights to all fragments; otherwise, a copy of
-        // the list will be returned and any modifications to the
-        // set of fragments in the collection will not be preserved
+        // create and return mutable fragments collection
+        // filtered by view access
         if (fragmentsList == null)
         {
             fragmentsList = new FragmentList(this);
         }
-        return filterFragmentsByAccess(fragmentsList);
+        return filterFragmentsByAccess(fragmentsList, true);
     }
     
     /* (non-Javadoc)
@@ -726,10 +723,11 @@
      * Filter fragments list for view access.
      *
      * @param nodes list containing fragments to check
+     * @param mutable make returned list mutable
      * @return original list if all elements viewable, a filtered
      *         partial list, or null if all filtered for view access
      */
-    static List filterFragmentsByAccess(List fragments)
+    List filterFragmentsByAccess(List fragments, boolean mutable)
     {
         if ((fragments != null) && !fragments.isEmpty())
         {
@@ -781,7 +779,14 @@
             {
                 if (!filteredFragments.isEmpty())
                 {
-                    return filteredFragments;
+                    if (mutable)
+                    {
+                        return new FilteredFragmentList(this, filteredFragments);
+                    }
+                    else
+                    {
+                        return filteredFragments;
+                    }
                 }
                 else
                 {

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/PageImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/PageImpl.java?rev=371848&r1=371847&r2=371848&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/PageImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/impl/PageImpl.java
Mon Jan 23 23:01:45 2006
@@ -306,7 +306,8 @@
         FragmentImpl rootFragment = (FragmentImpl)getRootFragment();
         if (rootFragment != null)
         {
-            return FragmentImpl.filterFragmentsByAccess(rootFragment.getFragmentsByName(name));
+            // return immutable filtered fragment list
+            return rootFragment.filterFragmentsByAccess(rootFragment.getFragmentsByName(name),
false);
         }
         return null;
     }

Added: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FilteredFragmentList.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FilteredFragmentList.java?rev=371848&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FilteredFragmentList.java
(added)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FilteredFragmentList.java
Mon Jan 23 23:01:45 2006
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2005 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.jetspeed.om.page.psml;
+
+import java.util.AbstractList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * FragmentList
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+class FilteredFragmentList extends AbstractList
+{
+    private FragmentImpl fragment;
+    private List filteredList;
+
+    FilteredFragmentList(FragmentImpl fragment, List filteredList)
+    {
+        super();
+        this.fragment = fragment;
+        this.filteredList = filteredList;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#add(int,java.lang.Object)
+     */
+    public void add(int index, Object element)
+    {
+        // implement for modifiable AbstractList
+        filteredList.add(index, element);
+        // add object to persistent list
+        fragment.accessFragments().add(element);
+        // maintain page implementation reference
+        if ((fragment.getPage() != null) && (element instanceof FragmentImpl))
+        {
+            ((FragmentImpl)element).setPage(fragment.getPage());
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#get(int)
+     */
+    public Object get(int index)
+    {
+        // implement for modifiable AbstractList
+        return filteredList.get(index);
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#remove(int)
+     */
+    public Object remove(int index)
+    {
+        // implement for modifiable AbstractList
+        Object o = filteredList.remove(index);
+        // remove removed object from persistent list
+        if (o != null)
+        {
+            ListIterator iter = fragment.accessFragments().listIterator();
+            while (iter.hasNext())
+            {
+                if (iter.next() == o)
+                {
+                    iter.remove();
+                    break;
+                }
+            }
+        }
+        return o;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#set(int,java.lang.Object)
+     */
+    public Object set(int index, Object element)
+    {
+        // implement for modifiable AbstractList
+        Object o = filteredList.set(index, element);
+        // replace replaced object in persistent list
+        if (o != null)
+        {
+            ListIterator iter = fragment.accessFragments().listIterator();
+            while (iter.hasNext())
+            {
+                if (iter.next() == o)
+                {
+                    iter.set(element);
+                    break;
+                }
+            }
+        }
+        // maintain page implementation reference
+        if ((fragment.getPage() != null) && (element instanceof FragmentImpl))
+        {
+            ((FragmentImpl)element).setPage(fragment.getPage());
+        }
+        return o;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#size()
+     */
+    public int size()
+    {
+        // implement for modifiable AbstractList
+        return filteredList.size();
+    }
+}

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java?rev=371848&r1=371847&r2=371848&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java
Mon Jan 23 23:01:45 2006
@@ -119,7 +119,8 @@
 
     public List getFragments()
     {
-        // return mutable fragments list if possible
+        // create and return mutable fragments collection
+        // filtered by view access
         if (fragmentsList == null)
         {
             fragmentsList = new FragmentList(this);
@@ -501,7 +502,7 @@
      * @return original list if all elements viewable, a filtered
      *         partial list, or null if all filtered for view access
      */
-    static List filterFragmentsByAccess(List fragments)
+    List filterFragmentsByAccess(List fragments)
     {
         if ((fragments != null) && !fragments.isEmpty())
         {
@@ -553,7 +554,7 @@
             {
                 if (!filteredFragments.isEmpty())
                 {
-                    return filteredFragments;
+                    return new FilteredFragmentList(this, filteredFragments);
                 }
                 else
                 {



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