[gatein-commits] gatein SVN: r3868 - in portal/branches/navcontroller: portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Aug 19 05:17:51 EDT 2010


Author: trong.tran
Date: 2010-08-19 05:17:49 -0400 (Thu, 19 Aug 2010)
New Revision: 3868

Modified:
   portal/branches/navcontroller/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java
   portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIApplicationOrganizer.java
   portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java
   portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java
   portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIBreadcumbsPortlet.java
   portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UILogoPortlet.java
   portal/branches/navcontroller/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UINavigationNodeSelector.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPageNodeSelector.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIDesktopPage.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageBrowser.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageCreationWizard.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageForm.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/PageNodeEvent.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalActionListener.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/util/Util.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java
   portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
GTNPORTAL-1388 Determine navigation/node target before entering webui layer

Modified: portal/branches/navcontroller/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java
===================================================================
--- portal/branches/navcontroller/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -93,7 +93,7 @@
       //String remoteUser = Util.getPortalRequestContext().getRemoteUser();
       //pageNavigation = getPageNavigation(PortalConfig.USER_TYPE + "::" + remoteUser);
       //TODO: Check this part carefully
-      this.pageNavigation = uiPortal.getSelectedNavigation();
+      this.pageNavigation = uiPortal.getNavigation();
    }
 
    /*

Modified: portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIApplicationOrganizer.java
===================================================================
--- portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIApplicationOrganizer.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIApplicationOrganizer.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -98,6 +98,7 @@
 
       PortalRequestContext portalContext = org.exoplatform.portal.webui.util.Util.getPortalRequestContext();
       UIPortal uiPortal = org.exoplatform.portal.webui.util.Util.getUIPortal();
+      //TODO why use MonitorEvent that not just Event
       MonitorEvent<UIPortal> pnevent = new MonitorEvent<UIPortal>(uiPortal, "ChangeApplicationList", portalContext);
       uiPortal.broadcast(pnevent, Event.Phase.PROCESS);
    }

Modified: portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java
===================================================================
--- portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/navigation/webui/component/UISiteManagement.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -300,7 +300,7 @@
          uiComposer.setCollapse(false);
          uiComposer.setShowControl(true);
          uiComposer.setComponentConfig(UIPortalComposer.class, null);
-         uiComposer.setId("UIPortalComposer");
+         uiComposer.setId(UIPortalComposer.UIPORTAL_COMPOSER);
          
          UIPortal uiPortal = Util.getUIPortal();
          uiWorkingWS.setBackupUIPortal(uiPortal);
@@ -312,9 +312,8 @@
          // Check if edit current portal
          if (uiPortal.getName().equals(editPortal.getName()))
          {
+            editPortal.setNavigation(uiPortal.getNavigation());
             editPortal.setSelectedNode(uiPortal.getSelectedNode());
-            editPortal.setSelectedNavigation(uiPortal.getSelectedNavigation());
-            editPortal.setSelectedPath(uiPortal.getSelectedPath());
             UISiteBody siteBody = uiWorkingWS.findFirstComponentOfType(UISiteBody.class);
             siteBody.setUIComponent(null);
          }

Modified: portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java
===================================================================
--- portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -50,7 +50,7 @@
 
    public PageNavigation getSelectedNavigation() throws Exception
    {
-      return Util.getUIPortal().getSelectedNavigation();
+      return Util.getUIPortal().getNavigation();
    }
 
    @Override

Modified: portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIBreadcumbsPortlet.java
===================================================================
--- portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIBreadcumbsPortlet.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIBreadcumbsPortlet.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -30,7 +30,6 @@
 import org.exoplatform.webui.core.UIBreadcumbs;
 import org.exoplatform.webui.core.UIPortletApplication;
 import org.exoplatform.webui.core.UIBreadcumbs.LocalPath;
-import org.exoplatform.webui.core.UIBreadcumbs.SelectPathActionListener;
 import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
 import org.exoplatform.webui.event.Event;
 import org.exoplatform.webui.event.EventListener;

Modified: portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UILogoPortlet.java
===================================================================
--- portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UILogoPortlet.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UILogoPortlet.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -54,7 +54,7 @@
 
    public String getNavigationTitle() throws Exception
    {
-      PageNavigation navigation = Util.getUIPortal().getSelectedNavigation();
+      PageNavigation navigation = Util.getUIPortal().getNavigation();
       if (navigation.getOwnerType().equals(PortalConfig.GROUP_TYPE))
       {
          return OrganizationUtils.getGroupLabel(navigation.getOwnerId());

Modified: portal/branches/navcontroller/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js
===================================================================
--- portal/branches/navcontroller/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/web/eXoResources/src/main/webapp/javascript/eXo/portal/UIPortal.js	2010-08-19 09:17:49 UTC (rev 3868)
@@ -671,27 +671,6 @@
 	}
 	return true;
 };
-	
-/*
-* This method will start the creation of a new javascript application such as a widget
-*
-* - The application parameter is the full javascript class for the application (for example "eXo.widget.web.info.UIInfoWidget")
-* - The application id is an id shared among all the application instance
-* - The instance id is unique among all the javascript application deployed in the layout
-* - The appLocation is the root path location of the jstmpl file on the server (for example /eXoWidgetWeb/javascript/)
-*
-*  If the application class name is not null, the associated .js file on the server is loaded using the eXo.require() method
-*
-*  Once loaded the initApplication() method is called; in other words, the application is lazy instantiated and initialized
-*  on the client browser
-*/
-//UIPortal.prototype.createJSApplication = function(application, applicationId, instanceId, appLocation) {
-//	if(application) {
-//	  eXo.require(application, appLocation);
-//	  var createApplication = application + '.initApplication(\''+applicationId+'\',\''+instanceId+'\');' ;
-//	  eval(createApplication);
-//	}
-//} ;
 
 eXo.portal.UIPortalComponent = UIComponent.prototype.constructor ;
 eXo.portal.UIPortal = new UIPortal() ;

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -24,7 +24,9 @@
 import org.exoplatform.container.ExoContainer;
 import org.exoplatform.portal.config.UserPortalConfigService;
 import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.model.PageNavigation;
 import org.exoplatform.portal.config.model.PageNode;
+import org.exoplatform.portal.webui.portal.PageNodeEvent;
 import org.exoplatform.portal.webui.portal.UIPortal;
 import org.exoplatform.portal.webui.util.Util;
 import org.exoplatform.portal.webui.workspace.UIPortalApplication;
