[gatein-commits] gatein SVN: r1977 - in portal/trunk: portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 4 11:51:13 EST 2010


Author: hoang_to
Date: 2010-03-04 11:51:12 -0500 (Thu, 04 Mar 2010)
New Revision: 1977

Modified:
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java
   portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java
   portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java
Log:
GTNPORTAL-779: An enhancement in navigation node management

Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java	2010-03-04 16:22:10 UTC (rev 1976)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/model/PageNode.java	2010-03-04 16:51:12 UTC (rev 1977)
@@ -252,6 +252,11 @@
    {
       this.visibility = visibility;
    }
+   
+   public Visibility getVisibility()
+   {
+      return this.visibility;
+   }
 
    private boolean isInPublicationDate()
    {

Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java	2010-03-04 16:22:10 UTC (rev 1976)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java	2010-03-04 16:51:12 UTC (rev 1977)
@@ -29,6 +29,7 @@
 import org.exoplatform.portal.config.UserPortalConfigService;
 import org.exoplatform.portal.config.model.PageNavigation;
 import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.webui.navigation.PageNavigationUtils;
 import org.exoplatform.portal.webui.navigation.UINavigationManagement;
 import org.exoplatform.portal.webui.navigation.UINavigationNodeSelector;
 import org.exoplatform.portal.webui.page.UIPageNodeForm2;
@@ -338,6 +339,8 @@
          naviManager.setOwnerType(PortalConfig.PORTAL_TYPE);
 
          PageNavigation navi = dataService.getPageNavigation(PortalConfig.PORTAL_TYPE, portalName);
+         //Filter the navigation
+         navi = PageNavigationUtils.filterNavigation(navi, context.getRemoteUser(), true);
          
          uicomp.setSelectedNavigation(navi);
          UINavigationNodeSelector selector = naviManager.getChild(UINavigationNodeSelector.class);

Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java	2010-03-04 16:22:10 UTC (rev 1976)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java	2010-03-04 16:51:12 UTC (rev 1977)
@@ -20,10 +20,13 @@
 package org.exoplatform.portal.webui.navigation;
 
 import org.exoplatform.container.ExoContainer;
+import org.exoplatform.portal.config.UserACL;
 import org.exoplatform.portal.config.UserPortalConfigService;
 import org.exoplatform.portal.config.model.PageNavigation;
 import org.exoplatform.portal.config.model.PageNode;
 import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.services.organization.User;
 import org.exoplatform.services.resources.ResourceBundleManager;
 import org.exoplatform.webui.application.WebuiRequestContext;
 
@@ -137,58 +140,123 @@
       return searchPageNodeByUri(nav, parentUri);
    }
 
