portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r920191 [2/5] - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/om/folder/proxy/ components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/om/page/proxy/ components/jetspeed-por...
Date Mon, 08 Mar 2010 03:54:18 GMT
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/impl/PortalSiteSessionContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/impl/PortalSiteSessionContextImpl.java?rev=920191&r1=920190&r2=920191&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/impl/PortalSiteSessionContextImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/impl/PortalSiteSessionContextImpl.java Mon Mar  8 03:54:17 2010
@@ -46,7 +46,9 @@
 import org.apache.jetspeed.portalsite.PortalSiteContentTypeMapper;
 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
 import org.apache.jetspeed.portalsite.PortalSiteSessionContext;
-import org.apache.jetspeed.portalsite.view.SiteView;
+import org.apache.jetspeed.portalsite.view.AbstractSiteView;
+import org.apache.jetspeed.portalsite.view.PhysicalSiteView;
+import org.apache.jetspeed.portalsite.view.SearchPathsSiteView;
 import org.apache.jetspeed.portalsite.view.SiteViewMenuDefinitionLocator;
 import org.apache.jetspeed.profiler.ProfileLocator;
 import org.apache.jetspeed.profiler.ProfileLocatorProperty;
@@ -113,7 +115,7 @@
     /**
      * siteView - session site view
      */
-    private transient SiteView siteView;
+    private transient AbstractSiteView siteView;
 
     /**
      * folderPageHistory - map of last page visited by folder 
@@ -211,7 +213,71 @@
     }
 
     /**
-     * selectRequestPage - select page proxy for request given profile locators
+     * newRequestContext - create a new request context instance without profiling
+     *                     support with fallback and history
+     *
+     * @param requestPath request path
+     * @param requestServerName request server name
+     * @return new request context instance
+     */
+    public PortalSiteRequestContext newRequestContext(String requestPath, String requestServerName)
+    {
+        return new PortalSiteRequestContextImpl(this, requestPath, requestServerName, true, true);
+    }
+
+    /**
+     * newRequestContext - create a new request context instance without profiling
+     *                     support with history
+     *
+     * @param requestPath request path
+     * @param requestServerName request server name
+     * @param requestFallback flag specifying whether to fallback to root folder
+     *                        if locators do not select a page or access is forbidden
+     * @return new request context instance
+     */
+    public PortalSiteRequestContext newRequestContext(String requestPath, String requestServerName, boolean requestFallback)
+    {
+        return new PortalSiteRequestContextImpl(this, requestPath, requestServerName, requestFallback, true);
+    }
+
+    /**
+     * newRequestContext - create a new request context instance without profiling
+     *                     support
+     *
+     * @param requestPath request path
+     * @param requestServerName request server name
+     * @param requestFallback flag specifying whether to fallback to root folder
+     *                        if locators do not select a page or access is forbidden
+     * @param useHistory flag indicating whether to use visited page
+     *                   history to select default page per site folder
+     * @return new request context instance
+     */
+    public PortalSiteRequestContext newRequestContext(String requestPath, String requestServerName, boolean requestFallback, boolean useHistory)
+    {
+        return new PortalSiteRequestContextImpl(this, requestPath, requestServerName, requestFallback, useHistory);
+    }
+
+    /**
+     * selectRequestPage - select page view for request given profile locators
+     *
+     * @param requestPath request path
+     * @param requestServerName request server name
+     * @param requestFallback flag specifying whether to fallback to root folder
+     *                        if locators do not select a page or access is forbidden
+     * @param useHistory flag indicating whether to use visited page
+     *                   history to select default page per site folder
+     * @param requestPageContentPath returned content path associated with selected page
+     * @return selected page view for request
+     * @throws NodeNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    public BaseConcretePageElement selectRequestPage(String requestPath, String requestServerName, boolean requestFallback, boolean useHistory, String [] requestPageContentPath) throws NodeNotFoundException
+    {
+        return selectRequestPage(null, requestPath, requestServerName, requestFallback, useHistory, false, requestPageContentPath);
+    }
+
+    /**
+     * selectRequestPage - select page view for request given profile locators
      *
      * @param requestProfileLocators map of profile locators for request
      * @param requestFallback flag specifying whether to fallback to root folder
@@ -220,35 +286,61 @@
      *                   history to select default page per site folder
      * @param forceReservedVisible force reserved/hidden folders visible for request
      * @param requestPageContentPath returned content path associated with selected page
-     * @return selected page proxy for request
+     * @return selected page view for request
      * @throws NodeNotFoundException if not found
      * @throws SecurityException if view access not granted
      */
     public BaseConcretePageElement selectRequestPage(Map requestProfileLocators, boolean requestFallback, boolean useHistory, boolean forceReservedVisible, String [] requestPageContentPath) throws NodeNotFoundException
     {
+        return selectRequestPage(requestProfileLocators, null, null, requestFallback, useHistory, forceReservedVisible, requestPageContentPath);
+    }
+    
+    /**
+     * selectRequestPage - select page view for request given profile locators
+     *
+     * @param requestProfileLocators map of profile locators for request
+     * @param requestPath request path if no locators specified
+     * @param requestServerName request server name if no locators specified
+     * @param requestFallback flag specifying whether to fallback to root folder
+     *                        if locators do not select a page or access is forbidden
+     * @param useHistory flag indicating whether to use visited page
+     *                   history to select default page per site folder
+     * @param forceReservedVisible force reserved/hidden folders visible for request
+     * @param requestPageContentPath returned content path associated with selected page
+     * @return selected page view for request
+     * @throws NodeNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    private BaseConcretePageElement selectRequestPage(Map requestProfileLocators, String requestPath, String requestServerName, boolean requestFallback, boolean useHistory, boolean forceReservedVisible, String [] requestPageContentPath) throws NodeNotFoundException
+    {
         // validate and update session profile locators if modified
         if (updateSessionProfileLocators(requestProfileLocators, forceReservedVisible))
         {
             // extract page request path and server from the locators
-            String requestPath = Folder.PATH_SEPARATOR;
-            String requestServerName = null;
-            ProfileLocator locator = (ProfileLocator)requestProfileLocators.get(ProfileLocator.PAGE_LOCATOR);
-            if (locator != null)
-            {
-                // use 'page' locator to determine request page by executing
-                // profile locator to determine path
-                requestPath = getRequestPathFromLocator(locator);
-            }
-            else
+            // if specified, otherwise use specified parameters
+            ProfileLocator locator = null;
+            if (requestProfileLocators != null)
             {
-                // 'page' locator unavailable, use first locator since
-                // all locators should have identical request paths, (do
-                // not execute profile locator though to determine path:
-                // simply use the request path)
-                locator = (ProfileLocator)requestProfileLocators.values().iterator().next();
-                requestPath = locator.getRequestPath();
+                requestPath = Folder.PATH_SEPARATOR;
+                requestServerName = null;
+                locator = (ProfileLocator)requestProfileLocators.get(ProfileLocator.PAGE_LOCATOR);
+                if (locator != null)
+                {
+                    // use 'page' locator to determine request page by executing
+                    // profile locator to determine path
+                    requestPath = getRequestPathFromLocator(locator);
+                }
+                else
+                {
+                    // 'page' locator unavailable, use first locator since
+                    // all locators should have identical request paths, (do
+                    // not execute profile locator though to determine path:
+                    // simply use the request path)
+                    locator = (ProfileLocator)requestProfileLocators.values().iterator().next();
+                    requestPath = locator.getRequestPath();
+                }
+                requestServerName = locator.getRequestServerName();
             }
-            requestServerName = locator.getRequestServerName();
             if (log.isDebugEnabled())
             {
                 log.debug("Select request page: requestPath="+requestPath+", requestServerName: "+requestServerName);
@@ -266,12 +358,12 @@
                 {
                     // test for exact system match if content fallback enabled;
                     // clear system type if not found
-                    SiteView view = getSiteView();
+                    AbstractSiteView view = getSiteView();
                     if (view != null)
                     {
                         try
                         {
-                            view.getNodeProxy(requestPath, null, false, false);
+                            view.getNodeView(requestPath, null, false, false);
                         }
                         catch (NodeNotFoundException nnfe)
                         {
@@ -319,12 +411,12 @@
                         if (systemPageRequestPath != null)
                         {
                             // verify system page existence
-                            SiteView view = getSiteView();
+                            AbstractSiteView view = getSiteView();
                             if (view != null)
                             {
                                 try
                                 {
-                                    if (view.getNodeProxy(systemPageRequestPath, null, false, false) instanceof Page)
+                                    if (view.getNodeView(systemPageRequestPath, null, false, false) instanceof Page)
                                     {
                                         systemType = PortalSiteContentTypeMapper.PAGE_SYSTEM_TYPE;
                                     }
@@ -563,14 +655,14 @@
     }
 
     /**
-     * selectRequestPage - select page proxy for request for specified
+     * selectRequestPage - select page view for request for specified
      *                     path given profile locators and site view
      *                     associated with this context
      *
      * @param requestPath request path
      * @param useHistory flag indicating whether to use visited page
      *                   history to select default page per site folder
-     * @return selected page proxy for request
+     * @return selected page view for request
      * @throws NodeNotFoundException if not found
      * @throws SecurityException if view access not granted
      */
