[gatein-commits] gatein SVN: r2067 - portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/page.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Mar 9 21:47:16 EST 2010


Author: hoang_to
Date: 2010-03-09 21:47:11 -0500 (Tue, 09 Mar 2010)
New Revision: 2067

Modified:
   portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
Log:
GTNPORTAL-851: Auto-correct node 's wrong URI

Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java	2010-03-10 02:44:31 UTC (rev 2066)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java	2010-03-10 02:47:11 UTC (rev 2067)
@@ -123,7 +123,6 @@
             UIPortal cachedUIPortal = uiPortalApp.getCachedUIPortal(newNavType, newNavId);
             if (cachedUIPortal != null)
             {
-//               System.out.println("Found UIPortal with OWNERTYPE: " + newNavType + " OWNERID " + newNavId);
                cachedUIPortal.setSelectedNode(targetPageNode);
                cachedUIPortal.setSelectedPath(targetedPathNodes);
                uiPortalApp.setShowedUIPortal(cachedUIPortal);
@@ -180,51 +179,66 @@
          
          String[] pathNodes = targetedUri.split("/");
          
-         //We check the first navigation in the list containing all descendants corresponding to pathNodes
-         for(PageNavigation nav : allNavs)
+         return getBestMatchNavigation(allNavs, pathNodes);
+      }
+      
+      /**
+       * Get the navigation containing longest subpath of 'pathNodes'
+       * 
+       * @param listNav
+       * @param pathNodes
+       * @return
+       */
+      private PageNavigation getBestMatchNavigation(List<PageNavigation> listNav, String[] pathNodes)
+      {
+         int temporalMaximalMatching = 0;
+         PageNavigation temporalBestNavigation = listNav.get(0);
+         
+         for(PageNavigation nav : listNav)
          {
-            if(containingDescendantNodes(nav, pathNodes))
+            int currentNumberOfMatching = countNumberOfMatchedPathNodes(nav, pathNodes);
+            
+            //The whole pathNodes matches current navigation
+            if(currentNumberOfMatching == pathNodes.length)
             {
                return nav;
             }
+            
+            if(currentNumberOfMatching > temporalMaximalMatching)
+            {
+               temporalMaximalMatching = currentNumberOfMatching;
+               temporalBestNavigation = nav;
+            }
          }
-         return null;
+         return temporalBestNavigation;
       }
       
       /**
-       *  Check if a given <code>PageNavigation</code> contains all the descendants corresponding to the pathNodes
+       * Count the maximal number of nodes matching the pathNodes while descending the navigation 'nav'
        * 
-       * @param navigation
+       * @param nav
        * @param pathNodes
        * @return
        */
-      private static boolean containingDescendantNodes(PageNavigation navigation, String[] pathNodes)
+      private int countNumberOfMatchedPathNodes(PageNavigation nav, String[] pathNodes)
       {
-        PageNode firstLevelNode = navigation.getNode(pathNodes[0]);
-        if(firstLevelNode == null)
-        {
-           return false;
-        }
-        
-        //Recursive code snippet with two variables
-        PageNode tempNode = firstLevelNode;
-        PageNode currentNode;
-        
-        for(int i = 1; i < pathNodes.length; i++)
-        {
-           currentNode = tempNode.getChild(pathNodes[i]);
-           
-           //If the navigation does not support an intermediate pathNode, then returns false
-           if (currentNode == null)
+         if(pathNodes.length == 0)
+         {
+            return 0;
+         }
+         
+         PageNode currentNode = nav.getNode(pathNodes[0]);
+         int numberOfMatch = (currentNode != null)? 1 : 0 ;
+         
+         for(int i = 1; i < pathNodes.length; i++)
+         {
+            if(currentNode == null)
             {
-               return false;
+               break;
             }
-            else
-            {
-               tempNode = currentNode;
-            }
-        }
-         return true;
+            currentNode = currentNode.getChild(pathNodes[i]);
+         }
+         return numberOfMatch;
       }
       
       /**
@@ -244,6 +258,11 @@
          }
          
          PageNode currentNode = targetedNav.getNode(pathNodes[0]);
+         if(currentNode == null)
+         {
+            return null;//Not found any node here
+         }
+         
          PageNode tempNode = null;
          
          for(int i = 1; i < pathNodes.length; i++)
@@ -251,7 +270,7 @@
             tempNode = currentNode.getChild(pathNodes[i]);
             if (tempNode == null)
             {
-               return null;
+               break;
             }
             else
             {
@@ -281,14 +300,14 @@
 
          for (int i = 1; i < pathNodes.length; i++)
          {
-            startNode = startNode.getChild(pathNodes[i]);
             if (startNode == null)
             {
-               return nodes;
+               break;
             }
             else
             {
                nodes.add(startNode);
+               startNode = startNode.getChild(pathNodes[i]);
             }
          }
          return nodes;
@@ -309,7 +328,6 @@
          UIPortal uiPortal = uiPortalApp.createUIComponent(UIPortal.class, null, null);
          //Reset selected navigation on userPortalConfig
          userPortalConfig.setSelectedNavigation(newPageNav);
-//         System.out.println("Build new UIPortal with OWNERTYPE: " + newPageNav.getOwnerType() + " OWNERID: " + newPageNav.getOwnerId());
          PortalDataMapper.toUIPortal(uiPortal, userPortalConfig);
          return uiPortal;
       }



More information about the gatein-commits mailing list