@@ -36,22 +38,16 @@
 import org.exoplatform.webui.application.WebuiApplication;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.event.Event;
 import org.gatein.common.http.QueryStringParser;
 import org.w3c.dom.Element;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.URLDecoder;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -61,6 +57,11 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 /**
  * This class extends the abstract WebuiRequestContext which itself extends the RequestContext one
@@ -69,7 +70,6 @@
  */
 public class PortalRequestContext extends WebuiRequestContext
 {
-
    protected static Log log = ExoLogger.getLogger("portal:PortalRequestContext");
 
    final static public int PUBLIC_ACCESS = 0;
@@ -113,28 +113,44 @@
    private List<Element> extraMarkupHeaders;
 
    private final PortalURLBuilder urlBuilder;
+
+   private Map<String, String[]> parameterMap;
    
-   private Map<String, String[]> parameterMap;
-
    private Locale locale = Locale.ENGLISH;
 
+   private PageNavigation targetNav;
+   
+   private PageNode targetNode_;
+
    public JavascriptManager getJavascriptManager()
    {
       return jsmanager_;
    }
 
+   /**
+    * Analyze a request and split this request's URI to get useful information
+    * then keep it in following properties of PortalRequestContext :<br/>
+    * 1. <code>requestURI</code> : The decoded URI of this request <br/>
+    * 2. <code>portalOwner</code> : The portal name ( "classic" for instance )<br/>
+    * 3. <code>portalURI</code> : The URI to current portal ( "/portal/classic/ for instance )<br/>
+    * 4. <code>nodePath</code> : The path that is used to reflect to a navigation node
+    * 
+    * @param app an instance of {@link PortalApplication}
+    * @param req the {@ HttpServletRequest} object that is sent to the {@link PortalController} servlet
+    * @param res 
+    * @throws Exception
+    */
    public PortalRequestContext(WebuiApplication app, HttpServletRequest req, HttpServletResponse res) throws Exception
    {
       super(app);
       request_ = req;
       response_ = res;
       response_.setBufferSize(1024 * 100);
-      setSessionId(req.getSession().getId());
-      
-      
+      setSessionId(request_.getSession().getId());
+
       //The encoding needs to be set before reading any of the parameters since the parameters's encoding
       //is set at the first access.
-      
+
       //TODO use the encoding from the locale-config.xml file
       response_.setContentType("text/html; charset=UTF-8");
       try
@@ -145,36 +161,36 @@
       {
          log.error("Encoding not supported", e);
       }
-      
+
       // Query parameters from the request will be set in the servlet container url encoding and not
       // necessarly in utf-8 format. So we need to directly parse the parameters from the query string.
       parameterMap = new HashMap<String, String[]>();
       parameterMap.putAll(request_.getParameterMap());
-      String queryString = req.getQueryString();
+      String queryString = request_.getQueryString();
       if (queryString != null)
       {
          Map<String, String[]> queryParams = QueryStringParser.getInstance().parseQueryString(queryString);
          parameterMap.putAll(queryParams);
       }
-      
-      ajaxRequest_ = "true".equals(req.getParameter("ajaxRequest"));
-      String cache = req.getParameter(CACHE_LEVEL);
+
+      ajaxRequest_ = "true".equals(request_.getParameter("ajaxRequest"));
+      String cache = request_.getParameter(CACHE_LEVEL);
       if (cache != null)
       {
          cacheLevel_ = cache;
       }
 
-      requestURI_ = URLDecoder.decode(req.getRequestURI(), "UTF-8");
-      
+      requestURI_ = URLDecoder.decode(request_.getRequestURI(), "UTF-8");
+
       // req.getPathInfo will already have the encoding set from the server.
       // We need to use the UTF-8 value since this is how we store the portal name.
       // Reconstructing the getPathInfo from the non server decoded values.
-      String servletPath = URLDecoder.decode(req.getServletPath(), "UTF-8");
-      String contextPath = URLDecoder.decode(req.getContextPath(), "UTF-8");
+      String servletPath = URLDecoder.decode(request_.getServletPath(), "UTF-8");
+      String contextPath = URLDecoder.decode(request_.getContextPath(), "UTF-8");
       String pathInfo = "/";
       if (requestURI_.length() > servletPath.length() + contextPath.length())
          pathInfo = requestURI_.substring(servletPath.length() + contextPath.length());
-      
+
       int colonIndex = pathInfo.indexOf("/", 1);
       if (colonIndex < 0)
       {
@@ -217,7 +233,8 @@
          {
             ExoContainer container = getApplication().getApplicationServiceContainer();
             container.getComponentInstanceOfType(UserPortalConfigService.class);
-            UserPortalConfigService configService = (UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
+            UserPortalConfigService configService =
+               (UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
             Page page = configService.getPage(node.getPageReference(), getRemoteUser());
 
             //
@@ -236,6 +253,43 @@
       return title;
    }
 
+   /**
+    * Process current Portal Request URI. if current require uri is not equal to last one then
+    * an event of type UIPortalApplication.CHANGE_NODE will be retuned, otherwise it returns <code>null</code>
+    * 
+    * @return
+    * @throws Exception
+    */
+   public Event<UIComponent> processPortalURI() throws Exception
+   {
+      UIPortalApplication uiPortalApp = (UIPortalApplication)uiApplication_;
+      List<PageNavigation> navigations = uiPortalApp.getNavigations();
+
+      String lastNodePath = uiPortalApp.getLastNodePath();
+      
+      // Do not need to process if the request uri is not changed from last one
+      if(nodePath_.equals(lastNodePath))
+      {
+         // Should set the last navi & node to this instance of PortalRequestContext to be used subsequently
+         return null;
+      }
+      
+      uiPortalApp.setLastNodePath(nodePath_);
+      
+      Object[] targets = Util.findBestMatchNavigationAndNode(navigations, nodePath_);
+      if(targets == null) 
+      {
+         targetNav = navigations.get(0);
+         targetNode_ = Util.findFirstAvailableNode(targetNav, this);
+      }
+      else
+      {
+         targetNav = (PageNavigation)targets[0];
+         targetNode_ = (PageNode)targets[1];
+      }
+      return uiPortalApp.createEvent(PageNodeEvent.CHANGE_NODE, Event.Phase.PROCESS, this);
+   }
+
    public Orientation getOrientation()
    {
       return ((UIPortalApplication)uiApplication_).getOrientation();
@@ -335,6 +389,26 @@
       return portalURI;
    }
 
+   public PageNavigation getTargetNav()
+   {
+      return targetNav;
+   }
+
+   public void setTargetNav(PageNavigation targetNav)
+   {
+      this.targetNav = targetNav;
+   }
+
+   public PageNode getTargetNode()
+   {
+      return targetNode_;
+   }
+
+   public void setTargetNode(PageNode naviNode)
+   {
+      targetNode_ = naviNode;
+   }
+   
    public URLBuilder<UIComponent> getURLBuilder()
    {
       return urlBuilder;
@@ -363,10 +437,10 @@
       }
       return writer_;
    }
-   
+
    final public void setWriter(Writer writer)
    {
-	   this.writer_ = writer;
+      this.writer_ = writer;
    }
 
    final public boolean useAjax()
@@ -426,11 +500,11 @@
          response_.setHeader(key, headers.get(key));
       }
    }
-   
+
    public List<String> getExtraMarkupHeadersAsStrings() throws Exception
    {
       List<String> markupHeaders = new ArrayList<String>();
-      
+
       if (extraMarkupHeaders != null && !extraMarkupHeaders.isEmpty())
       {
          Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -457,31 +531,30 @@
             markupHeaders.add(result.getWriter().toString());
          }
       }
-      
-       return markupHeaders;
+
+      return markupHeaders;
    }
-   
+
    /**
     * Get the extra markup headers to add to the head of the html.
     * @return The markup to be added.
     */
    public List<Element> getExtraMarkupHeaders()
    {
-	   return this.extraMarkupHeaders;
+      return this.extraMarkupHeaders;
    }
-   
+
    /**
     * Add an extra markup to the head of the html page.
     * @param element The element to add
     */
    public void addExtraMarkupHeader(Element element)
    {
-	  if (this.extraMarkupHeaders == null)
-	  {
-		  this.extraMarkupHeaders = new ArrayList<Element>();
-	  }
-	  this.extraMarkupHeaders.add(element);
+      if (this.extraMarkupHeaders == null)
+      {
+         this.extraMarkupHeaders = new ArrayList<Element>();
+      }
+      this.extraMarkupHeaders.add(element);
    }
 
-
 }

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -31,6 +31,8 @@
 import org.exoplatform.web.application.RequestFailure;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.core.UIApplication;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.event.Event;
 
 import java.util.List;
 
@@ -100,10 +102,19 @@
          UIApplication uiApp = app.getStateManager().restoreUIRootComponent(context);
          if (context.getUIApplication() != uiApp)
             context.setUIApplication(uiApp);
-
+         
          if (uiApp != null)
+         {
             uiApp.processDecode(context);
-
+            
+            Event<UIComponent> changeNodeEvent = context.processPortalURI();
+            if(changeNodeEvent != null)
+            {
+               changeNodeEvent.broadcast();
+               System.out.println("\nLoading node : " + context.getTargetNav() + "==>" + context.getTargetNode().getUri() + "\n");
+            }
+         }
+         
          if (!context.isResponseComplete() && !context.getProcessRender())
          {
             startRequestPhaseLifecycle(app, context, lifecycles, Phase.ACTION);

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -63,46 +63,37 @@
          appState = (ApplicationState)session.getAttribute(APPLICATION_ATTRIBUTE_PREFIX + key);
       }
 
-      //
-
-      //
       UIApplication uiapp = null;
       if (appState != null)
       {
+         log.debug("Found application " + key + " :" + appState.getApplication());
          if (Safe.equals(context.getRemoteUser(), appState.getUserName()))
          {
             uiapp = appState.getApplication();
          }
       }
-
-      //
-      if (appState != null)
-      {
-         log.debug("Found application " + key + " :" + appState.getApplication());
-      }
       else
       {
          log.debug("Application " + key + " not found");
       }
 