@@ -580,7 +672,7 @@
         SecurityException accessException = null;
 
         // valid SiteView required from session profile locators
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         if (view != null)
         {
             // default request to root folder if not specified
@@ -602,7 +694,7 @@
             try
             {
                 // try page or folder request url
-                requestNode = view.getNodeProxy(requestPath, null, false, false);
+                requestNode = view.getNodeView(requestPath, null, false, false);
             }
             catch (NodeNotFoundException nnfe)
             {
@@ -612,7 +704,7 @@
                 {
                     // retry folder request url
                     requestPath = requestPath.substring(0, requestPath.length() - Folder.FALLBACK_DEFAULT_PAGE.length());
-                    requestNode = view.getNodeProxy(requestPath, null, true, false);
+                    requestNode = view.getNodeView(requestPath, null, true, false);
                 }
                 else
                 {
@@ -737,7 +829,7 @@
                         }
                     }
                     
-                    // get default page for folder proxy if more than one
+                    // get default page for folder view if more than one
                     // page is available to choose from
                     if (requestFolderPages.size() > 1)
                     {
@@ -778,7 +870,7 @@
                     }
                     
                     // default page not available, select first page
-                    // proxy in request folder; save last visited
+                    // view in request folder; save last visited
                     // non-hidden page for folder path and return default page
                     requestPage = (Page)requestFolderPages.iterator().next();
                     if (!requestPage.isHidden())
@@ -824,14 +916,14 @@
     }
     
     /**
-     * selectContentRequestPage - select dynamic page proxy for request for
+     * selectContentRequestPage - select dynamic page view for request for
      *                            specified content request path and content
      *                            type given profile locators and site view
      *                            associated with this context
      *
      * @param requestPath request path
      * @param contentType content type
-     * @return selected dynamic page proxy for request
+     * @return selected dynamic page view for request
      * @throws NodeNotFoundException if not found
      * @throws SecurityException if view access not granted
      */
@@ -841,7 +933,7 @@
         SecurityException accessException = null;
 
         // valid SiteView required from session profile locators
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         if (view != null)
         {
             // default request to root folder if not specified
@@ -858,7 +950,7 @@
             
             // search for deepest matching content request path
             // that matches request path; start with root folder in view
-            Folder contentRequestFolder = (Folder)view.getNodeProxy(Folder.PATH_SEPARATOR, null, false, false);
+            Folder contentRequestFolder = (Folder)view.getNodeView(Folder.PATH_SEPARATOR, null, false, false);
             String contentRequestPath = contentRequestFolder.getPath();
             String contentRequestFile = null;
             for (;;)
@@ -948,11 +1040,23 @@
     }
 
     /**
-     * getRequestRootFolder - select root folder proxy for given profile locators
+     * getRequestRootFolder - select root folder view for given profile locators
+     *
+     * @return root folder view for request
+     * @throws NodeNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    public Folder getRequestRootFolder() throws NodeNotFoundException
+    {
+        return getRequestRootFolder(null, false);
+    }
+
+    /**
+     * getRequestRootFolder - select root folder view for given profile locators
      *
      * @param requestProfileLocators map of profile locators for request
      * @param requestForceReservedVisible force reserved/hidden folders visible for request
-     * @return root folder proxy for request
+     * @return root folder view for request
      * @throws NodeNotFoundException if not found
      * @throws SecurityException if view access not granted
      */
@@ -962,11 +1066,11 @@
         if (updateSessionProfileLocators(requestProfileLocators, requestForceReservedVisible))
         {
             // valid site view required from session profile locators
-            SiteView view = getSiteView();
+            AbstractSiteView view = getSiteView();
             if (view != null)
             {
-                // return root folder proxy from session site view
-                return view.getRootFolderProxy();
+                // return root folder view from session site view
+                return view.getRootFolderView();
             }
         }
 
