portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r209927 - /portals/jetspeed-2/branches/MENUS_BRANCH/components/portal-site/src/java/org/apache/jetspeed/portalsite/impl/PortalSiteRequestContextImpl.java
Date Sat, 09 Jul 2005 05:42:31 GMT
Author: rwatler
Date: Fri Jul  8 22:42:29 2005
New Revision: 209927

URL: http://svn.apache.org/viewcvs?rev=209927&view=rev
Log:
implement required hidden folder/page/link filtering to and caching for compatibility API
methods

Modified:
    portals/jetspeed-2/branches/MENUS_BRANCH/components/portal-site/src/java/org/apache/jetspeed/portalsite/impl/PortalSiteRequestContextImpl.java

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/components/portal-site/src/java/org/apache/jetspeed/portalsite/impl/PortalSiteRequestContextImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/components/portal-site/src/java/org/apache/jetspeed/portalsite/impl/PortalSiteRequestContextImpl.java?rev=209927&r1=209926&r2=209927&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/components/portal-site/src/java/org/apache/jetspeed/portalsite/impl/PortalSiteRequestContextImpl.java
(original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/components/portal-site/src/java/org/apache/jetspeed/portalsite/impl/PortalSiteRequestContextImpl.java
Fri Jul  8 22:42:29 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.jetspeed.portalsite.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -25,9 +26,11 @@
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.MenuDefinition;
 import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.document.Node;
 import org.apache.jetspeed.page.document.NodeException;
 import org.apache.jetspeed.page.document.NodeNotFoundException;
 import org.apache.jetspeed.page.document.NodeSet;
+import org.apache.jetspeed.page.document.proxy.NodeSetImpl;
 import org.apache.jetspeed.portalsite.Menu;
 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
 import org.apache.jetspeed.portalsite.PortalSiteSessionContext;
@@ -58,11 +61,41 @@
     private Page requestPage;
 
     /**
+     * siblingPages - cached node set of visible sibling page proxies
+     */
+    private NodeSet siblingPages;
+
+    /**
+     * siblingPagesCached - cached flag for sibling page proxies
+     */
+    private boolean siblingPagesCached;
+
+    /**
+     * siblingFolders - cached node set of visible sibling folder proxies
+     */
+    private NodeSet siblingFolders;
+
+    /**
+     * siblingFoldersCached - cached flag for sibling folder proxies
+     */
+    private boolean siblingFoldersCached;
+
+    /**
      * rootFolder - cached request profiled root folder proxy
      */
     private Folder requestRootFolder;
 
     /**
+     * rootLinks - cached node set of visible link proxies
+     */
+    private NodeSet rootLinks;
+
+    /**
+     * rootLinksCached - cached flag for link proxies
+     */
+    private boolean rootLinksCached;
+
+    /**
      * pageMenuDefinitionNames - cached menu definition names for request page
      */
     private Set pageMenuDefinitionNames;
@@ -166,22 +199,28 @@
      */
     public NodeSet getSiblingPages() throws NodeNotFoundException
     {
-        // return pages from parent folder of request page
-        Folder folder = getFolder();
-        if (folder != null)
+        // cache filtered return value
+        if (!siblingPagesCached)
         {
-            try
+            // return pages from parent folder of request page
+            Folder folder = getFolder();
+            if (folder != null)
             {
-                return folder.getPages();
-            }
-            catch (NodeException ne)
-            {
-                NodeNotFoundException nnfe = new NodeNotFoundException("Sibling pages not
found.");
-                nnfe.initCause(ne);
-                throw nnfe;
+                try
+                {
+                    // access, filter hidden, and cache
+                    siblingPages = filterHiddenNodes(folder.getPages());
+                    siblingPagesCached = true;
+                }
+                catch (NodeException ne)
+                {
+                    NodeNotFoundException nnfe = new NodeNotFoundException("Sibling pages
not found.");
+                    nnfe.initCause(ne);
+                    throw nnfe;
+                }
             }
         }
-        return null;
+        return siblingPages;
     }
 
     /**
@@ -198,7 +237,12 @@
         Folder folder = getFolder();
         if (folder != null)
         {
-            return (Folder)folder.getParent();
+            // access, filter hidden, and return
+            Folder parent = (Folder)folder.getParent();
+            if ((parent != null) && !parent.isHidden())
+            {
+                return parent;
+            }
         }
         return null;
     }
@@ -214,22 +258,28 @@
      */
     public NodeSet getSiblingFolders() throws NodeNotFoundException
     {
-        // return folders from parent folder of request page
-        Folder folder = getFolder();
-        if (folder != null)
+        // cache filtered return value
+        if (!siblingFoldersCached)
         {
-            try
-            {
-                return folder.getFolders();
-            }
-            catch (NodeException ne)
+            // return folders from parent folder of request page
+            Folder folder = getFolder();
+            if (folder != null)
             {
-                NodeNotFoundException nnfe = new NodeNotFoundException("Sibling folders not
found.");
-                nnfe.initCause(ne);
-                throw nnfe;
+                try
+                {
+                    // access, filter hidden, and cache
+                    siblingFolders = filterHiddenNodes(folder.getFolders());
+                    siblingFoldersCached = true;
+                }
+                catch (NodeException ne)
+                {
+                    NodeNotFoundException nnfe = new NodeNotFoundException("Sibling folders
not found.");
+                    nnfe.initCause(ne);
+                    throw nnfe;
+                }
             }
         }
-        return null;
+        return siblingFolders;
     }
 
     /**
@@ -261,22 +311,28 @@
      */
     public NodeSet getRootLinks() throws NodeNotFoundException
     {
-        // return links from request root folder
-        Folder rootFolder = getRootFolder();
-        if (rootFolder != null)
+        // cache filtered return value
+        if (!rootLinksCached)
         {
-            try
-            {
-                return rootFolder.getLinks();
-            }
-            catch (NodeException ne)
+            // return links from request root folder
+            Folder rootFolder = getRootFolder();
+            if (rootFolder != null)
             {
-                NodeNotFoundException nnfe = new NodeNotFoundException("Root links not found.");
-                nnfe.initCause(ne);
-                throw nnfe;
+                try
+                {
+                    // access, filter hidden, and cache
+                    rootLinks = filterHiddenNodes(rootFolder.getLinks());
+                    rootLinksCached = true;
+                }
+                catch (NodeException ne)
+                {
+                    NodeNotFoundException nnfe = new NodeNotFoundException("Root links not
found.");
+                    nnfe.initCause(ne);
+                    throw nnfe;
+                }
             }
         }
-        return null;
+        return rootLinks;
     }
 
     /**
@@ -423,5 +479,61 @@
             }
         }
         return null;
+    }
+
+    /**
+     * filterHiddenNodes - utility to filter hidden node proxies out of node sets
+     *
+     * @param nodes proxy node set to filter
+     * @return input or filtered proxy node set
+     */
+    private static NodeSet filterHiddenNodes(NodeSet nodes)
+    {
+        if ((nodes != null) && !nodes.isEmpty())
+        {
+            // filter node proxies in node set
+            List filteredNodes = null;
+            Iterator nodesIter = nodes.iterator();
+            while (nodesIter.hasNext())
+            {
+                // test hidden status of individual node proxies
+                Node node = (Node)nodesIter.next();
+                if (node.isHidden())
+                {
+                    // if not copying, create new node set
+                    // and copy preceding node proxies
+                    if (filteredNodes == null)
+                    {
+                        filteredNodes = new ArrayList(nodes.size());
+                        Iterator copyIter = nodes.iterator();
+                        while (copyIter.hasNext())
+                        {
+                            Node copyNode = (Node)copyIter.next();
+                            if (copyNode != node)
+                            {
+                                filteredNodes.add(copyNode);
+                            }
+                            else
+                            {
+                                break;
+                            }
+                        }
+                    }
+                }
+                else if (filteredNodes != null)
+                {
+                    // if copying, copy node proxy to filtered set
+                    filteredNodes.add(node);
+                }
+            }
+
+            // return filteredNodes node proxies if generated
+            // in new immutable proxy node set
+            if (filteredNodes != null)
+            {
+                return new NodeSetImpl(filteredNodes);
+            }
+        }
+        return nodes;
     }
 }



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