+   // Still keep this method to have compatibility with legacy code
    public static PageNavigation filter(PageNavigation nav, String userName) throws Exception
    {
+      return filterNavigation(nav, userName, false);
+   }
+
+   /**
+    * 
+    * @param nav
+    * @param userName
+    * @param acceptNonDisplayedNode
+    * @return
+    * @throws Exception
+    */
+   public static PageNavigation filterNavigation(PageNavigation nav, String userName, boolean acceptNonDisplayedNode) throws Exception
+   {
       PageNavigation filter = nav.clone();
       filter.setNodes(new ArrayList<PageNode>());
-      //    if(nav.getNodes() == null || nav.getNodes().size() < 1) return null;
+      
+      WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+      ExoContainer container = context.getApplication().getApplicationServiceContainer();
+      UserPortalConfigService userService =
+         (UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
+      UserACL userACL = (UserACL)container.getComponentInstanceOfType(UserACL.class);
+
       for (PageNode node : nav.getNodes())
       {
-         PageNode newNode = filter(node, userName);
+         PageNode newNode = filterNodeNavigation(node, userName, acceptNonDisplayedNode, userService, userACL);
          if (newNode != null)
             filter.addNode(newNode);
       }
       return filter;
    }
 
-   public static PageNode filter(PageNode node, String userName) throws Exception
+   /**
+    * PageNode won't be processed in following cases:
+    * 
+    * Case 1: Node 's visibility is SYSTEM and the user is not superuser or he is superuser but acceptNonDisplayNode = false
+    * 
+    * Case 2: Node 's visibility is not SYSTEM but the node is not display and the acceptNonDisplayedNode = false
+    * 
+    * Case 3: Node has non null pageReference but the associated Page does not exist
+    * 
+    * 
+    * @param startNode
+    * @param userName
+    * @param userService
+    * @return
+    * @throws Exception
+    */
+   private static PageNode filterNodeNavigation(PageNode startNode, String userName, boolean acceptNonDisplayedNode,
+      UserPortalConfigService userService, UserACL userACL) throws Exception
    {
-      WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
-      ExoContainer container = context.getApplication().getApplicationServiceContainer();
-      UserPortalConfigService userService =
-         (UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
-      if (!node.isDisplay()
-         || (node.getPageReference() != null && userService.getPage(node.getPageReference(), userName) == null))
+    
+      Visibility nodeVisibility = startNode.getVisibility();
+      String pageReference = startNode.getPageReference();
+
+      boolean doNothingCase_1 = nodeVisibility == Visibility.SYSTEM && (!userACL.getSuperUser().equals(userName) || !acceptNonDisplayedNode);
+      boolean doNothingCase_2 = nodeVisibility != Visibility.SYSTEM && !startNode.isDisplay() && !acceptNonDisplayedNode;
+      boolean doNothingCase_3 = (pageReference != null) && (userService.getPage(pageReference, userName) == null);
+
+      
+      
+      if (doNothingCase_1 || doNothingCase_2 || doNothingCase_3)
+      {
          return null;
-      PageNode copyNode = node.clone();
-      copyNode.setChildren(new ArrayList<PageNode>());
-      List<PageNode> children = node.getChildren();
+      }
+
+      PageNode cloneStartNode = startNode.clone();
+      ArrayList<PageNode> filteredChildren = new ArrayList<PageNode>();
+
+      List<PageNode> children = startNode.getChildren();
+
       if (children != null)
       {
          for (PageNode child : children)
          {
-            PageNode newNode = filter(child, userName);
-            if (newNode != null)
-               copyNode.getChildren().add(newNode);
+            PageNode filteredChildNode = filterNodeNavigation(child, userName, acceptNonDisplayedNode, userService, userACL);
+            if (filteredChildNode != null)
+            {
+               filteredChildren.add(filteredChildNode);
+            }
          }
       }
-      if ((copyNode.getChildren() == null || copyNode.getChildren().size() == 0)
-         && (copyNode.getPageReference() == null))
+
+      //If the node has no child and it does not point to any Page, then null is return
+      if (filteredChildren.size() == 0 && cloneStartNode.getPageReference() == null)
+      {
          return null;
-      return copyNode;
+      }
+      cloneStartNode.setChildren(filteredChildren);
+      return cloneStartNode;
    }
-   
-   public static void localizePageNavigation(PageNavigation nav,Locale locale, ResourceBundleManager i18nManager)
+
+   public static PageNode filter(PageNode node, String userName, boolean acceptNonDisplayedNode) throws Exception
    {
+      WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+      ExoContainer container = context.getApplication().getApplicationServiceContainer();
+      UserPortalConfigService userService =
+         (UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
+      UserACL userACL = (UserACL)container.getComponentInstanceOfType(UserACL.class);
+
+      return filterNodeNavigation(node, userName, acceptNonDisplayedNode, userService, userACL);
+   }
+
+   public static void localizePageNavigation(PageNavigation nav, Locale locale, ResourceBundleManager i18nManager)
+   {
       if (nav.getOwnerType().equals(PortalConfig.USER_TYPE))
          return;
-      ResourceBundle res = i18nManager.getNavigationResourceBundle(locale.getLanguage(), nav.getOwnerType(), nav.getOwnerId());
+      ResourceBundle res =
+         i18nManager.getNavigationResourceBundle(locale.getLanguage(), nav.getOwnerType(), nav.getOwnerId());
       for (PageNode node : nav.getNodes())
       {
          resolveLabel(res, node);
       }
    }
-   
+
    private static void resolveLabel(ResourceBundle res, PageNode node)
    {
       node.setResolvedLabel(res);
@@ -199,12 +267,12 @@
          resolveLabel(res, childNode);
       }
    }
-   
+
    public static PageNavigation findNavigationByID(List<PageNavigation> all_Navigations, int id)
    {
-      for(PageNavigation nav : all_Navigations)
+      for (PageNavigation nav : all_Navigations)
       {
-         if(nav.getId() == id)
+         if (nav.getId() == id)
          {
             return nav;
          }



More information about the gatein-commits mailing list