@@ -984,8 +1088,8 @@
      */
     private boolean updateSessionProfileLocators(Map requestProfileLocators, boolean requestForceReservedVisible)
     {
-        // request profile locators are required
-        if ((requestProfileLocators != null) && !requestProfileLocators.isEmpty())
+        // valid request profile locators are required
+        if ((requestProfileLocators == null) || !requestProfileLocators.isEmpty())
         {
             // get current user principal; ignore derivative
             // changes in role and group principals
@@ -1022,8 +1126,7 @@
             {
                 userUpdate = (((userPrincipal == null) && (currentUserPrincipal != null)) ||
                               ((userPrincipal != null) && !userPrincipal.equals(currentUserPrincipal)));
-                locatorsUpdate = ((profileLocators == null) ||
-                                  !locatorsEquals(profileLocators, requestProfileLocators));
+                locatorsUpdate = !locatorsEquals(profileLocators, requestProfileLocators);
                 forceReservedVisibleUpdate = (forceReservedVisible != requestForceReservedVisible);
                 if (stale || userUpdate || locatorsUpdate || forceReservedVisibleUpdate)
                 {
@@ -1147,18 +1250,20 @@
      *
      * @return site view instance
      */
-    public SiteView getSiteView()
+    public AbstractSiteView getSiteView()
     {
         // get or create site view
-        SiteView view = siteView;
-        if (view == null)
+        AbstractSiteView view = siteView;
+        while (view == null)
         {
             // access site view and test for creation
+            Map createViewProfileLocators = null;
             boolean createView = false;
             synchronized (this)
             {
                 view = siteView;
-                createView = ((view == null) && (pageManager != null) && (profileLocators != null));
+                createView = ((view == null) && (pageManager != null));
+                createViewProfileLocators = profileLocators;
             }
 
             // create new site view if necessary
@@ -1171,13 +1276,20 @@
                 // may arrive during construction of the site view which
                 // might then result in synchronized deadlock with page
                 // manager or page manager cache internals
-                view = new SiteView(pageManager, profileLocators, forceReservedVisible);
+                if (createViewProfileLocators != null)
+                {
+                    view = new SearchPathsSiteView(pageManager, createViewProfileLocators, forceReservedVisible);
+                }
+                else
+                {
+                    view = new PhysicalSiteView(pageManager);                    
+                }
 
                 // update site view if not already made available by another
                 // request thread
                 synchronized (this)
                 {
-                    if ((siteView == null) && (pageManager != null) && (profileLocators != null))
+                    if ((siteView == null) && (pageManager != null) && (profileLocators == createViewProfileLocators))
                     {
                         siteView = view;
                         viewCreated = true;
@@ -1189,7 +1301,14 @@
             // log site view creation
             if (viewCreated && log.isDebugEnabled())
             {
-                log.debug("Created site view: search paths=" + view.getSearchPathsString());
+                if (view instanceof SearchPathsSiteView)
+                {
+                    log.debug("Created search path site view: search paths=" + ((SearchPathsSiteView)view).getSearchPathsString());
+                }
+                else if (view instanceof PhysicalSiteView)
+                {
+                    log.debug("Created physical site view");
+                }
             }
         }
         
@@ -1245,50 +1364,50 @@
     public Set getStandardMenuNames()
     {
         // return standard menu names defined for site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         return ((view != null) ? view.getStandardMenuNames() : null);            
     }
 
     /**
-     * getMenuDefinitionLocators - get list of node proxy menu definition
+     * getMenuDefinitionLocators - get list of node view menu definition
      *                             locators from site view
      *
-     * @param node site view node proxy
+     * @param node site view node view
      * @return definition locator list
      */
     public List getMenuDefinitionLocators(Node node)
     {
         // return menu definition locators for node in site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         return ((view != null) ? view.getMenuDefinitionLocators(node) : null);            
     }
 
     /**
-     * getMenuDefinitionLocator - get named node proxy menu definition
+     * getMenuDefinitionLocator - get named node view menu definition
      *                            locator from site view
      *
-     * @param node site view node proxy
+     * @param node site view node view
      * @param name menu definition name
      * @return menu definition locator
      */
     public SiteViewMenuDefinitionLocator getMenuDefinitionLocator(Node node, String name)
     {
         // return named menu definition locator for node in site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         return ((view != null) ? view.getMenuDefinitionLocator(node, name) : null);            
     }
 
     /**
      * getManagedConcretePage - get concrete page or dynamic page instance
-     *                          from page proxy
+     *                          from page view
      *  
-     * @param page page proxy
+     * @param page page view
      * @return managed page
      */
     public BaseConcretePageElement getManagedPage(BaseConcretePageElement page)
     {
         // return managed page or dynamic page in site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         if (page instanceof Page)
         {
             return ((view != null) ? view.getManagedPage((Page)page) : null);
@@ -1302,43 +1421,43 @@
 
     /**
      * getManagedPageTemplate - get concrete page template instance from page
-     *                          template proxy
+     *                          template view
      *  
-     * @param pageTemplate page template proxy
+     * @param pageTemplate page template view
      * @return managed page template
      */
     public PageTemplate getManagedPageTemplate(PageTemplate pageTemplate)
     {
         // return managed page template in site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         return ((view != null) ? view.getManagedPageTemplate(pageTemplate) : null);            
     }
 
     /**
      * getManagedDynamicPage - get concrete dynamic page instance from dynamic
-     *                         page proxy
+     *                         page view
      *  
-     * @param dynamicPage dynamic page proxy
+     * @param dynamicPage dynamic page view
      * @return managed dynamic page
      */
     public DynamicPage getManagedDynamicPage(DynamicPage dynamicPage)
     {
         // return managed dynamic page in site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         return ((view != null) ? view.getManagedDynamicPage(dynamicPage) : null);            
     }
 
     /**
      * getManagedFragmentDefinition - get concrete dynamic page instance from
-     *                                fragment definition proxy
+     *                                fragment definition view
      *  
-     * @param fragmentDefinition fragment definition proxy
+     * @param fragmentDefinition fragment definition view
      * @return managed fragment definition
      */
     public FragmentDefinition getManagedFragmentDefinition(FragmentDefinition fragmentDefinition)
     {
         // return managed fragment definition in site view
-        SiteView view = getSiteView();
+        AbstractSiteView view = getSiteView();
         return ((view != null) ? view.getManagedFragmentDefinition(fragmentDefinition) : null);            
     }
 
@@ -1374,11 +1493,15 @@
      */
     private static boolean locatorsEquals(Map locators0, Map locators1)
     {
-        // trivial comparison
+        // trivial comparisons
         if (locators0 == locators1)
         {
             return true;
         }
+        if ((locators0 == null) || (locators1 == null))
+        {
+            return false;
+        }
 
         // compare locator map sizes
         if (locators0.size() != locators1.size())
@@ -1439,13 +1562,12 @@
      *
      * @param locator request profile locator
      * @return request path
-     
+     */     
     private static String locatorRequestPath(ProfileLocator locator)
     {
         // use request path in locator as default
         return locatorRequestPath(locator, locator.getRequestPath());
     }
-    */
 
     /**
      * locatorRequestPath - extract request specific path from profile locator
@@ -1453,7 +1575,7 @@
      * @param locator request profile locator
      * @param requestPath request path
      * @return request path
-     
+     */
     private static String locatorRequestPath(ProfileLocator locator, String requestPath)
     {
         // search locator using the most specific,
@@ -1508,7 +1630,6 @@
         }
         return requestPath;
     }
-    */
 
     /* (non-Javadoc)
      * @see org.apache.jetspeed.page.PageManagerEventListener#newNode(org.apache.jetspeed.page.document.Node)

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBackMenuDefinition.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBackMenuDefinition.java?rev=920191&r1=920190&r2=920191&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBackMenuDefinition.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBackMenuDefinition.java Mon Mar  8 03:54:17 2010
@@ -22,7 +22,7 @@
 
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.impl.StandardMenuDefinitionImpl;
-import org.apache.jetspeed.portalsite.view.SiteView;
+import org.apache.jetspeed.portalsite.view.AbstractSiteView;
 
 /**
  * This class provides a menu definition for the standard
@@ -48,7 +48,7 @@
      */
     public String getName()
     {
-        return SiteView.STANDARD_BACK_MENU_NAME;
+        return AbstractSiteView.STANDARD_BACK_MENU_NAME;
     }
 
     /**

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBreadcrumbsMenuDefinition.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBreadcrumbsMenuDefinition.java?rev=920191&r1=920190&r2=920191&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBreadcrumbsMenuDefinition.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardBreadcrumbsMenuDefinition.java Mon Mar  8 03:54:17 2010
@@ -16,7 +16,7 @@
  */
 package org.apache.jetspeed.portalsite.menu;
 
-import org.apache.jetspeed.portalsite.view.SiteView;
+import org.apache.jetspeed.portalsite.view.AbstractSiteView;
 
 /**
  * This class provides a menu definition for the standard
@@ -42,7 +42,7 @@
      */
     public String getName()
     {
-        return SiteView.STANDARD_BREADCRUMBS_MENU_NAME;
+        return AbstractSiteView.STANDARD_BREADCRUMBS_MENU_NAME;
     }
 
     /**
@@ -53,7 +53,7 @@
     public String getOptions()
     {
         // current page
-        return SiteView.CURRENT_PAGE_PATH;
+        return AbstractSiteView.CURRENT_PAGE_PATH;
     }
 
     /**

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardNavigationsMenuDefinition.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardNavigationsMenuDefinition.java?rev=920191&r1=920190&r2=920191&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardNavigationsMenuDefinition.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardNavigationsMenuDefinition.java Mon Mar  8 03:54:17 2010
@@ -28,7 +28,7 @@
 import org.apache.jetspeed.om.folder.impl.StandardMenuOptionsDefinitionImpl;
 import org.apache.jetspeed.om.folder.impl.StandardMenuSeparatorDefinitionImpl;
 import org.apache.jetspeed.om.page.Link;
-import org.apache.jetspeed.portalsite.view.SiteView;
+import org.apache.jetspeed.portalsite.view.AbstractSiteView;
 
 /**
  * This class provides a menu definition for the standard
@@ -60,7 +60,7 @@
      */
     public String getName()
     {
-        return SiteView.STANDARD_NAVIGATIONS_MENU_NAME;
+        return AbstractSiteView.STANDARD_NAVIGATIONS_MENU_NAME;
     }
 
     /**
@@ -132,7 +132,7 @@
                      */
                     public String getName()
                     {
-                        return SiteView.CUSTOM_PAGE_NAVIGATIONS_MENU_NAME;
+                        return AbstractSiteView.CUSTOM_PAGE_NAVIGATIONS_MENU_NAME;
                     }
                 });
             menuElements.add(new StandardMenuSeparatorDefinitionImpl()

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardPagesMenuDefinition.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardPagesMenuDefinition.java?rev=920191&r1=920190&r2=920191&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardPagesMenuDefinition.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/menu/StandardPagesMenuDefinition.java Mon Mar  8 03:54:17 2010
@@ -18,7 +18,7 @@
 
 import org.apache.jetspeed.om.folder.impl.StandardMenuDefinitionImpl;
 import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.portalsite.view.SiteView;
+import org.apache.jetspeed.portalsite.view.AbstractSiteView;
 
 /**
  * This class provides a menu definition for the standard
@@ -44,7 +44,7 @@
      */
     public String getName()
     {
-        return SiteView.STANDARD_PAGES_MENU_NAME;
+        return AbstractSiteView.STANDARD_PAGES_MENU_NAME;
     }
 
     /**

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/AbstractSiteView.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/AbstractSiteView.java?rev=920191&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/AbstractSiteView.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/AbstractSiteView.java Mon Mar  8 03:54:17 2010
@@ -0,0 +1,840 @@
+/*
+ * 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.portalsite.view;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.folder.FolderNotFoundException;
+import org.apache.jetspeed.om.page.DynamicPage;
+import org.apache.jetspeed.om.page.FragmentDefinition;
+import org.apache.jetspeed.om.page.Link;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.om.page.PageTemplate;
+import org.apache.jetspeed.page.PageManager;
+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.portalsite.menu.StandardBackMenuDefinition;
+import org.apache.jetspeed.portalsite.menu.StandardBreadcrumbsMenuDefinition;
+import org.apache.jetspeed.portalsite.menu.StandardNavigationsMenuDefinition;
+import org.apache.jetspeed.portalsite.menu.StandardPagesMenuDefinition;
+
+/**
+ * This abstract class defines the base implementation for
+ * views of site content.
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public abstract class AbstractSiteView
+{
+    /**
+     * CURRENT_PAGE_PATH - expression used to match the current page
+     */
+    public final static String CURRENT_PAGE_PATH = "~";
+
+    /**
+     * ALT_CURRENT_PAGE_PATH - alternate expression used to match the current page
+     */
+    public final static String ALT_CURRENT_PAGE_PATH = "@";
+    public final static char ALT_CURRENT_PAGE_PATH_CHAR = '@';
+    public final static String ALT_CURRENT_PAGE_PATH_0 = "@0";
+
+    /**
+     * STANDARD_*_MENU_NAME - standard menu names
+     */
+    public final static String STANDARD_BACK_MENU_NAME = "back";
+    public final static String STANDARD_BREADCRUMBS_MENU_NAME = "breadcrumbs";
+    public final static String STANDARD_PAGES_MENU_NAME = "pages";
+    public final static String STANDARD_NAVIGATIONS_MENU_NAME = "navigations";
+
+    /**
+     * CUSTOM_*_MENU_NAME - custom menu names
+     */
+    public final static String CUSTOM_PAGE_NAVIGATIONS_MENU_NAME = "page-navigations";
+
+    /**
+     * STANDARD_MENU_NAMES - set of supported standard menu names
+     */
+    private final static Set STANDARD_MENU_NAMES = new HashSet(3);
+    static
+    {
+        STANDARD_MENU_NAMES.add(STANDARD_BACK_MENU_NAME);
+        STANDARD_MENU_NAMES.add(STANDARD_BREADCRUMBS_MENU_NAME);
+        STANDARD_MENU_NAMES.add(STANDARD_PAGES_MENU_NAME);
+        STANDARD_MENU_NAMES.add(STANDARD_NAVIGATIONS_MENU_NAME);
+    }
+
+    /**
+     * STANDARD_MENU_DEFINITION_LOCATORS - list of standard menu definition locators
+     */
+    private final static List STANDARD_MENU_DEFINITION_LOCATORS = new ArrayList(4);
+    static
+    {
+        STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardBackMenuDefinition()));
+        STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardBreadcrumbsMenuDefinition()));
+        STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardPagesMenuDefinition()));
+        STANDARD_MENU_DEFINITION_LOCATORS.add(new SiteViewMenuDefinitionLocator(new StandardNavigationsMenuDefinition()));
+    }
+
+    /**
+     * pageManager - PageManager component
+     */
+    private PageManager pageManager;
+
+    /**
+     * rootFolderView - root folder view instance
+     */
+    private Folder rootFolderView;
+
+    /**
+     * AbstractSiteView - constructor
+     *
+     * @param pageManager PageManager component instance
+     */
+    public AbstractSiteView(PageManager pageManager)
+    {
+        this.pageManager = pageManager;
+    }
+
+    /**
+     * getPageManager - return PageManager component instance
+     *
+     * @return PageManager instance
+     */
+    public PageManager getPageManager()
+    {
+        return pageManager;
+    }
+
+    /**
+     * getRootFolderView - access root folder view instance
+     *
+     * @return root folder view
+     * @throws FolderNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    public Folder getRootFolderView() throws FolderNotFoundException
+    {
+        // latently construct and return root folder view
+        if (rootFolderView == null)
+        {
+            rootFolderView = createRootFolderView();
+        }
+        return rootFolderView;
+    }
+
+    /**
+     * createRootFolderView - create and return root folder view instance
+     *
+     * @return root folder view
+     * @throws FolderNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    protected abstract Folder createRootFolderView() throws FolderNotFoundException;
+
+    /**
+     * getNodeView - get single folder, page, or link view
+     *               at relative or absolute path
+     *
+     * @param path single node path
+     * @param currentNode current folder or page for relative paths or null
+     * @param onlyViewable node required to be viewable
+     * @param onlyVisible node required to be visible, (or current)
+     * @return folder, page, or link node view
+     * @throws NodeNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    public Node getNodeView(String path, Node currentNode, boolean onlyViewable, boolean onlyVisible) throws NodeNotFoundException
+    {
+        // determine current folder and page
+        String currentPath = path;
+        Folder currentFolder = null;
+        Page currentPage = null;
+        if (currentNode instanceof Page)
+        {
+            currentPage = (Page)currentNode;
+            currentFolder = (Folder)currentPage.getParent();
+        }
+        else if (currentNode instanceof Folder)
+        {
+            currentFolder = (Folder)currentNode;
+        }
+
+        // match current page path
+        if (currentPath.equals(CURRENT_PAGE_PATH) || currentPath.equals(ALT_CURRENT_PAGE_PATH))
+        {
+            // return current page if specified, (assume viewable)
+            return currentPage;
+        }
+
+        // match current node path
+        if (currentPath.equals(ALT_CURRENT_PAGE_PATH_0))
+        {
+            // return current node, (assume viewable)
+            return currentNode;
+        }
+
+        // convert absolute path to a root relative search
+        // and default current folder
+        if (currentPath.startsWith(Folder.PATH_SEPARATOR))
+        {
+            currentPath = currentPath.substring(1);
+            currentFolder = null;
+        }
+        if (currentFolder == null)
+        {
+            currentFolder = getRootFolderView();
+        }
+
+        // search for path based on current folder 
+        while ((currentPath.length() > 0) && !currentPath.equals(Folder.PATH_SEPARATOR))
+        {
+            // parse relative sub-folder from path
+            int separatorIndex = currentPath.indexOf(Folder.PATH_SEPARATOR);
+            if (separatorIndex != -1)
+            {
+                // isolate sub-folder and continue search
+                // using remaining paths
+                String subfolder = currentPath.substring(0, separatorIndex);
+                currentPath = currentPath.substring(separatorIndex+1);
+                if (subfolder.equals(".."))
+                {
+                    // adjust current folder if parent exists
+                    if (currentFolder.getParent() != null)
+                    {
+                        currentFolder = (Folder)currentFolder.getParent();
+                    }
+                    else
+                    {
+                        throw new NodeNotFoundException("Specified path " + path + " not found.");
+                    }
+                }
+                else if (!subfolder.equals("."))
+                {
+                    // access sub-folder or return null if nonexistent
+                    // or access forbidden
+                    try
+                    {
+                        currentFolder = currentFolder.getFolder(subfolder);
+                    }
+                    catch (NodeException ne)
+                    {
+                        NodeNotFoundException nnfe = new NodeNotFoundException("Specified path " + path + " not found.");
+                        nnfe.initCause(ne);
+                        throw nnfe;
+                    }
+                    catch (NodeNotFoundException nnfe)
+                    {
+                        // check security access to folder not found in site view
+                        checkAccessToNodeNotFound(currentFolder, subfolder);
+                        // folder not found in site view
+                        NodeNotFoundException nnfeWrapper = new NodeNotFoundException("Specified path " + path + " not found.");
+                        nnfeWrapper.initCause(nnfe);
+                        throw nnfeWrapper;
+                    }
+                }
+            }
+            else
+            {
+                // access remaining path as page, folder, or link node
+                // view; return null if not found or not viewable/visible
+                // and visibility is required
+                try
+                {
+                    NodeSet children = currentFolder.getAll();
+                    if (children != null)
+                    {
+                        Node node = children.get(currentPath);
+                        if (((node instanceof Folder) || (node instanceof Page) || (node instanceof Link)) &&
+                            (!onlyVisible || !node.isHidden() || (node == currentPage)) &&
+                            (!onlyViewable || isViewable(node, onlyVisible)))
+                        {
+                            return node;
+                        }
+                    }
+                }
+                catch (NodeException ne)
+                {
+                    NodeNotFoundException nnfe = new NodeNotFoundException("Specified path " + path + " not found.");
+                    nnfe.initCause(ne);
+                    throw nnfe;
+                }
+                // check security access to folder node not found in site view
+                checkAccessToNodeNotFound(currentFolder, currentPath);
+                // folder node not found in site view
+                throw new NodeNotFoundException("Specified path " + path + " not found or viewable/visible.");
+            }
+        }
+
+        // path maps to current folder; return if viewable/visible
+        // or visibility not required
+        if ((!onlyVisible || !currentFolder.isHidden()) &&
+            (!onlyViewable || isViewable(currentFolder, onlyVisible)))
+        {
+            return currentFolder;
+        }
+        throw new NodeNotFoundException("Specified path " + path + " not found or viewable/visible.");
+    }
+    
+    /**
+     * checkAccessToFolderNotFound - checks security access to child folder
+     *                               nodes not found in site view when accessed
+     *                               directly
+     *
+     * @param folder parent view folder
+     * @param folderName name of child folder in view to check
+     * @throws SecurityException if view access to folder not granted
+     */
+    protected abstract void checkAccessToNodeNotFound(Folder folder, String folderName);
+
+    /**
+     * getNodeViews - get folder, page, or link views at
+     *                relative or absolute path using simple path
+     *                wildcards and character classes
+     *
+     * @param regexpPath regular expression node path
+     * @param currentNode current folder or page for relative paths or null
+     * @param onlyViewable nodes required to be viewable flag
+     * @param onlyVisible node required to be visible, (or current)
+     * @return list of folder, page, or link node views
+     */
+    public List getNodeViews(String regexpPath, Node currentNode, boolean onlyViewable, boolean onlyVisible)
+    {
+        // determine current folder and page
+        String currentRegexpPath = regexpPath;
+        Folder currentFolder = null;
+        Page currentPage = null;
+        if (currentNode instanceof Page)
+        {
+            currentPage = (Page)currentNode;
+            currentFolder = (Folder)currentPage.getParent();
+        }
+        else if (currentNode instanceof Folder)
+        {
+            currentFolder = (Folder)currentNode;
+        }
+
+        // match current page path
+        if (currentRegexpPath.equals(CURRENT_PAGE_PATH) || currentRegexpPath.equals(ALT_CURRENT_PAGE_PATH))
+        {
+            if (currentPage != null)
+            {
+                // return current page, (assume viewable)
+                List views = new ArrayList(1);
+                views.add(currentPage);
+                return views;
+            }
+            else
+            {
+                // current page not specified
+                return null;
+            }
+        }
+        
+        // convert pattern with indexed current node path expressions
+        if (currentNode != null)
+        {
+            // match current node path
+            if (currentRegexpPath.equals(ALT_CURRENT_PAGE_PATH_0))
+            {
+                // return current node, (assume viewable)
+                List views = new ArrayList(1);
+                views.add(currentNode);
+                return views;
+            }
+
+            // match current node path expression
+            int currentNodePathIndex = currentRegexpPath.indexOf(ALT_CURRENT_PAGE_PATH_CHAR);
+            String [] currentNodePathElements = null;
+            while (currentNodePathIndex != -1)
+            {
+                if (currentNodePathIndex+1 < currentRegexpPath.length())
+                {
+                    String currentNodePathElement = null;
+                    char currentNodePathElementIndexChar = currentRegexpPath.charAt(currentNodePathIndex+1);
+                    if ((currentNodePathElementIndexChar >= '0') && (currentNodePathElementIndexChar <= '9'))
+                    {
+                        // valid current node path pattern
+                        int currentNodePathElementIndex = (int)(currentNodePathElementIndexChar-'0');
+                        if (currentNodePathElementIndex > 0)
+                        {
+                            // use indexed current node path element
+                            if (currentNodePathElements == null)
+                            {
+                                // note: leading '/' in path makes index one based
+                                currentNodePathElements = currentNode.getPath().split(Folder.PATH_SEPARATOR);
+                            }
+                            if (currentNodePathElementIndex < currentNodePathElements.length)
+                            {
+                                currentNodePathElement = currentNodePathElements[currentNodePathElementIndex];
+                            }
+                        }
+                        else
+                        {
+                            // use full current node path trimmed of separators
+                            currentNodePathElement = currentNode.getPath();
+                            if (currentNodePathElement.endsWith(Folder.PATH_SEPARATOR))
+                            {
+                                currentNodePathElement = currentNodePathElement.substring(0, currentNodePathElement.length()-1);
+                            }
+                            if (currentNodePathElement.startsWith(Folder.PATH_SEPARATOR))
+                            {
+                                currentNodePathElement = currentNodePathElement.substring(1);
+                            }
+                        }
+                    }
+                    else if (currentNodePathElementIndexChar == '$')
+                    {
+                        // use last current node path element
+                        if (currentNodePathElements == null)
+                        {
+                            // note: leading '/' in path makes index one based
+                            currentNodePathElements = currentNode.getPath().split(Folder.PATH_SEPARATOR);
+                        }
+                        currentNodePathElement = currentNodePathElements[currentNodePathElements.length-1];
+                    }
+                    // replace current node path expression
+                    if (currentNodePathElement != null)
+                    {
+                        currentRegexpPath = currentRegexpPath.substring(0, currentNodePathIndex)+currentNodePathElement+currentRegexpPath.substring(currentNodePathIndex+2);
+                        currentNodePathIndex += currentNodePathElement.length()-1;
+                    }
+                }
+                currentNodePathIndex = currentRegexpPath.indexOf(ALT_CURRENT_PAGE_PATH_CHAR, currentNodePathIndex+1);
+            }
+        }
+
+        // convert absolute path to a root relative search
+        // and default current folder
+        if (currentRegexpPath.startsWith(Folder.PATH_SEPARATOR))
+        {
+            currentRegexpPath = currentRegexpPath.substring(1);
+            currentFolder = null;
+        }
+        if (currentFolder == null)
+        {
+            try
+            {
+                currentFolder = getRootFolderView();
+            }
+            catch (FolderNotFoundException fnfe)
+            {
+                return null;
+            }
+            catch (SecurityException se)
+            {
+                return null;
+            }
+        }
+
+        // search for path based on current folder 
+        while ((currentRegexpPath.length() > 0) && !currentRegexpPath.equals(Folder.PATH_SEPARATOR))
+        {
+            // parse relative sub-folder from path
+            int separatorIndex = currentRegexpPath.indexOf(Folder.PATH_SEPARATOR);
+            if (separatorIndex != -1)
+            {
+                // isolate sub-folder and continue search
+                // using remaining paths
+                String subfolder = currentRegexpPath.substring(0, separatorIndex);
+                currentRegexpPath = currentRegexpPath.substring(separatorIndex+1);
+                if (subfolder.equals(".."))
+                {
+                    // adjust current folder if parent exists
+                    if (currentFolder.getParent() != null)
+                    {
+                        currentFolder = (Folder)currentFolder.getParent();
+                    }
+                    else
+                    {
+                        return null;
+                    }
+                }
+                else if (!subfolder.equals("."))
+                {
+                    try
+                    {
+                        // check for regular expression pattern
+                        String subfolderPattern = pathRegexpPattern(subfolder);
+                        if (subfolderPattern != null)
+                        {
+                            // follow all matching sub-folders
+                            NodeSet subfolders = currentFolder.getFolders();
+                            if (subfolders != null)
+                            {
+                                subfolders = subfolders.inclusiveSubset(subfolderPattern);
+                                if (subfolders != null)
+                                {
+                                    // recursively process sub-folders if more than
+                                    // one match, access single sub-folder, or return
+                                    // null if nonexistent
+                                    if (subfolders.size() > 1)
+                                    {
+                                        // recursively process matching sub-folders
+                                        List views = null;
+                                        Iterator subfoldersIter = subfolders.iterator();
+                                        while (subfoldersIter.hasNext())
+                                        {
+                                            currentFolder = (Folder)subfoldersIter.next();
+                                            List subfolderProxies = getNodeViews(currentRegexpPath, currentFolder, onlyViewable, onlyVisible);
+                                            if ((subfolderProxies != null) && !subfolderProxies.isEmpty())
+                                            {
+                                                if (views == null)
+                                                {
+                                                    views = new ArrayList();
+                                                }
+                                                views.addAll(subfolderProxies);
+                                            }
+                                        }
+                                        return views;
+                                    }
+                                    else if (subfolders.size() == 1)
+                                    {
+                                        // access single sub-folder
+                                        currentFolder = (Folder)subfolders.iterator().next();
+                                    }
+                                    else
+                                    {
+                                        // no matching sub-folders
+                                        return null;
+                                    }
+                                }
+                                else
+                                {
+                                    // no matching sub-folders
+                                    return null;
+                                }
+                            }
+                            else
+                            {
+                                // no sub-folders
+                                return null;
+                            }
+                        }
+                        else
+                        {
+                            // access single sub-folder or return null if
+                            // nonexistent by throwing exception
+                            currentFolder = currentFolder.getFolder(subfolder);
+                        }
+                    }
+                    catch (NodeException ne)
+                    {
+                        // could not access sub-folders
+                        return null;
+                    }
+                    catch (NodeNotFoundException nnfe)
+                    {
+                        // could not access sub-folders
+                        return null;
+                    }
+                    catch (SecurityException se)
+                    {
+                        // could not access sub-folders
+                        return null;
+                    }
+                }
+            }
+            else
+            {
+                try
+                {
+                    // get all children of current folder
+                    NodeSet children = currentFolder.getAll();
+                    if (children != null)
+                    {
+                        // check for regular expression pattern
+                        String pathPattern = pathRegexpPattern(currentRegexpPath);
+                        if (pathPattern != null)
+                        {
+                            // copy children matching remaining path pattern as
+                            // page, folder, or link views if viewable/visible or
+                            // visibility not required
+                            children = children.inclusiveSubset(pathPattern);
+                            if ((children != null) && !children.isEmpty())
+                            {
+                                List views = null;
+                                Iterator childrenIter = children.iterator();
+                                while (childrenIter.hasNext())
+                                {
+                                    Node child = (Node)childrenIter.next(); 
+                                    if (((child instanceof Folder) || (child instanceof Page) || (child instanceof Link)) &&
+                                        (!onlyVisible || !child.isHidden() || (child == currentPage)) &&
+                                        (!onlyViewable || isViewable(child, onlyVisible)))
+                                    {
+                                        if (views == null)
+                                        {
+                                            views = new ArrayList(children.size());
+                                        }
+                                        views.add(child);
+                                    }
+                                }
+                                return views;
+                            }
+                        }
+                        else
+                        {
+                            // access remaining path as page, folder, or link
+                            // node view; return null if not found or not
+                            // viewable and visibility is required
+                            Node child = children.get(currentRegexpPath);
+                            if (((child instanceof Folder) || (child instanceof Page) || (child instanceof Link)) &&
+                                (!onlyVisible || !child.isHidden() || (child == currentPage)) &&
+                                (!onlyViewable || isViewable(child, onlyVisible)))
+                            {
+                                List views = new ArrayList(1);
+                                views.add(currentFolder);
+                                return views;
+                            }
+                        }
+                    }
+                    
+                }
+                catch (NodeException ne)
+                {
+                }
+                catch (SecurityException se)
+                {
+                }
+
+                // no children match or available
+                return null;
+            }
+        }
+
+        // path maps to current folder; return if viewable/visible
+        // or visibility not required
+        if ((!onlyVisible || !currentFolder.isHidden()) &&
+            (!onlyViewable || isViewable(currentFolder, onlyVisible)))
+        {
+            List views = new ArrayList(1);
+            views.add(currentFolder);
+            return views;
+        }
+        return null;
+    }
+
+    /**
+     * pathRegexpPattern - tests for and converts simple path wildcard
+     *                     and character class regular expressions to
+     *                     perl5/standard java pattern syntax
+     *
+     * @param regexp - candidate path regular expression
+     * @return - converted pattern or null if no regular expression
+     */
+    private static String pathRegexpPattern(String regexp)
+    {
+        // convert expression to pattern
+        StringBuffer pattern = null;
+        for (int i = 0, limit = regexp.length(); (i < limit); i++)
+        {
+            char regexpChar = regexp.charAt(i);
+            switch (regexpChar)
+            {
+                case '*':
+                case '.':
+                case '?':
+                case '[':
+                    if (pattern == null)
+                    {
+                        pattern = new StringBuffer(regexp.length()*2);
+                        pattern.append(regexp.substring(0, i));
+                    }
+                    switch (regexpChar)
+                    {
+                        case '*':
+                            pattern.append(".*");
+                            break;
+                        case '.':
+                            pattern.append("\\.");
+                            break;
+                        case '?':
+                            pattern.append('.');
+                            break;
+                        case '[':
+                            pattern.append('[');
+                            break;
+                    }
+                    break;
+                default:
+                    if (pattern != null)
+                    {
+                        pattern.append(regexpChar);
+                    }
+                    break;
+            }
+        }
+
+        // return converted pattern or null if not a regular expression
+        if (pattern != null)
+            return pattern.toString();
+        return null;
+    }
+
+    /**
+     * isViewable - tests for node visibility in view
+     *
+     * @param node test node view
+     * @param onlyVisible nodes required to be visible
+     * @return - viewable flag
+     */
+    private static boolean isViewable(Node node, boolean onlyVisible)
+    {
+        // pages and links are always considered viewable
+        if ((node instanceof Page) || (node instanceof Link))
+        {
+            return true;
+        }
+        // folders must be tested for viewable and visible
+        // child nodes
+        if (node instanceof Folder)
+        {
+            try
+            {
+                NodeSet children = ((Folder) node).getAll();
+                if (children != null)
+                {
+                    Iterator childrenIter = children.iterator();
+                    while (childrenIter.hasNext())
+                    {
+                        Node child = (Node)childrenIter.next();
+                        if ((!onlyVisible || !child.isHidden()) && isViewable(child, onlyVisible))
+                        {
+                            return true;
+                        }
+                    }
+                }
+            }
+            catch (NodeException ne)
+            {
+            }
+            catch (SecurityException se)
+            {
+            }
+            return false;
+        }
+        // templates, fragments, and dynamic page are not visible
+        return false;
+    }
+
+    /**
+     * getStandardMenuNames - get set of available standard menu names
+     *  
+     * @return menu names set
+     */
+    public Set getStandardMenuNames()
+    {
+        // return constant standard menu names
+        return STANDARD_MENU_NAMES;
+    }
+
+    /**
+     * getStandardMenuDefinitionLocators - get list of available standard
+     *                                     menu definition locators
+     *  
+     * @return menu definition locators list
+     */
+    public List getStandardMenuDefinitionLocators()
+    {
+        // return constant standard menu definition locators
+        return STANDARD_MENU_DEFINITION_LOCATORS;
+    }
+
+    /**
+     * getMenuDefinitionLocators - get list of view node menu definition locators
+     *
+     * @param node node view
+     * @return definition locator list
+     */
+    public abstract List getMenuDefinitionLocators(Node node);
+
+    /**
+     * getMenuDefinitionLocator - get named view node menu definition locator
+     *
+     * @param node node view
+     * @param name menu definition name
+     * @return menu definition locator
+     */
+    public abstract SiteViewMenuDefinitionLocator getMenuDefinitionLocator(Node node, String name);
+
+    /**
+     * getProfileLocatorName - get profile locator name from view node
+     *
+     * @param node node view
+     * @return profile locator name or null
+     */
+    public abstract String getProfileLocatorName(Node node);
+
+    /**
+     * getManagedPage - get concrete page instance from page view
+     *  
+     * @param page page view
+     * @return managed page
+     */
+    public abstract Page getManagedPage(Page page);
+
+    /**
+     * getManagedLink - get concrete link instance from link view
+     *  
+     * @param link link view
+     * @return managed link
+     */
+    public abstract Link getManagedLink(Link link);
+
+    /**
+     * getManagedFolder - get concrete folder instance from folder view
+     *  
+     * @param folder folder view
+     * @return managed folder
+     */
+    public abstract Folder getManagedFolder(Folder folder);
+
+    /**
+     * getManagedPageTemplate - get concrete page template instance from
+     *                          page template view
+     *  
+     * @param pageTemplate page template view
+     * @return managed page template
+     */
+    public abstract PageTemplate getManagedPageTemplate(PageTemplate pageTemplate);
+
+    /**
+     * getManagedDynamicPage - get concrete dynamic page instance from
+     *                         dynamic page view
+     *  
+     * @param dynamicPage dynamic page view
+     * @return managed dynamic page
+     */
+    public abstract DynamicPage getManagedDynamicPage(DynamicPage dynamicPage);
+
+    /**
+     * getManagedFragmentDefinition - get concrete fragment definition
+     *                                instance from fragment definition
+     *                                view
+     *  
+     * @param fragmentDefinition fragment definition view
+     * @return managed dynamic page
+     */
+    public abstract FragmentDefinition getManagedFragmentDefinition(FragmentDefinition fragmentDefinition);
+}

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/PhysicalSiteView.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/PhysicalSiteView.java?rev=920191&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/PhysicalSiteView.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal-site/src/main/java/org/apache/jetspeed/portalsite/view/PhysicalSiteView.java Mon Mar  8 03:54:17 2010
@@ -0,0 +1,271 @@
+/*
+ * 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.portalsite.view;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.folder.FolderNotFoundException;
+import org.apache.jetspeed.om.page.DynamicPage;
+import org.apache.jetspeed.om.page.FragmentDefinition;
+import org.apache.jetspeed.om.page.Link;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.om.page.PageTemplate;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.page.document.Node;
+import org.apache.jetspeed.page.document.NodeException;
+import org.apache.jetspeed.page.document.NodeNotFoundException;
+
+/**
+ * This class defines a physical view of site content.
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public class PhysicalSiteView extends AbstractSiteView
+{
+    private static final List NULL_LOCATORS = new ArrayList(0);
+    
+    /**
+     * menuDefinitionLocatorsCache - cached menu definition locators
+     */
+    private ConcurrentHashMap menuDefinitionLocatorsCache = new ConcurrentHashMap();
+    
+    /**
+     * PhysicalSiteView - basic constructor
+     *
+     * @param pageManager PageManager component instance
+     */
+    public PhysicalSiteView(PageManager pageManager)
+    {
+        super(pageManager);
+    }
+
+    /**
+     * createRootFolderView - create and return root folder view instance
+     *
+     * @return root folder view
+     * @throws FolderNotFoundException if not found
+     * @throws SecurityException if view access not granted
+     */
+    protected Folder createRootFolderView() throws FolderNotFoundException
+    {
+        try
+        {
+            // get concrete root folder from page manager
+            return getPageManager().getFolder(Folder.PATH_SEPARATOR);
+        }
+        catch (NodeException ne)
+        {
+            FolderNotFoundException fnfe = new FolderNotFoundException("Root folder not found");
+            fnfe.initCause(ne);
+            throw fnfe;
+        }
+        catch (NodeNotFoundException nnfe)
+        {
+            FolderNotFoundException fnfe = new FolderNotFoundException("Root folder not found");
+            fnfe.initCause(nnfe);
+            throw fnfe;
+        }        
+    }
+
+    /**
+     * checkAccessToFolderNotFound - checks security access to child folder
+     *                               nodes not found in site view when accessed
+     *                               directly
+     *
+     * @param folder parent view folder
+     * @param folderName name of child folder in view to check
+     * @throws SecurityException if view access to folder not granted
+     */
+    protected void checkAccessToNodeNotFound(Folder folder, String folderName)
+    {
+        // additional security checks not required for physical view access
+    }
+
+    /**
+     * getMenuDefinitionLocators - get list of view node menu definition locators
+     *
+     * @param node node view
+     * @return definition locator list
+     */
+    public List getMenuDefinitionLocators(Node node)
+    {
+        // access cached menu definition locators
+        String path = node.getPath();
+        List locators = (List)menuDefinitionLocatorsCache.get(path);
+        if (locators == null)
+        {
+            if (node instanceof Folder)
+            {
+                // merge folder menu definition locators from most to least
+                // specific along inheritance folder graph by name
+                Folder folder = (Folder)node;
+                while (folder != null)
+                {
+                    // get menu definitions from inheritance folders and
+                    // merge into menu definition locators
+                    locators = SiteViewUtils.mergeMenuDefinitionLocators(folder.getMenuDefinitions(), folder, false, locators);
+                    folder = (Folder)folder.getParent();
+                }
+                // merge standard menu definition locator defaults
+                locators = SiteViewUtils.mergeMenuDefinitionLocators(getStandardMenuDefinitionLocators(), locators);        
+            }
+            else if (node instanceof Page)
+            {
+                // merge page and parent folder menu definition locators
+                // by name, (most specific page definitions are merged first
+                // since they override any folder definitions); note parent
+                // folder menu definitions include standard menu definition
+                // locator defaults
+                Page page = (Page)node;
+                locators = SiteViewUtils.mergeMenuDefinitionLocators(page.getMenuDefinitions(), page, true, locators);
+                Folder folder = (Folder)node.getParent();
+                locators = SiteViewUtils.mergeMenuDefinitionLocators(getMenuDefinitionLocators(folder), locators);
+            }
+            else if (node instanceof DynamicPage)
+            {
+                // merge page and parent folder menu definition locators
+                // by name, (most specific page definitions are merged first
+                // since they override any folder definitions); note parent
+                // folder menu definitions include standard menu definition
+                // locator defaults
+                DynamicPage dynamicPage = (DynamicPage)node;
+                locators = SiteViewUtils.mergeMenuDefinitionLocators(dynamicPage.getMenuDefinitions(), dynamicPage, true, locators);
+                Folder parentFolder = (Folder)node.getParent();
+                locators = SiteViewUtils.mergeMenuDefinitionLocators(getMenuDefinitionLocators(parentFolder), locators);
+            }
+            else if (node instanceof PageTemplate)
+            {
+                // merge only page template menu definition locators by name
+                PageTemplate pageTemplate = (PageTemplate)node;
+                locators = SiteViewUtils.mergeMenuDefinitionLocators(pageTemplate.getMenuDefinitions(), pageTemplate, false, locators);
+            }
+            locators = ((locators != null) ? locators : NULL_LOCATORS);
+            List cachedLocators = (List)menuDefinitionLocatorsCache.putIfAbsent(path, locators);
+            locators = ((cachedLocators != null) ? cachedLocators : locators);
+        }
+        return ((locators != NULL_LOCATORS) ? locators : null);
+    }
+
+    /**
+     * getMenuDefinitionLocators - get list of view node menu definition locators
+     *
+     * @param node node view
+     * @return definition locator list
+     */
+    public SiteViewMenuDefinitionLocator getMenuDefinitionLocator(Node node, String name)
+    {
+        // get menu definition locators and find by name
+        List locators = getMenuDefinitionLocators(node);
+        if (locators != null)
+        {
+            return SiteViewUtils.findMenuDefinitionLocator(locators, name);
+        }
+        return null;
+    }
+
+    /**
+     * getProfileLocatorName - get profile locator name from view node
+     *
+     * @param node node view
+     * @return profile locator name or null
+     */
+    public String getProfileLocatorName(Node node)
+    {
+        // profile locators not applicable in physical view
+        return null;
+    }
+
+    /**
+     * getManagedPage - get concrete page instance from page view
+     *  
+     * @param page page view
+     * @return managed page
+     */
+    public Page getManagedPage(Page page)
+    {
+        // physical view is directly managed
+        return page;
+    }
+
+    /**
+     * getManagedLink - get concrete link instance from link view
+     *  
+     * @param link link view
+     * @return managed link
+     */
+    public Link getManagedLink(Link link)
+    {
+        // physical view is directly managed
+        return link;
+    }
+
+    /**
+     * getManagedFolder - get concrete folder instance from folder view
+     *  
+     * @param folder folder view
+     * @return managed folder
+     */
+    public Folder getManagedFolder(Folder folder)
+    {
+        // physical view is directly managed
+        return folder;
+    }
+
+    /**
+     * getManagedPageTemplate - get concrete page template instance from
+     *                          page template view
+     *  
+     * @param pageTemplate page template view
+     * @return managed page template
+     */
+    public PageTemplate getManagedPageTemplate(PageTemplate pageTemplate)
+    {
+        // physical view is directly managed
+        return pageTemplate;
+    }
+
+    /**
+     * getManagedDynamicPage - get concrete dynamic page instance from
+     *                         dynamic page view
+     *  
+     * @param dynamicPage dynamic page view
+     * @return managed dynamic page
+     */
+    public DynamicPage getManagedDynamicPage(DynamicPage dynamicPage)
+    {
+        // physical view is directly managed
+        return dynamicPage;
+    }
+
+    /**
+     * getManagedFragmentDefinition - get concrete fragment definition
+     *                                instance from fragment definition
+     *                                view
+     *  
+     * @param fragmentDefinition fragment definition view
+     * @return managed dynamic page
+     */
+    public FragmentDefinition getManagedFragmentDefinition(FragmentDefinition fragmentDefinition)
+    {
+        // physical view is directly managed
+        return fragmentDefinition;
+    }
+}



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