-      // Looks like some necessary hacking
-      if (context instanceof PortalRequestContext)
-      {
-         PortalRequestContext portalRC = (PortalRequestContext)context;
-         UserPortalConfig config = getUserPortalConfig(portalRC);
-         if (config == null)
-         {
-            HttpServletResponse response = portalRC.getResponse();
-            response.sendRedirect(portalRC.getRequest().getContextPath() + "/portal-unavailable.jsp");
-            portalRC.setResponseComplete(true);
-            return null;
-         }
-         portalRC.setAttribute(UserPortalConfig.class, config);
-      }
-
       //
       if (uiapp == null)
       {
+         if (context instanceof PortalRequestContext)
+         {
+            PortalRequestContext portalRC = (PortalRequestContext)context;
+            UserPortalConfig config = getUserPortalConfig(portalRC);
+            if (config == null)
+            {
+               HttpServletResponse response = portalRC.getResponse();
+               response.sendRedirect(portalRC.getRequest().getContextPath() + "/portal-unavailable.jsp");
+               portalRC.setResponseComplete(true);
+               return null;
+            }
+            portalRC.setAttribute(UserPortalConfig.class, config);
+         }
+         
          ConfigurationManager cmanager = app.getConfigurationManager();
          String uirootClass = cmanager.getApplication().getUIRootComponent();
          Class<? extends UIApplication> type = (Class<UIApplication>) Thread.currentThread().getContextClassLoader().loadClass(uirootClass);

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UINavigationNodeSelector.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UINavigationNodeSelector.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UINavigationNodeSelector.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -431,7 +431,7 @@
 
             uiApp.setModeState(UIPortalApplication.APP_BLOCK_EDIT_MODE);
             //uiWorkingWS.setRenderedChild(UIPortalToolPanel.class);
-            //uiWorkingWS.addChild(UIPortalComposer.class, "UIPageEditor", null);
+            //uiWorkingWS.addChild(UIPortalComposer.class, UIPortalComposer.UIPAGE_EDITOR, null);
 
             uiWorkingWS.setRenderedChild(UIEditInlineWorkspace.class);
 
@@ -440,14 +440,13 @@
             portalComposer.setShowControl(true);
             portalComposer.setEditted(false);
             portalComposer.setCollapse(false);
-            portalComposer.setId("UIPageEditor");
-            portalComposer.setComponentConfig(UIPortalComposer.class, "UIPageEditor");
+            portalComposer.setId(UIPortalComposer.UIPAGE_EDITOR);
+            portalComposer.setComponentConfig(UIPortalComposer.class, UIPortalComposer.UIPAGE_EDITOR);
 
             uiToolPanel.setShowMaskLayer(false);
             uiToolPanel.setWorkingComponent(UIPage.class, null);
             UIPage uiPage = (UIPage)uiToolPanel.getUIComponent();
 
-            WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
             if(selectPage.getTitle() == null)
                selectPage.setTitle(selectedPageNode.getLabel());
 

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPageNodeSelector.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPageNodeSelector.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPageNodeSelector.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -67,7 +67,7 @@
 
    private void loadNavigations() throws Exception
    {
-      PageNavigation portalSelectedNav = Util.getUIPortal().getSelectedNavigation();
+      PageNavigation portalSelectedNav = Util.getUIPortal().getNavigation();
       if (portalSelectedNav != null)
       {
          selectNavigation(portalSelectedNav);

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -25,7 +25,6 @@
 import org.exoplatform.portal.webui.portal.PageNodeEvent;
 import org.exoplatform.portal.webui.portal.UIPortal;
 import org.exoplatform.portal.webui.util.Util;
-import org.exoplatform.web.application.JavascriptManager;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.core.UIComponent;
 import org.exoplatform.webui.event.Event;
@@ -188,12 +187,7 @@
 
    public PageNavigation getSelectedNavigation() throws Exception
    {
-      PageNavigation nav = Util.getUIPortal().getSelectedNavigation();
-      if (nav != null)
-         return nav;
-      if (Util.getUIPortal().getNavigations().size() < 1)
-         return null;
-      return Util.getUIPortal().getNavigations().get(0);
+      return Util.getUIPortal().getNavigation();
    }
 
    public Object getSelectedParent()
@@ -264,13 +258,13 @@
          PageNavigation selectNav = null;
          if (index <= 0)
          {
-            selectNav = uiPortal.getSelectedNavigation();
+            selectNav = uiPortal.getNavigation();
          }
          else
          {
             String navId = uri.substring(0, index);
             //selectNav = uiPortal.getPageNavigation(Integer.parseInt(navId));
-            selectNav = uiPortal.getSelectedNavigation();
+            selectNav = uiPortal.getNavigation();
          }
          PageNode selectNode = PageNavigationUtils.searchPageNodeByUri(selectNav, id);
          uiNavigation.selectedNode_ = selectNode;
@@ -353,7 +347,7 @@
          
          //TODO: Minh Hoang TO
          //selectNav = uiPortal.getPageNavigation(Integer.parseInt(navId));
-         selectNav = uiPortal.getSelectedNavigation();
+         selectNav = uiPortal.getNavigation();
          
          // get PageNode by uri
          PageNode expandNode = PageNavigationUtils.searchPageNodeByUri(selectNav, id);

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -72,21 +72,13 @@
    {
       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
       List<PageNavigation> result = new ArrayList<PageNavigation>();
-      for (PageNavigation nav : Util.getUIPortal().getNavigations())
-      {
-         result.add(PageNavigationUtils.filter(nav, context.getRemoteUser()));
-      }
+      result.add(PageNavigationUtils.filter(Util.getUIPortal().getNavigation(), context.getRemoteUser()));
       return result;
    }
 
    public PageNavigation getSelectedNavigation() throws Exception
    {
-      PageNavigation nav = Util.getUIPortal().getSelectedNavigation();
-      if (nav != null)
-         return nav;
-      if (Util.getUIPortal().getNavigations().size() < 1)
-         return null;
-      return Util.getUIPortal().getNavigations().get(0);
+      return Util.getUIPortal().getNavigation();
    }
 
    public Object getSelectedParent()
@@ -157,7 +149,7 @@
          PageNavigation selectNav = null;
          if (index <= 0)
          {
-            selectNav = uiPortal.getSelectedNavigation();
+            selectNav = uiPortal.getNavigation();
          }
          else
          {
@@ -165,7 +157,7 @@
             
             //TODO: Minh Hoang TO
             //selectNav = uiPortal.getPageNavigation(Integer.parseInt(navId));
-            selectNav = uiPortal.getSelectedNavigation();
+            selectNav = uiPortal.getNavigation();
          }
          PageNode selectNode = PageNavigationUtils.searchPageNodeByUri(selectNav, id);
          uiNavigation.selectedNode_ = selectNode;

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -29,7 +29,6 @@
 import org.exoplatform.portal.webui.workspace.UIPortalApplication;
 
 import java.util.ArrayList;
-import java.util.List;
 
 /**
  * Created by The eXo Platform SAS
@@ -79,19 +78,5 @@
       
       DataStorage dataService = uiPortal.getApplicationComponent(DataStorage.class);
       dataService.save(navi);
-      setNavigation(uiPortal.getNavigations(), navi);
    }
-
-   private static void setNavigation(List<PageNavigation> navs, PageNavigation nav)
-   {
-      for (int i = 0; i < navs.size(); i++)
-      {
-         if (navs.get(i).getId() == nav.getId())
-         {
-            navs.set(i, nav);
-            return;
-         }
-      }
-   }
-
 }

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIDesktopPage.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIDesktopPage.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIDesktopPage.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -77,13 +77,9 @@
 
    public List<PageNavigation> getNavigations() throws Exception
    {
-      List<PageNavigation> allNav = Util.getUIPortal().getNavigations();
       String removeUser = Util.getPortalRequestContext().getRemoteUser();
       List<PageNavigation> result = new ArrayList<PageNavigation>();
-      for (PageNavigation nav : allNav)
-      {
-         result.add(PageNavigationUtils.filter(nav, removeUser));
-      }
+      result.add(PageNavigationUtils.filter(Util.getUIPortal().getNavigation(), removeUser));
       return result;
    }
 

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageActionListener.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -19,11 +19,9 @@
 
 package org.exoplatform.portal.webui.page;
 
-import org.exoplatform.container.ExoContainer;
 import org.exoplatform.portal.application.PortalRequestContext;
 import org.exoplatform.portal.config.DataStorage;
 import org.exoplatform.portal.config.UserPortalConfig;
-import org.exoplatform.portal.config.UserPortalConfigService;
 import org.exoplatform.portal.config.model.Container;
 import org.exoplatform.portal.config.model.ModelObject;
 import org.exoplatform.portal.config.model.Page;
@@ -47,88 +45,79 @@
 import java.util.List;
 
 /**
- * Created by The eXo Platform SAS Author : Tran The Trong trongtt at gmail.com Jun
- * 14, 2006
+ * Just a class that contains the Page related action listeners
+ * 
+ * @author <a href="mailto:trongtt at gmail.com">Tran The Trong</a>
+ * @version $Revision$
  */
 public class UIPageActionListener
 {
-
-   static public class ChangePageNodeActionListener extends EventListener<UIPortal>
+   private static UIPortal buildUIPortal(PageNavigation newPageNav, UIPortalApplication uiPortalApp, UserPortalConfig userPortalConfig) throws Exception
    {
+      DataStorage storage = uiPortalApp.getApplicationComponent(DataStorage.class);
+      if(storage == null){
+         return null;
+      }
+      PortalConfig portalConfig = storage.getPortalConfig(newPageNav.getOwnerType(), newPageNav.getOwnerId());
+      Container layout = portalConfig.getPortalLayout();
+      if(layout != null)
+      {
+         userPortalConfig.setPortal(portalConfig);
+      }
+      UIPortal uiPortal = uiPortalApp.createUIComponent(UIPortal.class, null, null);
+      //Reset selected navigation on userPortalConfig
+      userPortalConfig.setSelectedNavigation(newPageNav);
+      PortalDataMapper.toUIPortal(uiPortal, userPortalConfig);
+      return uiPortal;
+   }
+   
+   /**
+    * Navigate to a page node base on the input parameters <code>nav</code> PageNavigaton and <code>pageNode</code> PageNode
+    * 
+    * @author <a href="mailto:trongtt at gmail.com">Tran The Trong</a>
+    * @version $Revision$
+    */
+   static public class ChangeNodeActionListener extends EventListener<UIPortalApplication>
+   {
       @Override
-      public void execute(Event<UIPortal> event) throws Exception
+      public void execute(Event<UIPortalApplication> event) throws Exception
       {
-         UIPortal showedUIPortal = event.getSource();
-         UIPortalApplication uiPortalApp = showedUIPortal.getAncestorOfType(UIPortalApplication.class);
+         PortalRequestContext pcontext = (PortalRequestContext)event.getRequestContext();
+         PageNavigation targetNav = pcontext.getTargetNav();
+         PageNode newPageNode = pcontext.getTargetNode();
          
-         //This code snippet is to make sure that Javascript/Skin is fully loaded at the first request
-         UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
-         PortalRequestContext pcontext = Util.getPortalRequestContext();
-         pcontext.setFullRender(true);
-         pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
-         
-         PageNavigation currentNav = showedUIPortal.getSelectedNavigation();
-         String currentUri = showedUIPortal.getSelectedNode().getUri();
-         if(currentUri.startsWith("/"))
+         UIPortalApplication uiPortalApp = event.getSource();
+         UIPortal uiPortal = uiPortalApp.getShowedUIPortal();
+         PageNavigation currentNav = uiPortal.getNavigation();
+         if(currentNav.getOwnerType().equals(targetNav.getOwnerType()) & currentNav.getOwnerId().equals(targetNav.getOwnerId()))
          {
-            currentUri = currentUri.substring(1);
-         }
-         
-         //This if branche is to make sure that the first time user logs in, showedUIPortal has selectedPaths
-         //Otherwise, there will be NPE on BreadcumbsPortlet
-         if(showedUIPortal.getSelectedPath() == null)
-         {
-            List<PageNode> currentSelectedPath = findPath(currentNav, currentUri.split("/"));
-            showedUIPortal.setSelectedPath(currentSelectedPath);
-         }
-         
-         String targetedUri = ((PageNodeEvent<UIPortal>)event).getTargetNodeUri();
-         if(targetedUri.startsWith("/"))
-         {
-            targetedUri = targetedUri.substring(1);
-         }
-         
-         PageNavigation targetedNav = getTargetedNav(uiPortalApp, targetedUri);
-         
-         if(targetedNav == null)
-         {
-            return;
-         }
-       
-         String formerNavType = currentNav.getOwnerType();
-         String formerNavId = currentNav.getOwnerId();
-         String newNavType = targetedNav.getOwnerType();
-         String newNavId = targetedNav.getOwnerId();
-         
-         String[] targetPath = targetedUri.split("/");
-         PageNode targetPageNode = getTargetedNode(targetedNav, targetPath);
-         List<PageNode> targetedPathNodes = findPath(targetedNav, targetPath);
-         
-         if(formerNavType.equals(newNavType) && formerNavId.equals(newNavId))
-         {
-            //Case 1: Both navigation type and id are not changed, but current page node is changed
-            if(!currentUri.equals(targetedUri))
+            if(!uiPortal.getSelectedNode().getUri().equals(newPageNode.getUri()))
             {
-               showedUIPortal.setSelectedNode(targetPageNode);
-               showedUIPortal.setSelectedPath(targetedPathNodes);
+               uiPortal.setSelectedNode(newPageNode);
             }
          }
          else
          {
-            // Case 2: Either navigation type or id has been changed
-            // First, we try to find a cached UIPortal
-            uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
-            uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
-            showedUIPortal = uiPortalApp.getCachedUIPortal(newNavType, newNavId);
-            if (showedUIPortal != null)
+            uiPortal = uiPortalApp.getCachedUIPortal(targetNav.getOwnerType(), targetNav.getOwnerId());
+            if(uiPortal == null)
             {
-               showedUIPortal.setSelectedNode(targetPageNode);
-               showedUIPortal.setSelectedPath(targetedPathNodes);
-               uiPortalApp.setShowedUIPortal(showedUIPortal);
+               uiPortal = buildUIPortal(targetNav, uiPortalApp, uiPortalApp.getUserPortalConfig());
+               if(uiPortal == null)
+               {
+                  return;
+               }
+               uiPortal.setSelectedNode(newPageNode);
+               uiPortalApp.setShowedUIPortal(uiPortal);
+               uiPortalApp.putCachedUIPortal(uiPortal);
+            }
+            else
+            {
+               uiPortal.setSelectedNode(newPageNode);
+               uiPortalApp.setShowedUIPortal(uiPortal);
                
                //Temporary solution to fix edit inline error while switching between navigations
                DataStorage storageService = uiPortalApp.getApplicationComponent(DataStorage.class);
-               PortalConfig associatedPortalConfig = storageService.getPortalConfig(newNavType, newNavId);
+               PortalConfig associatedPortalConfig = storageService.getPortalConfig(targetNav.getOwnerType(), targetNav.getOwnerId());
                UserPortalConfig userPortalConfig = uiPortalApp.getUserPortalConfig();
                
                //Update layout-related data on UserPortalConfig
@@ -136,250 +125,98 @@
 
                //Update selected navigation on UserPortalConfig, that is mandatory as at the moment the PortalConfig
                //does not hold any navigation data.
-               userPortalConfig.updateSelectedNavigation(newNavType, newNavId);
+               userPortalConfig.setSelectedNavigation(targetNav);
             }
-            else
-            {
-               showedUIPortal = buildUIPortal(targetedNav, uiPortalApp, uiPortalApp.getUserPortalConfig());
-               if(showedUIPortal == null)
-               {
-                  return;
-               }
-               showedUIPortal.setSelectedNode(targetPageNode);
-               showedUIPortal.setSelectedPath(targetedPathNodes);
-               uiPortalApp.setShowedUIPortal(showedUIPortal);
-               uiPortalApp.putCachedUIPortal(showedUIPortal);
-            }
          }
-         showedUIPortal.refreshUIPage();
+         uiPortal.refreshUIPage();
       }
-      
-      /**
-       * Get the targeted <code>PageNavigation</code>
-       * 
-       * @param uiPortalApp
-       * @param targetedUri
-       * @return
-       */
-      private PageNavigation getTargetedNav(UIPortalApplication uiPortalApp, String targetedUri)
+   }
+   
+   /**
+    * Navigate to a page node in current navigation of UIPortal.
+    * 
+    * @author <a href="mailto:trongtt at gmail.com">Tran The Trong</a>
+    * @version $Revision$
+    */
+   static public class ChangePageNodeActionListener extends EventListener<UIPortal>
+   {
+      @Override
+      public void execute(Event<UIPortal> event) throws Exception
       {
-         List<PageNavigation> allNavs = uiPortalApp.getUserPortalConfig().getNavigations();
+         UIPortal uiPortal = event.getSource();
+         UIPortalApplication uiPortalApp = uiPortal.getAncestorOfType(UIPortalApplication.class);
          
-         //That happens when user browses to an empty-nodeUri URL like ../portal/public/classic/
-         //In this case, we returns default navigation
-         if(targetedUri.length() == 0)
-         {
-            return uiPortalApp.getNavigations().get(0);
-         }
+         //This code snippet is to make sure that Javascript/Skin is fully loaded at the first request
+         UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
+         PortalRequestContext pcontext = Util.getPortalRequestContext();
+         pcontext.setFullRender(true);
+         pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
+
          
-         String[] pathNodes = targetedUri.split("/");
+         String targetedUri = ((PageNodeEvent<UIPortal>)event).getTargetNodeUri();
          
-         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)
+         PageNode targetPageNode;
+         PageNavigation targetedNav;
+         List<PageNavigation> navigations = uiPortalApp.getNavigations();
+
+         Object[] targets = Util.findBestMatchNavigationAndNode(navigations, targetedUri);
+         if(targets == null) 
          {
-            int currentNumberOfMatching = countNumberOfMatchedPathNodes(nav, pathNodes);
-            
-            //The whole pathNodes matches current navigation
-            if(currentNumberOfMatching == pathNodes.length)
-            {
-               return nav;
-            }
-            
-            if(currentNumberOfMatching > temporalMaximalMatching)
-            {
-               temporalMaximalMatching = currentNumberOfMatching;
-               temporalBestNavigation = nav;
-            }
+            targetedNav = navigations.get(0);
+            targetPageNode = Util.findFirstAvailableNode(targetedNav, pcontext);
          }
-         return temporalBestNavigation;
-      }
-      
-      /**
-       * Count the maximal number of nodes matching the pathNodes while descending the navigation 'nav'
-       * 
-       * @param nav
-       * @param pathNodes
-       * @return
-       */
-      private int countNumberOfMatchedPathNodes(PageNavigation nav, String[] pathNodes)
-      {
-         if(pathNodes.length == 0)
+         else
          {
-            return 0;
+            targetedNav = (PageNavigation)targets[0];
+            targetPageNode = (PageNode)targets[1];
          }
          
-         PageNode currentNode = nav.getNode(pathNodes[0]);
-         int numberOfMatch = (currentNode != null)? 1 : 0 ;
+         /////////////////////////////
          
-         for(int i = 1; i < pathNodes.length; i++)
+         PageNavigation currentNav = uiPortal.getNavigation();
+         if(currentNav.getOwnerType().equals(targetedNav.getOwnerType()) & currentNav.getOwnerId().equals(targetedNav.getOwnerId()))
          {
-            if(currentNode == null)
+            if(!uiPortal.getSelectedNode().getUri().equals(targetPageNode.getUri()))
             {
-               break;
+               uiPortal.setSelectedNode(targetPageNode);
             }
-            currentNode = currentNode.getChild(pathNodes[i]);
          }
-         return numberOfMatch;
-      }
-      
-      /**
-       * Fetch the currently selected pageNode under a PageNavigation. It is the last node encountered
-       * while descending the pathNodes
-       * 
-       * This method returns <code>null</code> iff only 'notfound' node remains in the navigation
-       * 
-       * @param targetedNav
-       * @param pathNodes
-       * @return
-       */
-      private PageNode getTargetedNode(PageNavigation targetedNav, String[] pathNodes)
-      {
-         //Case users browses to a URL of the form  */portal/public/classic
-         if(pathNodes.length == 0)
+         else
          {
-           return getDefaultNode(targetedNav);
-         }
-         
-         PageNode currentNode = targetedNav.getNode(pathNodes[0]);
-         if(currentNode == null)
-         {
-            return getDefaultNode(targetedNav);
-         }
-         
-         PageNode tempNode = null;
-         
-         for(int i = 1; i < pathNodes.length; i++)
-         {
-            tempNode = currentNode.getChild(pathNodes[i]);
-            if (tempNode == null)
+            uiPortal = uiPortalApp.getCachedUIPortal(targetedNav.getOwnerType(), targetedNav.getOwnerId());
+            if(uiPortal == null)
             {
-               break;
-            }
-            else
-            {
-               currentNode = tempNode;
-            }
-         }
-         return currentNode;
-      }
-      
-      /**
-       * Default node of a navigation. This method returns
-       * 
-       * 1. The first node in the list of 'nav' 's children if the list contains
-       * at least one child other than 'notfound'
-       * 
-       * 2. <code>null</code> otherwise
-       * 
-       * @param nav
-       * @return
-       */
-      private PageNode getDefaultNode(PageNavigation nav)
-      {
-         PageNode defaultNode = null;
-         try
-         {
-            if (nav != null && nav.getNodes().size() > 0)
-            {
-               WebuiRequestContext context = Util.getPortalRequestContext();
-               ExoContainer appContainer = context.getApplication().getApplicationServiceContainer();
-               UserPortalConfigService userPortalConfigService = (UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
-               
-               for (PageNode pageNode : nav.getNodes())
+               uiPortal = buildUIPortal(targetedNav, uiPortalApp, uiPortalApp.getUserPortalConfig());
+               if(uiPortal == null)
                {
-                  Page page = userPortalConfigService.getPage(pageNode.getPageReference(), context.getRemoteUser());
-                  if (page != null)
-                  {
-                     defaultNode = pageNode;
-                     break;
-                  }
+                  return;
                }
+               uiPortal.setSelectedNode(targetPageNode);
+               uiPortalApp.setShowedUIPortal(uiPortal);
+               uiPortalApp.putCachedUIPortal(uiPortal);
             }
             else
             {
-               return null;
-            }
-         }
-         catch (Exception e)
-         {
-            e.printStackTrace();
-            return null;
-         }
-         if (defaultNode != null && !("notfound".equals(defaultNode.getName())))
-         {
-            return defaultNode;
-         }
-         else
-         {
-            return null;
-         }
-      }
-      
-      private List<PageNode> findPath(PageNavigation nav, String[] pathNodes)
-      {
-         List<PageNode> nodes = new ArrayList<PageNode>(4);
-         
-         //That happens when user browses to a URL like /portal/public/classic
-         if(pathNodes.length == 0)
-         {
-            nodes.add(getDefaultNode(nav));
-            return nodes;
-         }
-         PageNode startNode = nav.getNode(pathNodes[0]);
-         if (startNode == null)
-         {
-            nodes.add(getDefaultNode(nav));
-            return nodes;
-         }
-         nodes.add(startNode);
+               uiPortal.setSelectedNode(targetPageNode);
+               uiPortalApp.setShowedUIPortal(uiPortal);
+               
+               //Temporary solution to fix edit inline error while switching between navigations
+               DataStorage storageService = uiPortalApp.getApplicationComponent(DataStorage.class);
+               PortalConfig associatedPortalConfig = storageService.getPortalConfig(targetedNav.getOwnerType(), targetedNav.getOwnerId());
+               UserPortalConfig userPortalConfig = uiPortalApp.getUserPortalConfig();
+               
+               //Update layout-related data on UserPortalConfig
+               userPortalConfig.setPortal(associatedPortalConfig);
 
-         for (int i = 1; i < pathNodes.length; i++)
-         {
-            startNode = startNode.getChild(pathNodes[i]);
-            if(startNode == null)
-            {
-               break;
+               //Update selected navigation on UserPortalConfig, that is mandatory as at the moment the PortalConfig
+               //does not hold any navigation data.
+               userPortalConfig.setSelectedNavigation(targetedNav);
             }
-            else
-            {
-               nodes.add(startNode);
-            }
          }
-         return nodes;
+         uiPortal.refreshUIPage();
       }
-
-      private UIPortal buildUIPortal(PageNavigation newPageNav, UIPortalApplication uiPortalApp, UserPortalConfig userPortalConfig) throws Exception
-      {
-         DataStorage storage = uiPortalApp.getApplicationComponent(DataStorage.class);
-         if(storage == null){
-            return null;
-         }
-         PortalConfig portalConfig = storage.getPortalConfig(newPageNav.getOwnerType(), newPageNav.getOwnerId());
-         Container layout = portalConfig.getPortalLayout();
-         if(layout != null)
-         {
-            userPortalConfig.setPortal(portalConfig);
-         }
-         UIPortal uiPortal = uiPortalApp.createUIComponent(UIPortal.class, null, null);
-         //Reset selected navigation on userPortalConfig
-         userPortalConfig.setSelectedNavigation(newPageNav);
-         PortalDataMapper.toUIPortal(uiPortal, userPortalConfig);
-         return uiPortal;
-      }
    }
 
   

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageBrowser.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageBrowser.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageBrowser.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -436,16 +436,16 @@
          editInlineWS.setUIComponent(uiPage);
 
          UIPortalComposer portalComposer = editInlineWS.getChild(UIPortalComposer.class).setRendered(true);
-         portalComposer.setComponentConfig(UIPortalComposer.class, "UIPageEditor");
+         portalComposer.setComponentConfig(UIPortalComposer.class, UIPortalComposer.UIPAGE_EDITOR);
          portalComposer.setShowControl(true);
          portalComposer.setEditted(false);
          portalComposer.setCollapse(false);
-         portalComposer.setId("UIPageEditor");
+         portalComposer.setId(UIPortalComposer.UIPAGE_EDITOR);
 
          //toolPanel.setUIComponent(uiPage);
          //toolPanel.setShowMaskLayer(false);
          //uiWorkingWS.setRenderedChild(UIPortalToolPanel.class);
-         //uiWorkingWS.addChild(UIPortalComposer.class, "UIPageEditor", null);
+         //uiWorkingWS.addChild(UIPortalComposer.class, UIPortalComposer.UIPAGE_EDITOR, null);
          uiWorkingWS.setRenderedChild(UIPortalApplication.UI_EDITTING_WS_ID);
          pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
          pcontext.setFullRender(true);

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageCreationWizard.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageCreationWizard.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageCreationWizard.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -36,7 +36,6 @@
 import org.exoplatform.portal.webui.workspace.UIPortalToolPanel;
 import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
 import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.web.application.JavascriptManager;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.config.annotation.ComponentConfig;
 import org.exoplatform.webui.config.annotation.ComponentConfigs;
@@ -75,7 +74,7 @@
       setNumberSteps(NUMBER_OF_STEPs);
       viewStep(FIRST_STEP);
       setShowWelcomeComponent(false);
-      boolean isUserNav = Util.getUIPortal().getSelectedNavigation().getOwnerType().equals(PortalConfig.USER_TYPE);
+      boolean isUserNav = Util.getUIPortal().getNavigation().getOwnerType().equals(PortalConfig.USER_TYPE);
       if (isUserNav)
       {
          uiPageInfo.getChild(UIPageNodeSelector.class).setRendered(false);
@@ -117,22 +116,8 @@
       DataStorage dataService = getApplicationComponent(DataStorage.class); 
       dataService.create(page);
       dataService.save(pageNav);
-      UIPortal uiPortal = Util.getUIPortal();
-      setNavigation(uiPortal.getNavigations(), uiNodeSelector.getSelectedNavigation());
    }
 
-   private void setNavigation(List<PageNavigation> navs, PageNavigation nav)
-   {
-      for (int i = 0; i < navs.size(); i++)
-      {
-         if (navs.get(i).getId() == nav.getId())
-         {
-            navs.set(i, nav);
-            return;
-         }
-      }
-   }
-
    /**
     * Returns <code>true</code> if the creating node is existing already.
     * Otherwise it returns <code>false</code>

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageForm.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageForm.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageForm.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -32,7 +32,6 @@
 import org.exoplatform.portal.config.model.PortalConfig;
 import org.exoplatform.portal.webui.application.UIPortlet;
 import org.exoplatform.portal.webui.container.UIContainer;
-import org.exoplatform.portal.webui.portal.UIPortalComponent;
 import org.exoplatform.portal.webui.portal.UIPortalComposer;
 import org.exoplatform.portal.webui.util.PortalDataMapper;
 import org.exoplatform.portal.webui.util.Util;
@@ -41,16 +40,13 @@
 import org.exoplatform.portal.webui.workspace.UIPortalToolPanel;
 import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
 import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.config.InitParams;
-import org.exoplatform.webui.config.Param;
 import org.exoplatform.webui.config.annotation.ComponentConfig;
 import org.exoplatform.webui.config.annotation.ComponentConfigs;
 import org.exoplatform.webui.config.annotation.EventConfig;
 import org.exoplatform.webui.config.annotation.ParamConfig;
 import org.exoplatform.webui.core.UIComponent;
 import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
-import org.exoplatform.webui.core.model.SelectItemCategory;
 import org.exoplatform.webui.core.model.SelectItemOption;
 import org.exoplatform.webui.event.Event;
 import org.exoplatform.webui.event.EventListener;
@@ -355,7 +351,7 @@
             PortalDataMapper.toUIPage(uiPage, page);
          } catch(NoSuchDataException de){
             uiPortalApp.addMessage(new ApplicationMessage("UIPageForm.msg.notExistOrDeleted", null, ApplicationMessage.ERROR));
-            UIPortalComposer uiPortalComposer = (UIPortalComposer)uiPortalApp.findComponentById("UIPageEditor");
+            UIPortalComposer uiPortalComposer = (UIPortalComposer)uiPortalApp.findComponentById(UIPortalComposer.UIPAGE_EDITOR);
             if(uiPortalComposer != null){
                Event aboutEvent = new Event<UIPortalComposer>(uiPortalComposer, "Abort", event.getRequestContext());
                uiPortalComposer.broadcast(aboutEvent, event.getExecutionPhase());

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -274,7 +274,7 @@
             uiForm.setShowPublicationDate(false);
             uiForm.setFirstTime(false);
             UIPortal uiPortal = Util.getUIPortal();
-            uiPageNodeSelector.selectNavigation(uiPortal.getSelectedNavigation());
+            uiPageNodeSelector.selectNavigation(uiPortal.getNavigation());
             if (uiPortal.getSelectedNode() != null)
             {
                uiPageNodeSelector.selectPageNodeByUri(uiPortal.getSelectedNode().getUri());

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/PageNodeEvent.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/PageNodeEvent.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/PageNodeEvent.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -19,6 +19,8 @@
 
 package org.exoplatform.portal.webui.portal;
 
+import org.exoplatform.portal.config.model.PageNavigation;
+import org.exoplatform.portal.config.model.PageNode;
 import org.exoplatform.webui.core.UIComponent;
 import org.exoplatform.webui.event.Event;
 
@@ -27,19 +29,42 @@
  */
 public class PageNodeEvent<T extends UIComponent> extends Event<T>
 {
-
+   public static final String CHANGE_NODE = "ChangeNode";
+   
    final static public String CHANGE_PAGE_NODE = "ChangePageNode";
 
    private String targetNodeUri;
-
+   
+   private PageNavigation navi;
+   
+   private PageNode pageNode;
+   
    public PageNodeEvent(T source, String name, String targetNodeUri)
    {
       super(source, name, null);
       this.targetNodeUri = targetNodeUri;
    }
 
+   public PageNodeEvent(T source, String name, PageNavigation targetNavi, PageNode _pageNode)
+   {
+      super(source, name, null);
+      this.navi = targetNavi;
+      this.pageNode = _pageNode;
+      this.targetNodeUri = _pageNode.getUri();
+   }
+   
    public String getTargetNodeUri()
    {
       return targetNodeUri;
    }
+   
+   public PageNavigation getNavigation()
+   {
+      return navi;
+   }
+   
+   public PageNode getPageNode()
+   {
+      return pageNode;
+   }
 }
\ No newline at end of file

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortal.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -30,6 +30,7 @@
 import org.exoplatform.portal.webui.container.UIContainer;
 import org.exoplatform.portal.webui.page.UIPage;
 import org.exoplatform.portal.webui.page.UIPageBody;
+import org.exoplatform.portal.webui.page.UIPageActionListener.ChangeNodeActionListener;
 import org.exoplatform.portal.webui.page.UIPageActionListener.ChangePageNodeActionListener;
 import org.exoplatform.portal.webui.portal.UIPortalComponentActionListener.ChangeApplicationListActionListener;
 import org.exoplatform.portal.webui.portal.UIPortalComponentActionListener.ChangeLanguageActionListener;
@@ -68,6 +69,7 @@
 import javax.servlet.http.HttpServletRequest;
 
 @ComponentConfig(lifecycle = UIPortalLifecycle.class, template = "system:/groovy/portal/webui/portal/UIPortal.gtmpl", events = {
+   @EventConfig(listeners = ChangeNodeActionListener.class),
    @EventConfig(listeners = ChangePageNodeActionListener.class),
    @EventConfig(listeners = ChangeApplicationListActionListener.class),
    @EventConfig(listeners = MoveChildActionListener.class),
@@ -97,8 +99,6 @@
 
    private PageNavigation navigation;
    
-   private List<PageNode> selectedPath;
-
    private PageNode selectedNode_;
    
    private Map<String, UIPage> all_UIPages;
@@ -167,7 +167,13 @@
       publicParameters_ = publicParams;
    }
    
-   /** At the moment, this method ensure compatibility with legacy code */
+   /**
+    * @deprecated the list of navigation now is located in {@link UIPortalApplication} instead of {@link UIPortal}
+    * So using {@link UIPortalApplication#getNavigations()} instead
+    * 
+    * @return
+    * @throws Exception
+    */
    public List<PageNavigation> getNavigations() throws Exception
    {
       List<PageNavigation> listNavs = new ArrayList<PageNavigation>();
@@ -211,6 +217,11 @@
       this.navigation = _navigation;
    }
    
+   public PageNavigation getNavigation()
+   {
+      return navigation;
+   }
+   
    /**
     * Refresh the UIPage under UIPortal 
     * 
@@ -246,19 +257,6 @@
    {
       selectedNode_ = node;
    }
-
-   /*
-   public PageNode getSelectedNode() throws Exception
-   {
-      if (selectedNode_ != null)
-         return selectedNode_;
-      if (getSelectedNavigation() == null || selectedNavigation_.getNodes() == null
-         || selectedNavigation_.getNodes().size() < 1)
-         return null;
-      selectedNode_ = selectedNavigation_.getNodes().get(0);
-      return selectedNode_;
-   }
-   */
    
    public PageNode getSelectedNode() throws Exception
    {
@@ -275,22 +273,43 @@
 
    public List<PageNode> getSelectedPath()
    {
-      return selectedPath;
+      String[] pathNodes = selectedNode_.getUri().split("/");
+      PageNode tempNode = navigation.getNode(pathNodes[0]);
+      List<PageNode> nodes = new ArrayList<PageNode>(4);
+      nodes.add(tempNode);
+
+      for (int i = 1; i < pathNodes.length; i++)
+      {
+         tempNode = tempNode.getChild(pathNodes[i]);
+         if(tempNode == null)
+         {
+            break;
+         }
+         else
+         {
+            nodes.add(tempNode);
+         }
+      }
+      return nodes;
    }
 
+   /**
+    * @deprecated Do not use
+    * 
+    * @param nodes
+    */
    public void setSelectedPath(List<PageNode> nodes)
    {
-      selectedPath = nodes;
    }
    
-   public PageNavigation getSelectedNavigation() throws Exception
-   {
-      return navigation;
-   }
-   
+   /**
+    * @deprecated use {@link #setNavigation(PageNavigation)} instead
+    * 
+    * @param _navigation
+    */
    public void setSelectedNavigation(PageNavigation _navigation)
    {
-      this.navigation = _navigation;
+      setNavigation(_navigation);
    }
 
    /**

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalActionListener.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalActionListener.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalActionListener.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -54,6 +54,7 @@
       }
    }
 
+   //TODO This method seems not to be used
    static public class ChangeWindowStateActionListener extends EventListener<UIPortal>
    {
       public void execute(Event<UIPortal> event) throws Exception

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -66,16 +66,16 @@
 /** Created by The eXo Platform SAS Author : Pham Thanh Tung thanhtungty at gmail.com Jun 10, 2009 */
 @ComponentConfigs({
    @ComponentConfig(template = "app:/groovy/portal/webui/portal/UIPortalComposer.gtmpl", events = {
-      @EventConfig(listeners = UIPortalComposer.ViewPropertiesActionListener.class),
-      @EventConfig(listeners = UIPortalComposer.AbortActionListener.class),
-      @EventConfig(listeners = UIPortalComposer.FinishActionListener.class),
+      @EventConfig(name = "ViewProperties", listeners = UIPortalComposer.ViewSitePropertiesActionListener.class),
+      @EventConfig(name = "Abort", listeners = UIPortalComposer.AbortSiteEditionActionListener.class),
+      @EventConfig(name = "Finish", listeners = UIPortalComposer.FinishSiteEditionActionListener.class),
       @EventConfig(listeners = UIPortalComposer.SwitchModeActionListener.class),
       @EventConfig(listeners = UIPortalComposer.ChangeEdittedStateActionListener.class),
       @EventConfig(listeners = UIPortalComposer.ToggleActionListener.class)}),
-   @ComponentConfig(id = "UIPageEditor", template = "app:/groovy/portal/webui/portal/UIPortalComposer.gtmpl", events = {
-      @EventConfig(name = "ViewProperties", listeners = UIPortalComposer.ViewProperties2ActionListener.class),
-      @EventConfig(name = "Abort", listeners = UIPortalComposer.Abort2ActionListener.class),
-      @EventConfig(name = "Finish", listeners = UIPortalComposer.Finish2ActionListener.class),
+   @ComponentConfig(id = UIPortalComposer.UIPAGE_EDITOR, template = "app:/groovy/portal/webui/portal/UIPortalComposer.gtmpl", events = {
+      @EventConfig(name = "ViewProperties", listeners = UIPortalComposer.ViewPagePropertiesActionListener.class),
+      @EventConfig(name = "Abort", listeners = UIPortalComposer.AbortPageEditionActionListener.class),
+      @EventConfig(name = "Finish", listeners = UIPortalComposer.FinishPageEditionActionListener.class),
       @EventConfig(name = "Back", listeners = UIPortalComposer.BackActionListener.class),
       @EventConfig(listeners = UIPortalComposer.SwitchModeActionListener.class),
       @EventConfig(listeners = UIPortalComposer.ChangeEdittedStateActionListener.class),
@@ -83,7 +83,10 @@
    @ComponentConfig(id = "UIPortalComposerTab", type = UITabPane.class, template = "app:/groovy/portal/webui/portal/UIPortalComposerContent.gtmpl", events = {@EventConfig(listeners = UIPortalComposer.SelectTabActionListener.class)})})
 public class UIPortalComposer extends UIContainer
 {
-
+   final static public String UIPORTAL_COMPOSER = "UIPortalComposer";
+   
+   final static public String UIPAGE_EDITOR = "UIPageEditor";
+   
    private boolean isEditted = false;
 
    private boolean isCollapsed = false;
@@ -351,7 +354,7 @@
       super.processRender(context);
    }
 
-   static public class ViewPropertiesActionListener extends EventListener<UIPortalComposer>
+   static public class ViewSitePropertiesActionListener extends EventListener<UIPortalComposer>
    {
 
       public void execute(Event<UIPortalComposer> event) throws Exception
@@ -393,7 +396,7 @@
       }
    }
 
-   static public class AbortActionListener extends EventListener<UIPortalComposer>
+   static public class AbortSiteEditionActionListener extends EventListener<UIPortalComposer>
    {
       public void execute(Event<UIPortalComposer> event) throws Exception
       {
@@ -405,15 +408,14 @@
          uiEditWS.getComposer().setEditted(false);
          uiEditWS.setRendered(false);
          uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
-         prContext.setFullRender(true);
          UISiteBody siteBody = uiWorkingWS.findFirstComponentOfType(UISiteBody.class);
 
          UIPortal uiPortal = uiWorkingWS.getBackupUIPortal();
          siteBody.setUIComponent(uiPortal);
 
-         String uri = uiPortal.getSelectedNode() != null ? uiPortal.getSelectedNode().getUri() : null;
-         PageNodeEvent<UIPortal> pnevent = new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, uri);
-         uiPortal.broadcast(pnevent, Event.Phase.PROCESS);
+         uiPortal.refreshUIPage();
+         
+         prContext.setFullRender(true);
          prContext.addUIComponentToUpdateByAjax(uiWorkingWS);
          JavascriptManager jsManager = prContext.getJavascriptManager();
          jsManager.addJavascript("eXo.portal.portalMode=" + UIPortalApplication.NORMAL_MODE + ";");
@@ -427,7 +429,7 @@
     * @author <a href="trong.tran at exoplatform.com">Trong Tran</a>
     * @version $Revision$
     */
-   static public class FinishActionListener extends EventListener<UIPortalComposer>
+   static public class FinishSiteEditionActionListener extends EventListener<UIPortalComposer>
    {
 
       public void execute(Event<UIPortalComposer> event) throws Exception
@@ -464,8 +466,8 @@
          {
             DataStorage storage = uiPortalApp.getApplicationComponent(DataStorage.class);
             PortalConfig pConfig =
-               storage.getPortalConfig(uiPortal.getSelectedNavigation().getOwnerType(), uiPortal
-                  .getSelectedNavigation().getOwnerId());
+               storage.getPortalConfig(uiPortal.getNavigation().getOwnerType(), uiPortal
+                  .getNavigation().getOwnerId());
             if (pConfig != null)
             {
                uiPortalApp.getUserPortalConfig().setPortal(pConfig);
@@ -602,7 +604,7 @@
       }
    }
 
-   static public class ViewProperties2ActionListener extends EventListener<UIPortalComposer>
+   static public class ViewPagePropertiesActionListener extends EventListener<UIPortalComposer>
    {
       public void execute(Event<UIPortalComposer> event) throws Exception
       {
@@ -620,7 +622,7 @@
       }
    }
 
-   static public class Abort2ActionListener extends EventListener<UIPortalComposer>
+   static public class AbortPageEditionActionListener extends EventListener<UIPortalComposer>
    {
       public void execute(Event<UIPortalComposer> event) throws Exception
       {
@@ -631,7 +633,6 @@
          UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
          uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
          uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
-         Util.getPortalRequestContext().setFullRender(true);
 
          UIPortal uiPortal = uiPortalApp.getShowedUIPortal();
          uiPortal.setRenderSibling(UIPortal.class);
@@ -639,11 +640,10 @@
          composer.setEditted(false);
 
          uiPortal.refreshUIPage();
-         
-         PageNodeEvent<UIPortal> pnevent =
-            new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, (uiPortal.getSelectedNode() != null
-               ? uiPortal.getSelectedNode().getUri() : null));
-         uiPortal.broadcast(pnevent, Event.Phase.PROCESS);
+         PortalRequestContext pcontext = Util.getPortalRequestContext();
+         pcontext.setFullRender(true);
+         pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
+
          JavascriptManager jsManager = event.getRequestContext().getJavascriptManager();
          jsManager.addJavascript("eXo.portal.portalMode=" + UIPortalApplication.NORMAL_MODE + ";");
       }
@@ -655,7 +655,7 @@
     * @author <a href="trong.tran at exoplatform.com">Trong Tran</a>
     * @version $Revision$
     */
-   static public class Finish2ActionListener extends EventListener<UIPortalComposer>
+   static public class FinishPageEditionActionListener extends EventListener<UIPortalComposer>
    {
       public void execute(Event<UIPortalComposer> event) throws Exception
       {
@@ -673,14 +673,15 @@
             uiWorkingWS.getApplicationComponent(UserPortalConfigService.class);
          
          /*
-          * if it is a edition of the current page
+          * if it is a edition of the current page and it is not available to current remote user anymore.
           */
+         PortalRequestContext pContext = Util.getPortalRequestContext();
          if (page.getStorageId() != null && portalConfigService.getPage(pageId) == null)
          {
             uiPortalApp.addMessage(new ApplicationMessage("UIPageBrowser.msg.PageNotExist", new String[]{pageId}, 1));
             uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
             uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
-            Util.getPortalRequestContext().setFullRender(true);
+            pContext.setFullRender(true);
             PageNodeEvent<UIPortal> pnevent =
                new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE,
                   (uiPortal.getSelectedNode() != null ? uiPortal.getSelectedNode().getUri() : null));
@@ -737,7 +738,7 @@
          }
          uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
          uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
-         Util.getPortalRequestContext().setFullRender(true);
+         pContext.setFullRender(true);
          PageNodeEvent<UIPortal> pnevent =
             new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, (uiPortal.getSelectedNode() != null
                ? uiPortal.getSelectedNode().getUri() : null));

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/util/Util.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/util/Util.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/util/Util.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -19,11 +19,12 @@
 
 package org.exoplatform.portal.webui.util;
 
+import org.exoplatform.container.ExoContainer;
 import org.exoplatform.portal.application.PortalRequestContext;
 import org.exoplatform.portal.config.UserPortalConfigService;
 import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.model.PageNavigation;
 import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.webui.application.UIPortlet;
 import org.exoplatform.portal.webui.container.UIContainer;
 import org.exoplatform.portal.webui.page.UIDesktopPage;
 import org.exoplatform.portal.webui.page.UIPage;
@@ -38,6 +39,7 @@
 import org.exoplatform.webui.core.UIComponentDecorator;
 import org.exoplatform.webui.event.Event;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -45,6 +47,144 @@
  */
 public class Util
 {
+   /**
+    * Split given <code>path</code> into an array of valid node's names.
+    * The node names in the <code>path</code> parameter are separated by the "/" forward slash.
+    * An empty node name is not accepted and will be ignored
+    * <p> For examples:</p>
+    * <table cellpadding=1 cellspacing=0>
+    *    <tr>
+    *       <th>Path</th>
+    *       <th>Result</th>
+    *    </tr>
+    *    <tr>
+    *       <td align=center>administration/registry</td>
+    *       <td><tt>{ "administration", "registry" }</tt></td>
+    *    </tr>
+    *    <tr>
+    *       <td align=center>/administration/registry/</td>
+    *       <td><tt>{ "administration", "registry" }</tt></td>
+    *    </tr>
+    *    <tr>
+    *       <td align=center>/administration//registry</td>
+    *       <td><tt>{ "administration", "registry" }</tt></td>
+    *    </tr>
+    * </table>
+    * <p/>
+    * @param path
+    * @return
+    */
+   static private String[] splitPath(String path)
+   {
+      String[] split = path.split("/", 0);
+      List<String> nodeNames = new ArrayList<String>();
+
+      for (String name : split)
+      {
+         if (name.trim().length() > 0)
+         {
+            nodeNames.add(name);
+         }
+      }
+      return nodeNames.toArray(new String[nodeNames.size()]);
+   }
+
+
+   /**
+    * Return the first available child node from the <code>nav</code> parameter
+    * that the current remote user can view its page.
+    * <p/>
+    * If there is not any an available node in the <code>nav</code> navigation.
+    * The method will returns the "notfound"node if it's existing, otherwise is the <code>null</code> value 
+    * 
+    * @param nav
+    * @return
+    * @throws Exception 
+    */
+   static public PageNode findFirstAvailableNode(PageNavigation nav, PortalRequestContext context) throws Exception
+   {
+      PageNode node = null;
+      if (nav != null && nav.getNodes().size() > 0)
+      {
+         ExoContainer appContainer = context.getApplication().getApplicationServiceContainer();
+         UserPortalConfigService userPortalConfigService =
+            (UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
+
+         for (PageNode pageNode : nav.getNodes())
+         {
+            Page page = userPortalConfigService.getPage(pageNode.getPageReference(), context.getRemoteUser());
+            if (page != null)
+            {
+               node = pageNode;
+               if (!"notfound".equals(node.getName()))
+                  break;
+            }
+         }
+      }
+      else
+      {
+         return null;
+      }
+      return node;
+   }
+   
+   static public Object[] findBestMatchNavigationAndNode(List<PageNavigation> navigations, String nodePath_)
+   {
+      PageNavigation targetNav = null;
+      PageNode targetNode = null;
+      
+      if (nodePath_.length() > 0)
+      {
+         String[] pathNodes = splitPath(nodePath_);
+         if (pathNodes.length > 0)
+         {
+            int lastDeepMatchNumber = 0;
+
+            for (PageNavigation nav : navigations)
+            {
+               int deepMatchNumber = 0;
+               PageNode currentNode = nav.getNode(pathNodes[deepMatchNumber++]);
+               if (currentNode == null) {
+                  continue;
+               }
+               while (deepMatchNumber < pathNodes.length)
+               {
+                  PageNode tempNode = currentNode.getChild(pathNodes[deepMatchNumber]);
+                  if (tempNode == null)
+                  {
+                     break;
+                  }
+                  ++deepMatchNumber;
+                  currentNode = tempNode;
+               }
+
+               //The whole pathNodes matches current navigation
+               if (deepMatchNumber == pathNodes.length)
+               {
+                  targetNav = nav;
+                  targetNode = currentNode;
+                  break;
+               }
+
+               if (deepMatchNumber > lastDeepMatchNumber)
+               {
+                  lastDeepMatchNumber = deepMatchNumber;
+                  targetNav = nav;
+                  targetNode = currentNode;
+               }
+            }
+         }
+      }
+      Object[] results = null;
+      if(targetNav != null)
+      {
+         results = new Object[2];
+         results[0] = targetNav;
+         results[1] = targetNode;
+      }
+      return results;
+   }
+   
    static public PortalRequestContext getPortalRequestContext()
    {
       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
@@ -121,56 +261,6 @@
       return uiWork;
    }
 
-   static public void showPortalComponentLayoutMode(UIPortalApplication uiPortalApp)
-   {
-      UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
-      uiWorkingWS.setRenderedChild(UIPortal.class);
-      UIPortal uiPortal = uiWorkingWS.findFirstComponentOfType(UIPortal.class);
-
-      UIContainer uiContainer = Util.findUIComponent(uiPortal, UIContainer.class, UIPage.class);
-      UIPage uiPage = uiPortal.findFirstComponentOfType(UIPage.class);
-      UIPortlet uiPortlet = Util.findUIComponent(uiPortal, UIPortlet.class, UIPage.class);
-
-      String name = "";
-      if (uiContainer != null && uiContainer.isShowEditControl())
-         name = "'UIContainer'";
-      else if (uiPage != null && uiPage.isShowEditControl())
-         name = "'UIPage'";
-      else if (uiPortlet != null && uiPortlet.isShowEditControl())
-         name = "'UIPortlet'";
-
-      getPortalRequestContext().getJavascriptManager().addCustomizedOnLoadScript(
-         "eXo.portal.UIPortal.showLayoutModeForPortal(" + name + ");");
-   }
-
-   //  public UIPortlet getFirstUIPortlet(UIContainer uiContainer){
-   //    return 
-   //  }
-
-   //  public UIContainer getFirstUIContainer(){
-   //    return (UIContainer)Util.findUIComponent(UIContainer uiContainer, UIContainer.class, UIPage.class);
-   //  }
-
-   static public void showPageComponentLayoutMode(UIPortalApplication uiPortalApp)
-   {
-      UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
-      uiWorkingWS.setRenderedChild(UIPortalToolPanel.class);
-      UIPortalToolPanel uiPortalToolPanel = uiWorkingWS.findFirstComponentOfType(UIPortalToolPanel.class);
-
-      UIPage uiPage = uiPortalToolPanel.findFirstComponentOfType(UIPage.class);
-      UIContainer uiContainer = uiPage.findFirstComponentOfType(UIContainer.class);
-      UIPortlet uiPortlet = uiPage.findFirstComponentOfType(UIPortlet.class);
-
-      String name = "";
-      if (uiContainer != null && uiContainer.isShowEditControl())
-         name = "UIContainer";
-      else if (uiPortlet != null && uiPortlet.isShowEditControl())
-         name = "UIPortlet";
-
-      getPortalRequestContext().getJavascriptManager().addCustomizedOnLoadScript(
-         "eXo.portal.UIPortal.showLayoutModeForPage('" + name + "');");
-   }
-
    @SuppressWarnings("unchecked")
    static public <T extends UIComponent> T findUIComponent(UIComponent uiComponent, Class<T> clazz, Class ignoreClazz)
    {

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIMainActionListener.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -77,8 +77,8 @@
 
          UIPortalComposer portalComposer =
             uiWorkingWS.findFirstComponentOfType(UIPortalComposer.class).setRendered(true);
-         portalComposer.setComponentConfig(UIPortalComposer.class, "UIPageEditor");
-         portalComposer.setId("UIPageEditor");
+         portalComposer.setComponentConfig(UIPortalComposer.class, UIPortalComposer.UIPAGE_EDITOR);
+         portalComposer.setId(UIPortalComposer.UIPAGE_EDITOR);
          portalComposer.setShowControl(true);
          portalComposer.setEditted(false);
          portalComposer.setCollapse(false);
@@ -119,8 +119,8 @@
 
          UIPortalComposer portalComposer = uiWorkingWS.findFirstComponentOfType(UIPortalComposer.class);
          portalComposer.setRendered(false);
-         portalComposer.setComponentConfig(UIPortalComposer.class, "UIPageEditor");
-         portalComposer.setId("UIPageEditor");
+         portalComposer.setComponentConfig(UIPortalComposer.class, UIPortalComposer.UIPAGE_EDITOR);
+         portalComposer.setId(UIPortalComposer.UIPAGE_EDITOR);
          portalComposer.setShowControl(true);
          portalComposer.setEditted(true);
          portalComposer.setCollapse(false);
@@ -138,7 +138,7 @@
       {
          UIPortal currentPortal = Util.getUIPortal();
          UserACL userACL = Util.getUIPortalApplication().getApplicationComponent(UserACL.class);
-         PageNavigation selectedNavigation = currentPortal.getSelectedNavigation();
+         PageNavigation selectedNavigation = currentPortal.getNavigation();
          if (PortalConfig.PORTAL_TYPE.equals(selectedNavigation.getOwnerType()))
          {
             return userACL.hasEditPermissionOnPortal(currentPortal.getOwnerType(), currentPortal.getOwner(), currentPortal.getEditPermission());
@@ -184,8 +184,7 @@
          UIPortal newPortal = uiWorkingWS.createUIComponent(UIPortal.class, null, null);
          PortalDataMapper.toUIPortal(newPortal, userConfig);
          newPortal.setSelectedNode(uiPortal.getSelectedNode());
-         newPortal.setSelectedNavigation(uiPortal.getSelectedNavigation());
-         newPortal.setSelectedPath(uiPortal.getSelectedPath());
+         newPortal.setNavigation(uiPortal.getNavigation());
          newPortal.refreshUIPage();
 
          UIEditInlineWorkspace uiEditWS = uiWorkingWS.getChild(UIEditInlineWorkspace.class);
@@ -198,7 +197,7 @@
          uiComposer.setShowControl(true);
          uiComposer.setEditted(false);
          uiComposer.setCollapse(false);
-         uiComposer.setId("UIPortalComposer");
+         uiComposer.setId(UIPortalComposer.UIPORTAL_COMPOSER);
 
          uiWorkingWS.setRenderedChild(UIEditInlineWorkspace.class);
          pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);

Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java	2010-08-19 08:18:22 UTC (rev 3867)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java	2010-08-19 09:17:49 UTC (rev 3868)
@@ -36,8 +36,8 @@
 import org.exoplatform.portal.resource.SkinURL;
 import org.exoplatform.portal.webui.application.UIPortlet;
 import org.exoplatform.portal.webui.navigation.PageNavigationUtils;
+import org.exoplatform.portal.webui.page.UIPageActionListener.ChangeNodeActionListener;
 import org.exoplatform.portal.webui.page.UISiteBody;
-import org.exoplatform.portal.webui.portal.PageNodeEvent;
 import org.exoplatform.portal.webui.portal.UIPortal;
 import org.exoplatform.portal.webui.util.PortalDataMapper;
 import org.exoplatform.portal.webui.util.Util;
@@ -52,11 +52,11 @@
 import org.exoplatform.web.application.javascript.JavascriptConfigService;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.config.annotation.EventConfig;
 import org.exoplatform.webui.core.UIApplication;
 import org.exoplatform.webui.core.UIComponent;
 import org.exoplatform.webui.core.UIComponentDecorator;
 import org.exoplatform.webui.core.UIContainer;
-import org.exoplatform.webui.event.Event;
 
 import java.io.Writer;
 import java.util.ArrayList;
@@ -68,7 +68,6 @@
 import java.util.Map;
 import java.util.Set;
 
-
 /**
  * This extends the UIApplication and hence is a sibling of UIPortletApplication
  * (used by any eXo Portlets as the Parent class to build the portlet component
@@ -78,7 +77,8 @@
  * display the normal or webos portal layouts - UIPopupWindow: a popup window
  * that display or not
  */
- at ComponentConfig(lifecycle = UIPortalApplicationLifecycle.class, template = "system:/groovy/portal/webui/workspace/UIPortalApplication.gtmpl")
+ at ComponentConfig(lifecycle = UIPortalApplicationLifecycle.class, template = "system:/groovy/portal/webui/workspace/UIPortalApplication.gtmpl", events = {
+      @EventConfig(listeners = ChangeNodeActionListener.class)})
 public class UIPortalApplication extends UIApplication
 {
    public static final int NORMAL_MODE = 0;
@@ -93,7 +93,7 @@
 
    private int modeState = NORMAL_MODE;
 
-   private String nodePath_;
+   private String lastNodePath;
 
    private Orientation orientation_ = Orientation.LT;
 
@@ -326,6 +326,16 @@
       return (modeState != NORMAL_MODE);
    }
 
+   public String getLastNodePath()
+   {
+      return lastNodePath;
+   }
+
+   public void setLastNodePath(String lastNodePath)
+   {
+      this.lastNodePath = lastNodePath;
+   }
+   
    public Collection<String> getJavascriptURLs()
    {
       JavascriptConfigService service = getApplicationComponent(JavascriptConfigService.class);
@@ -512,30 +522,6 @@
    }
 
    /**
-    * The processDecode() method is doing 3 actions: 
-    * 1) if the nodePath is null (case of the first request) a call to 
-    * super.processDecode(context) is made and we end the method here 
-    * 2) if the nodePath exist but is equals to the current one 
-    * then we also call super and stops here 
-    * 3) if the requested nodePath is not equals to the current one or current 
-    * page no longer exists, then an event of type PageNodeEvent.CHANGE_PAGE_NODE 
-    * is sent to the associated EventListener; a call to super is then done
-    */
-   public void processDecode(WebuiRequestContext context) throws Exception
-   {
-      PortalRequestContext pcontext = (PortalRequestContext)context;
-      String nodePath = pcontext.getNodePath().trim();
-      
-      if (!nodePath.equals(nodePath_) || !isPageExist())
-      {
-         nodePath_ = nodePath;
-         PageNodeEvent<UIPortal> pnevent = new PageNodeEvent<UIPortal>(showedUIPortal, PageNodeEvent.CHANGE_PAGE_NODE, nodePath_);
-         showedUIPortal.broadcast(pnevent, Event.Phase.PROCESS);
-      }
-      super.processDecode(context);
-   }
-
-   /**
     * The processrender() method handles the creation of the returned HTML
     * either for a full page render or in the case of an AJAX call The first
     * request, Ajax is not enabled (means no ajaxRequest parameter in the



More information about the gatein-commits mailing list