[gatein-commits] gatein SVN: r5276 - in exo/portal/branches/standalone: component/portal/src/main/java/org/exoplatform/portal/pom/config and 7 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 25 12:08:48 EST 2010


Author: phuong_vu
Date: 2010-11-25 12:08:47 -0500 (Thu, 25 Nov 2010)
New Revision: 5276

Added:
   exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/standalone-webui-configuration.xml
   exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneAppContainer.gtmpl
   exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneGadget.gtmpl
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestContext.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestHandler.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppStateManager.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneApplication.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneAppContainer.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneGadget.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplication.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplicationLifecycle.java
Modified:
   exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
   exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
   exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
   exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
   exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java
   exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/web.xml
   exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
   exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalController.java
   exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
Log:
EXOGTN-171 Support the portal standalone mode to show an application (gadget for now) standalone

Modified: exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
===================================================================
--- exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -19,21 +19,23 @@
 
 package org.exoplatform.portal.config;
 
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
 import org.exoplatform.commons.utils.LazyPageList;
 import org.exoplatform.commons.utils.ListAccess;
 import org.exoplatform.portal.application.PortletPreferences;
+import org.exoplatform.portal.config.model.Application;
 import org.exoplatform.portal.config.model.ApplicationState;
 import org.exoplatform.portal.config.model.ApplicationType;
 import org.exoplatform.portal.config.model.Container;
 import org.exoplatform.portal.config.model.Dashboard;
-import org.exoplatform.portal.pom.data.ModelChange;
 import org.exoplatform.portal.config.model.Page;
 import org.exoplatform.portal.config.model.PageNavigation;
 import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.pom.data.ModelChange;
 
-import java.util.Comparator;
-import java.util.List;
-
 /**
  * Created by The eXo Platform SAS
  * Apr 19, 2007
@@ -144,4 +146,15 @@
     * @throws Exception any exception
     */
    public List<String> getAllPortalNames() throws Exception;
+   
+   /**
+    * Returns info on site holding workspace object specified by applicationStorageId
+    * 
+    * @param applicationStorageId
+    * @return
+    * @throws Exception
+    */
+   public Map<String, String> getSiteInfo(String applicationStorageId) throws Exception;
+   
+   public <S> Application<S> getApplicationModel(String applicationStorageId) throws Exception;
 }
\ No newline at end of file

Modified: exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
===================================================================
--- exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -18,9 +18,18 @@
  */
 package org.exoplatform.portal.config;
 
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
 import org.exoplatform.commons.utils.LazyPageList;
 import org.exoplatform.commons.utils.ListAccess;
 import org.exoplatform.portal.application.PortletPreferences;
+import org.exoplatform.portal.config.model.Application;
 import org.exoplatform.portal.config.model.ApplicationState;
 import org.exoplatform.portal.config.model.ApplicationType;
 import org.exoplatform.portal.config.model.Container;
@@ -29,6 +38,7 @@
 import org.exoplatform.portal.config.model.Page;
 import org.exoplatform.portal.config.model.PageNavigation;
 import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.pom.data.ApplicationData;
 import org.exoplatform.portal.pom.data.DashboardData;
 import org.exoplatform.portal.pom.data.ModelChange;
 import org.exoplatform.portal.pom.data.ModelData;
@@ -41,9 +51,6 @@
 import org.exoplatform.portal.pom.data.PortalKey;
 import org.exoplatform.services.listener.ListenerService;
 
-import java.lang.reflect.Array;
-import java.util.*;
-
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -52,7 +59,7 @@
 {
    /** . */
    private ModelDataStorage delegate;
-   
+
    private ListenerService listenerServ_ ;
 
    public DataStorageImpl(ModelDataStorage delegate, ListenerService listenerServ)
@@ -85,7 +92,7 @@
       delegate.save(config.build());
       listenerServ_.broadcast(PORTAL_CONFIG_UPDATED, this, config);
    }
-   
+
    public void remove(PortalConfig config) throws Exception
    {
       delegate.remove(config.build());
@@ -104,7 +111,7 @@
       listenerServ_.broadcast(PAGE_UPDATED, this, page);
       return changes;
    }
-   
+
    public void remove(Page page) throws Exception
    {
       delegate.remove(page.build());
@@ -174,7 +181,7 @@
       final Query<O> q;
 
       final Class<D> dataType;
-      
+
       final Comparator<O> cp;
 
       Bilto(Query<O> q, Class<D> dataType)
@@ -183,7 +190,7 @@
          this.dataType = dataType;
          this.cp = null;
       }
-      
+
       Bilto(Query<O> q, Class<D> dataType, Comparator<O> cp)
       {
          this.q = q;
@@ -217,9 +224,9 @@
                return pages;
             }
          };
-      }      
-      
+      }
 
+
       private List<D> sort(List<D> list, final Comparator<O> comparator) {
          List<D> tmpList = new ArrayList<D>();
          for (int i=0; i<list.size();i++) {
@@ -235,9 +242,9 @@
                O o2 = create(d2);
                return comparator.compare(o1, o2);
             }
-            
+
          });
-         return tmpList;         
+         return tmpList;
       }
    }
 
@@ -340,4 +347,24 @@
    {
       delegate.saveDashboard(dashboard.build());
    }
+
+	public Map<String, String> getSiteInfo(String applicationStorageId)
+			throws Exception {
+		// TODO Auto-generated method stub
+		return delegate.getSiteInfo(applicationStorageId);
+	}
+
+	public <S> Application<S> getApplicationModel(String applicationStorageId)
+			throws Exception {
+		// TODO Auto-generated method stub
+		try {
+			ApplicationData<S> applicationData = delegate
+					.getApplicationData(applicationStorageId);
+			return new Application<S>(applicationData);
+		} catch (NoSuchDataException ex)
+	   {
+		   //TODO: Throw something else
+		   throw ex;
+	   }
+	}
 }

Modified: exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
===================================================================
--- exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -19,10 +19,18 @@
 
 package org.exoplatform.portal.pom.config;
 
+import java.io.ByteArrayInputStream;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
 import org.exoplatform.commons.utils.IOUtil;
 import org.exoplatform.commons.utils.LazyPageList;
 import org.exoplatform.container.configuration.ConfigurationManager;
 import org.exoplatform.portal.application.PortletPreferences;
+import org.exoplatform.portal.config.NoSuchDataException;
 import org.exoplatform.portal.config.Query;
 import org.exoplatform.portal.config.model.Application;
 import org.exoplatform.portal.config.model.ApplicationState;
@@ -39,7 +47,9 @@
 import org.exoplatform.portal.pom.config.tasks.PortletPreferencesTask;
 import org.exoplatform.portal.pom.config.tasks.PreferencesTask;
 import org.exoplatform.portal.pom.config.tasks.SearchTask;
+import org.exoplatform.portal.pom.data.ApplicationData;
 import org.exoplatform.portal.pom.data.DashboardData;
+import org.exoplatform.portal.pom.data.Mapper;
 import org.exoplatform.portal.pom.data.ModelChange;
 import org.exoplatform.portal.pom.data.ModelDataStorage;
 import org.exoplatform.portal.pom.data.NavigationData;
@@ -48,16 +58,15 @@
 import org.exoplatform.portal.pom.data.PageKey;
 import org.exoplatform.portal.pom.data.PortalData;
 import org.exoplatform.portal.pom.data.PortalKey;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.api.workspace.WorkspaceObject;
+import org.gatein.mop.api.workspace.ui.UIComponent;
+import org.gatein.mop.api.workspace.ui.UIWindow;
 import org.jibx.runtime.BindingDirectory;
 import org.jibx.runtime.IBindingFactory;
-import org.jibx.runtime.IUnmarshallingContext;
 import org.jibx.runtime.impl.UnmarshallingContext;
 
-import java.io.ByteArrayInputStream;
-import java.util.Comparator;
-import java.util.List;
-import java.util.UUID;
-
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -313,4 +322,60 @@
          }
       });
    }
+   
+   @Override
+	public Map<String, String> getSiteInfo(String workspaceObjectId)
+			throws Exception {
+	
+	   POMSession session = pomMgr.getSession();
+	   
+	   WorkspaceObject workspaceObject = session.findObjectById(workspaceObjectId);
+	   
+	   if(workspaceObject instanceof UIComponent)
+	   {
+		   Site site = ((UIComponent)workspaceObject).getPage().getSite();
+		   ObjectType<? extends Site> siteType = site.getObjectType();
+		   
+		   Map<String, String> returnedMap = new HashMap<String, String>();
+		   
+		   //Put the siteType on returned map
+		   if(siteType == ObjectType.PORTAL_SITE)
+		   {
+			   returnedMap.put("siteType", "portal");
+		   }
+		   else if(siteType == ObjectType.GROUP_SITE)
+		   {
+			   returnedMap.put("siteType", "group");
+		   }else if(siteType == ObjectType.USER_SITE)
+		   {
+			   returnedMap.put("siteType", "user");
+		   }
+		   
+		   //Put the siteOwner on returned map
+		   returnedMap.put("siteOwner", site.getName());
+		   
+		   return returnedMap;
+	   }
+	   
+	   throw new Exception("The provided ID is not associated with an application");
+	}
+   
+   @Override
+	public <S> ApplicationData<S> getApplicationData(String applicationStorageId)
+			throws Exception {
+		// TODO Auto-generated method stub
+	   
+	   POMSession session = pomMgr.getSession();
+	   WorkspaceObject workspaceObject = session.findObjectById(applicationStorageId);
+	   
+	   if(workspaceObject instanceof UIWindow)
+	   {
+		   UIWindow application = (UIWindow)workspaceObject;
+		   Mapper mapper = new Mapper(session);
+		   
+		   ApplicationData data = mapper.load(application);
+		   return data;
+	   }
+	   throw new NoSuchDataException("Could not load the application data specified by the ID: " + applicationStorageId);
+	}
 }

Modified: exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
===================================================================
--- exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -915,7 +915,7 @@
       }
    }
 
-   private <S> ApplicationData<S> load(UIWindow src)
+   public <S> ApplicationData<S> load(UIWindow src)
    {
       Attributes attrs = src.getAttributes();
 

Modified: exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java
===================================================================
--- exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -19,19 +19,17 @@
 
 package org.exoplatform.portal.pom.data;
 
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
 import org.exoplatform.commons.utils.LazyPageList;
 import org.exoplatform.portal.application.PortletPreferences;
 import org.exoplatform.portal.config.Query;
 import org.exoplatform.portal.config.model.ApplicationState;
 import org.exoplatform.portal.config.model.ApplicationType;
 import org.exoplatform.portal.config.model.Container;
-import org.exoplatform.portal.pom.data.ModelChange;
-import org.exoplatform.portal.pom.data.PageData;
-import org.exoplatform.portal.pom.data.PortalData;
 
-import java.util.Comparator;
-import java.util.List;
-
 /**
  * Created by The eXo Platform SAS
  * Apr 19, 2007
@@ -109,4 +107,9 @@
    public void saveDashboard(DashboardData dashboard) throws Exception;
 
    public void save() throws Exception;
+   
+   public Map<String, String> getSiteInfo(String workspaceObjectId) throws Exception;
+   
+   public <S> ApplicationData<S> getApplicationData(String applicationStorageId) throws Exception;
+   
 }
\ No newline at end of file

Added: exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/standalone-webui-configuration.xml
===================================================================
--- exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/standalone-webui-configuration.xml	                        (rev 0)
+++ exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/standalone-webui-configuration.xml	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,55 @@
+<!--
+
+    Copyright (C) 2009 eXo Platform SAS.
+    
+    This is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Lesser General Public License as
+    published by the Free Software Foundation; either version 2.1 of
+    the License, or (at your option) any later version.
+    
+    This software is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+    Lesser General Public License for more details.
+    
+    You should have received a copy of the GNU Lesser General Public
+    License along with this software; if not, write to the Free
+    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+    02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+
+<webui-configuration>  
+  <application>     
+    <init-params>
+      <param>
+        <name>application.resource.bundle</name>
+        <value>locale.portal.expression, locale.portal.services, locale.portal.webui</value>
+      </param>
+    </init-params>
+
+    <ui-component-root>org.exoplatform.portal.webui.workspace.UIStandaloneApplication</ui-component-root>    
+    <state-manager>org.exoplatform.portal.application.StandaloneAppStateManager</state-manager>
+
+    <application-lifecycle-listeners>       
+      <listener>org.exoplatform.portal.application.UserSiteLifeCycle</listener>
+      <!--<listener>org.exoplatform.portal.application.PortalStatisticLifecycle</listener>-->
+      <listener>org.exoplatform.portal.application.PortalApplicationLifecycle</listener>
+      <listener>org.exoplatform.webui.application.MonitorApplicationLifecycle</listener>
+      <listener>org.exoplatform.portal.application.UserProfileLifecycle</listener>
+      <listener>org.exoplatform.portal.application.concurrent.PortalConcurrencyMonitorLifecycle</listener>
+    </application-lifecycle-listeners>
+
+    <events>
+      <event>
+        <event-name>portal.application.lifecycle.event</event-name>
+        <listener>org.exoplatform.webui.event.ConsoleEventMonitorListener</listener>
+      </event>
+
+      <event>
+        <event-name>portal.execution.lifecycle.event</event-name>
+        <listener>org.exoplatform.webui.event.ConsoleEventMonitorListener</listener>
+      </event>
+    </events>
+  </application>
+</webui-configuration>

Modified: exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/web.xml	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/web/portal/src/main/webapp/WEB-INF/web.xml	2010-11-25 17:08:47 UTC (rev 5276)
@@ -186,6 +186,10 @@
 	  	<param-name>webui.configuration</param-name> 
 	  	<param-value>app:/WEB-INF/webui-configuration.xml</param-value> 
 	  </init-param>
+    <init-param>
+      <param-name>standalone.webui.configuration</param-name>
+      <param-value>app:/WEB-INF/standalone-webui-configuration.xml</param-value>
+    </init-param>
 	  <load-on-startup>1</load-on-startup> 
 	</servlet>
  
@@ -281,7 +285,10 @@
     <servlet-name>GateInServlet</servlet-name>
     <url-pattern>/gateinservlet</url-pattern>
   </servlet-mapping>
-
+  <servlet-mapping>
+    <servlet-name>portal</servlet-name>
+    <url-pattern>/StandaloneApplication/*</url-pattern> 
+  </servlet-mapping>
 	<session-config>
 	  <session-timeout>30</session-timeout> 
 	</session-config>
@@ -320,6 +327,20 @@
 		  <transport-guarantee>NONE</transport-guarantee> 
 	  </user-data-constraint>
 	</security-constraint>
+  <security-constraint>
+		<web-resource-collection>
+	  	<web-resource-name>user authentication</web-resource-name>
+	  	<url-pattern>/StandaloneApplication/*</url-pattern> 
+	  	<http-method>POST</http-method>
+	  	<http-method>GET</http-method>
+	  </web-resource-collection>
+		<auth-constraint>
+	  	<role-name>users</role-name>
+	  </auth-constraint>
+		<user-data-constraint>
+	  	<transport-guarantee>NONE</transport-guarantee>
+	  </user-data-constraint>
+	</security-constraint>
 	<login-config>
 	  <auth-method>FORM</auth-method> 
 	  <realm-name>gatein-domain</realm-name> 

Modified: exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
===================================================================
--- exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl	2010-11-25 17:08:47 UTC (rev 5276)
@@ -1,8 +1,16 @@
-<%	
+<%
 	import org.exoplatform.web.application.JavascriptManager;
 	import org.exoplatform.portal.webui.application.GadgetUtil;
+	import org.exoplatform.portal.application.PortalRequestContext;
+	import javax.servlet.http.HttpSession;
+	import org.exoplatform.portal.config.model.PersistentApplicationState;
+	import org.exoplatform.portal.pom.spi.gadget.Gadget;
+	import javax.portlet.PortletRequest;
+	import javax.portlet.PortletResponse;
 	
 	def rcontext = _ctx.getRequestContext();
+	def portalRC = rcontext.getParentAppRequestContext();
+	HttpSession httpSession = portalRC.getRequest().getSession(true);	
 	JavascriptManager jsmanager = rcontext.getJavascriptManager();
 	def hostName = GadgetUtil.getRelGadgetServerUrl();
 	def url = uicomponent.getUrl();
@@ -26,8 +34,19 @@
 	String unminiTitle = _ctx.appRes("UIGadget.tooltip.Unminimize");
 	String maxiTitle = _ctx.appRes("UIGadget.tooltip.Maximize");
 	String unmaxiTitle = _ctx.appRes("UIGadget.tooltip.Unmaximize");
+		
+	def portletRequest = rcontext.getRequest();
+	def scheme = portletRequest.getScheme();
+	def serverName = portletRequest.getServerName();
+	def port = portletRequest.getServerPort();
+	def standaloneURL = scheme + "://" + serverName + ":" + port + rcontext.getPortalContextPath();
+	standaloneURL += "/StandaloneApplication/" + uicomponent.getStorageId();
+
+	def portletResponse = rcontext.getResponse();
+	standaloneURL = portletResponse.encodeURL(standaloneURL);
 %>
 <div class="UIGadget" id="$id" style="left: $posX; top: $posY; z-Index: $zIndex; width: 100%" >
+	<a style="display:none" href="$standaloneURL"></a>
 	<div class="GadgetControl" style="visibility: visible;">
 		<div class="LeftControlBar">
 			<div class="RightControlBar">
@@ -67,4 +86,4 @@
 		</div>
 	</div>
 	<div class="UIMask" style="display: none; border:solid 1px red"><span></span></div>
-</div>
\ No newline at end of file
+</div>

Added: exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneAppContainer.gtmpl
===================================================================
--- exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneAppContainer.gtmpl	                        (rev 0)
+++ exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneAppContainer.gtmpl	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,14 @@
+<div class="UIStandaloneAppContainer" id="<%=uicomponent.getId()%>">
+<%
+	if (uicomponent.isLossData())	{
+		print("Can not render this gadget</div>");
+		return;
+	}
+	if (uicomponent.currApp != null)	 {
+		uicomponent.renderChild(uicomponent.currApp);
+	} else {
+%>
+	<div class="Icon">Not have permission</div>
+	<div class="Icon"><a href="<%=uicomponent.url("Logout")%>">Login with other UserName</a> </div>
+<% 	} %>
+</div>

Added: exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneGadget.gtmpl
===================================================================
--- exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneGadget.gtmpl	                        (rev 0)
+++ exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/application/UIStandaloneGadget.gtmpl	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,27 @@
+<%	
+	import org.exoplatform.web.application.JavascriptManager;
+	import org.exoplatform.portal.webui.application.GadgetUtil;
+	def rcontext = _ctx.getRequestContext();
+	JavascriptManager jsmanager = rcontext.getJavascriptManager();
+	def hostName = GadgetUtil.getRelGadgetServerUrl();
+	def url = uicomponent.getUrl();
+	def metadata = uicomponent.getMetadata();
+	def posX = uicomponent.getProperties().getIntValue("locationX") + "px";
+	def posY = uicomponent.getProperties().getIntValue("locationY") + "px";
+	def zIndex = uicomponent.getProperties().getIntValue("zIndex");
+	def id = uicomponent.getId();
+	def isDev = uicomponent.isGadgetDeveloper();
+	def noCache = uicomponent.isNoCache();
+	def isDebug = uicomponent.isDebug();
+	def view = uicomponent.getView();
+	def userPref = uicomponent.getUserPref();
+	jsmanager.importJavascript("eXo.gadget.UIGadget");
+	jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.createGadget('$url','content-$id', $metadata, $userPref, '$view', '$hostName', " + (isDev ? 1 : 0)
+																																						+ ", " + (isDebug ? 1 : 0) + ", " + (noCache ? 1 : 0) + ");");																																						
+%>
+<div class="UIGadget" id="$id" style="left: $posX; top: $posY; z-Index: $zIndex; width: 100%" >
+	<div class="GadgetControl" style="visibility: visible; ">		
+	</div>
+ 	<div id="content-$id"></div>
+	<div class="UIMask" style="display: none; border:solid 1px red"><span></span></div>
+</div>

Modified: exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl
===================================================================
--- exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl	2010-11-25 17:08:47 UTC (rev 5276)
@@ -81,7 +81,7 @@
       eXo.portal.portalMode = <%= uicomponent.getModeState() %>;
       eXo.session.level = "$sessionAliveLevel";
       eXo.session.canKeepState = $canKeepState;
-      eXo.session.isOpen = $uicomponent.isSessionOpen ;
+      eXo.session.isOpen = <%=uicomponent.isSessionOpen()%> ;
       eXo.session.itvTime = ${((PortalRequestContext)rcontext).getRequest().getSession().getMaxInactiveInterval()} ;
     </script>
     <script type="text/javascript" src="/eXoResources/javascript/eXo/i18n/I18NMessage.js"></script>

Modified: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalController.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalController.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalController.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -77,6 +77,11 @@
          application.onInit();
          controller.addApplication(application);
          controller.register(new PortalRequestHandler());
+         
+         StandaloneApplication standaloneApplication = new StandaloneApplication(config);
+         standaloneApplication.onInit();
+         controller.addApplication(standaloneApplication);
+         controller.register(new StandaloneAppRequestHandler());
          log.info("The WebAppController has been successfully initialized for the portal '" + portalContainer.getName()
             + "'");
       }

Modified: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java	2010-11-25 16:37:48 UTC (rev 5275)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -77,7 +77,6 @@
     *   12) Release the context from the thread
     * 
     */
-   @SuppressWarnings("unchecked")
    public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception
    {
       log.debug("Session ID = " + req.getSession().getId());
@@ -89,6 +88,12 @@
          res.sendRedirect(req.getContextPath());
          return;
       }
+      processRequest(context, app);
+   }
+
+   @SuppressWarnings("unchecked")
+   protected void processRequest(PortalRequestContext context, PortalApplication app) throws Exception
+   {
       WebuiRequestContext.setCurrentInstance(context);
       List<ApplicationLifecycle> lifecycles = app.getApplicationLifecycle();
       try

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestContext.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestContext.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestContext.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,94 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application;
+
+import org.exoplatform.portal.webui.application.UIStandaloneGadget;
+import org.exoplatform.portal.webui.workspace.UIStandaloneApplication;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.resources.Orientation;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.core.UIApplication;
+import java.util.Locale;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class StandaloneAppRequestContext extends PortalRequestContext
+{
+   private String storageId;
+   protected static Log log = ExoLogger.getLogger(StandaloneAppRequestContext.class);
+
+   public StandaloneAppRequestContext(WebuiApplication app, HttpServletRequest req, HttpServletResponse res)
+      throws Exception
+   {
+      super(app, req, res);
+      int idx = (req.getServletPath() + req.getContextPath()).length() + 1;
+      if (idx <= getRequestURI().length())
+      {
+         storageId = getRequestURI().substring(idx);
+      }
+      else
+      {
+         storageId = "";
+      }
+   }
+
+   public String getStorageId()
+   {
+      return storageId;
+   }
+
+   public String getTitle() throws Exception
+   {
+      String title = null;
+      UIApplication uiApp = getUIApplication();
+      UIStandaloneGadget aloneGadget = uiApp.findFirstComponentOfType(UIStandaloneGadget.class);
+      if (aloneGadget != null)
+      {
+         title = aloneGadget.getApplicationName();         
+      }
+      
+      if (title == null)
+      {
+         title = "";
+      }
+      return title;
+   }
+
+   public Orientation getOrientation()
+   {
+      return ((UIStandaloneApplication)uiApplication_).getOrientation();
+   }
+
+   public Locale getLocale()
+   {
+      return ((UIStandaloneApplication)uiApplication_).getLocale();
+   }
+
+   public String getPortalOwner()
+   {
+      return null;
+   }
+
+   public String getNodePath()
+   {
+      throw new UnsupportedOperationException();
+   }
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestHandler.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestHandler.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppRequestHandler.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ * 
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.exoplatform.web.WebAppController;
+
+
+public class StandaloneAppRequestHandler extends PortalRequestHandler
+{
+
+   private String[] PATHS = {"/StandaloneApplication"};
+
+   public String[] getPath()
+   {
+      return PATHS;
+   }
+
+   public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception
+   {
+      log.debug("Session ID = " + req.getSession().getId());
+      res.setHeader("Cache-Control", "no-cache");
+
+      StandaloneApplication app = controller.getApplication(StandaloneApplication.STANDALONE_APPLICATION_ID);
+      StandaloneAppRequestContext context = new StandaloneAppRequestContext(app, req, res);
+//      if (context.getPortalOwner().length() == 0) {
+//         res.sendRedirect(req.getContextPath());
+//         return;
+//      }
+      processRequest(context, app);
+   }     
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppStateManager.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppStateManager.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneAppStateManager.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,127 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application;
+
+import org.exoplatform.commons.utils.Safe;
+import org.exoplatform.portal.application.replication.ApplicationState;
+import org.exoplatform.webui.application.ConfigurationManager;
+import org.exoplatform.webui.application.StateManager;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.core.UIApplication;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+public class StandaloneAppStateManager extends StateManager
+{
+
+   /** . */
+   protected static final String APPLICATION_KEY = "StandaloneApp";
+
+   /** . */
+   private static final Logger log = LoggerFactory.getLogger(StandaloneAppStateManager.class);
+
+   @Override
+   public UIApplication restoreUIRootComponent(WebuiRequestContext context) throws Exception
+   {
+      context.setStateManager(this);
+
+      //
+      WebuiApplication app = (WebuiApplication)context.getApplication();
+
+      //
+      ApplicationState appState = null;
+      HttpSession session = getSession(context);
+      if (session != null)
+      {
+         appState = (ApplicationState)session.getAttribute(APPLICATION_KEY);
+      }
+
+      //
+
+      //
+      UIApplication uiapp = null;
+      if (appState != null)
+      {
+         if (Safe.equals(context.getRemoteUser(), appState.getUserName()))
+         {
+            uiapp = appState.getApplication();
+         }
+      }
+
+      //
+      if (appState != null)
+      {
+         log.debug("Found application " + APPLICATION_KEY + " :" + appState.getApplication());
+      }
+      else
+      {
+         log.debug("Application " + APPLICATION_KEY + " not found");
+      }
+
+      //
+      if (uiapp == null)
+      {
+         ConfigurationManager cmanager = app.getConfigurationManager();
+         String uirootClass = cmanager.getApplication().getUIRootComponent();
+         Class<? extends UIApplication> type = (Class<UIApplication>) Thread.currentThread().getContextClassLoader().loadClass(uirootClass);
+         uiapp = app.createUIComponent(type, null, null, context);
+      }
+
+      //
+      return uiapp;
+   }
+
+   @Override
+   public void storeUIRootComponent(final WebuiRequestContext context) throws Exception
+   {
+      UIApplication uiapp = context.getUIApplication();
+
+      //
+      if (uiapp != null)
+      {
+         HttpSession session = getSession(context);
+
+         // At this point if it returns null it means that it was not possible to create a session
+         // because the session might be invalidated and the response is already commited to the client.
+         // That situation happens during a logout that invalidates the HttpSession
+         if (session != null)
+         {
+            log.debug("Storing application " + APPLICATION_KEY);
+            session.setAttribute(APPLICATION_KEY, new ApplicationState(uiapp, context.getRemoteUser()));
+         }
+      }
+   }
+
+   @Override
+   public void expire(String sessionId, WebuiApplication app) throws Exception
+   {
+      // For now do nothing....
+   }
+   
+   protected HttpSession getSession(WebuiRequestContext webuiRC)
+   {
+      StandaloneAppRequestContext staRC = (StandaloneAppRequestContext)webuiRC;
+      HttpServletRequest req = staRC.getRequest();
+      return req.getSession(false);
+   }
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneApplication.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneApplication.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/application/StandaloneApplication.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,44 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ * 
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application;
+
+import javax.servlet.ServletConfig;
+
+public class StandaloneApplication extends PortalApplication
+{
+
+   final static public String STANDALONE_APPLICATION_ID = "StandaloneApplication";
+
+   public StandaloneApplication(ServletConfig config) throws Exception
+   {
+      super(config);
+   }
+
+
+   public String getApplicationId()
+   {
+      return STANDALONE_APPLICATION_ID;
+   }
+   
+   public String getApplicationInitParam(String name)
+   {
+      return getServletConfig().getInitParameter("standalone." + name);
+   }
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneAppContainer.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneAppContainer.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneAppContainer.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,181 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.webui.application;
+
+import org.exoplatform.portal.application.StandaloneAppRequestContext;
+import org.exoplatform.portal.config.DataStorage;
+import org.exoplatform.portal.config.model.Application;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.pom.spi.gadget.Gadget;
+import org.exoplatform.portal.webui.util.PortalDataMapper;
+import org.exoplatform.services.security.ConversationState;
+import org.exoplatform.web.login.InitiateLoginServlet;
+import org.exoplatform.web.security.security.AbstractTokenService;
+import org.exoplatform.web.security.security.CookieTokenService;
+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.UIComponent;
+import org.exoplatform.webui.core.UIContainer;
+import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.EventListener;
+import java.util.Map;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+ at ComponentConfig(template = "system:/groovy/portal/webui/application/UIStandaloneAppContainer.gtmpl", events = {
+   @EventConfig(listeners = UIStandaloneAppContainer.LogoutActionListener.class)})
+public class UIStandaloneAppContainer extends UIContainer
+{
+   private boolean lossData;
+   private UIStandaloneGadget currApp;
+
+   public String getCurrStorageId()
+   {
+      if (currApp != null)
+      {
+         return currApp.getStorageId();
+      }
+      return null;
+   }
+
+   public void setCurrStorageId(String storageId) throws Exception
+   {
+      //New app, so we reset the lossData status
+      lossData = false;
+      
+      currApp = getChildByStorageId(storageId);
+      if (currApp != null)
+      {
+         return;
+      }
+
+      DataStorage ds = getApplicationComponent(DataStorage.class);
+      Map<String, String> siteInfo;
+      try
+      {
+         siteInfo = ds.getSiteInfo(storageId);
+      }
+      catch (Exception ex)
+      {
+         lossData = true;
+         return;
+      }
+
+      String siteType = null;
+      String siteOwner = null;
+      if (siteInfo != null)
+      {
+         siteType = siteInfo.get("siteType");
+         siteOwner = siteInfo.get("siteOwner");
+      }
+      ConversationState currentState = ConversationState.getCurrent();
+      if (PortalConfig.USER_TYPE.equals(siteType) && currentState.getIdentity().getUserId().equals(siteOwner))
+      {
+         Application<Gadget> gadgetModel = ds.getApplicationModel(storageId);
+         UIStandaloneGadget staGadget = createUIComponent(UIStandaloneGadget.class, null, null);
+         staGadget.setStorageId(storageId);
+         PortalDataMapper.toUIGadget(staGadget, gadgetModel);
+         addChild(staGadget);
+         currApp = staGadget;
+      }
+   }
+
+   private UIStandaloneGadget getChildByStorageId(String storageId)
+   {
+      for (UIComponent child : getChildren())
+      {
+         if (child instanceof UIStandaloneGadget)
+         {
+            UIStandaloneGadget gadget = (UIStandaloneGadget)child;
+            if (gadget.getStorageId().equals(storageId))
+            {
+               return gadget;
+            }
+         }
+      }
+      return null;
+   }
+
+   public boolean isLossData()
+   {
+      return lossData;
+   }
+
+   @Override
+   public void processRender(WebuiRequestContext context) throws Exception
+   {
+      if (!lossData)
+      {
+         if (currApp != null && currApp.isLossData())
+         {
+            removeChildById(currApp.getId());
+            currApp = null;
+            lossData = true;
+         }
+      }                                                     
+      super.processRender(context);
+   }
+
+   static public class LogoutActionListener extends EventListener<UIComponent>
+   {
+      public void execute(Event<UIComponent> event) throws Exception
+      {
+         StandaloneAppRequestContext staReqContext = (StandaloneAppRequestContext)event.getRequestContext();
+         HttpServletRequest req = staReqContext.getRequest();
+         HttpServletResponse res = staReqContext.getResponse();
+
+         //Delete the token from JCR
+         String token = getTokenCookie(req);
+         if (token != null)
+         {
+            AbstractTokenService tokenService = AbstractTokenService.getInstance(CookieTokenService.class);
+            tokenService.deleteToken(token);
+         }
+
+         req.getSession().invalidate();
+         Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, "");
+         cookie.setPath(req.getContextPath());
+         cookie.setMaxAge(0);
+         res.addCookie(cookie);
+
+         res.sendRedirect(req.getRequestURI());
+         staReqContext.setResponseComplete(true);
+      }
+
+      private String getTokenCookie(HttpServletRequest req)
+      {
+         Cookie[] cookies = req.getCookies();
+         if (cookies != null)
+         {
+            for (Cookie cookie : cookies)
+            {
+               if (InitiateLoginServlet.COOKIE_NAME.equals(cookie.getName()))
+               {
+                  return cookie.getValue();
+               }
+            }
+         }
+         return null;
+      }
+
+   }
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneGadget.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneGadget.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIStandaloneGadget.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,65 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ * 
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.webui.application;
+
+import org.exoplatform.portal.config.DataStorage;
+import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.config.annotation.EventConfig;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.EventListener;
+
+ at ComponentConfig(template = "system:/groovy/portal/webui/application/UIStandaloneGadget.gtmpl", events = {
+   @EventConfig(listeners = UIStandaloneGadget.SaveUserPrefActionListener.class)})
+public class UIStandaloneGadget extends UIGadget
+{
+
+   @Override
+   public boolean isLossData()
+   {
+      DataStorage ds = getApplicationComponent(DataStorage.class);
+      try
+      {
+         ds.getId(getState());
+      }
+      catch (Exception e)
+      {
+         return true;
+      }
+      return super.isLossData();
+   }
+
+   static public class SaveUserPrefActionListener extends EventListener<UIStandaloneGadget>
+   {
+      public void execute(Event<UIStandaloneGadget> event) throws Exception
+      {
+         UIStandaloneGadget uiGadget = event.getSource();
+
+         try
+         {
+            uiGadget.addUserPref(event.getRequestContext().getRequestParameter("userPref"));
+         }
+         catch(Exception e)
+         {
+            event.getRequestContext().addUIComponentToUpdateByAjax(uiGadget.<UIComponent>getParent());
+         }
+      }
+   }
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplication.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplication.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplication.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,239 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.webui.workspace;
+
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.application.StandaloneAppRequestContext;
+import org.exoplatform.portal.config.DataStorage;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.resource.Skin;
+import org.exoplatform.portal.resource.SkinService;
+import org.exoplatform.portal.webui.application.UIStandaloneAppContainer;
+import org.exoplatform.services.resources.Orientation;
+import org.exoplatform.services.security.ConversationState;
+import org.exoplatform.web.application.javascript.JavascriptConfigService;
+import org.exoplatform.web.login.InitiateLoginServlet;
+import org.exoplatform.web.security.security.AbstractTokenService;
+import org.exoplatform.web.security.security.CookieTokenService;
+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.event.Event;
+import org.exoplatform.webui.event.EventListener;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+ at ComponentConfig(lifecycle = UIStandaloneApplicationLifecycle.class, template = "system:/groovy/portal/webui/workspace/UIPortalApplication.gtmpl")
+public class UIStandaloneApplication extends UIApplication
+{
+   public static final int NORMAL_MODE = 0;
+
+   //modeState, locale, skin_, orientation will be used when we display portlet in standalone mode
+   private int modeState = NORMAL_MODE;
+
+   private Locale locale_ = Locale.ENGLISH;
+
+   private String skin_ = "Default";
+
+   private Orientation orientation_ = Orientation.LT;
+
+   private boolean isSessionOpen = false;
+
+   public UIStandaloneApplication() throws Exception
+   {
+      addChild(UIStandaloneAppContainer.class, null, null);
+   }  
+
+   //Temporary need this, don't want to render UIPopupMessage
+   public void renderChildren() throws Exception
+   {
+      WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+      super.renderChildren(context);
+   }
+
+   @Override
+   public void processDecode(WebuiRequestContext context) throws Exception
+   {
+      String storageId = ((StandaloneAppRequestContext)context).getStorageId();      
+      
+      UIStandaloneAppContainer staContaner = getChild(UIStandaloneAppContainer.class);
+      if (!storageId.equals(staContaner.getCurrStorageId()) )
+      {         
+         staContaner.setCurrStorageId(storageId);
+      }
+      super.processDecode(context);
+   }
+
+   public void processRender(WebuiRequestContext context) throws Exception
+   {
+      Writer w = context.getWriter();
+
+      //
+      if (!context.useAjax())
+      {
+         super.processRender(context);
+      }
+      else
+      {
+         PortalRequestContext pcontext = (PortalRequestContext)context;
+
+//         if (getUIPopupMessages().hasMessage())
+//         {
+//            pcontext.addUIComponentToUpdateByAjax(getUIPopupMessages());
+//         }         
+
+         Set<UIComponent> list = context.getUIComponentToUpdateByAjax();
+//         List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>(3);
+//         List<UIComponent> uiDataComponents = new ArrayList<UIComponent>(5);
+
+//         if (list != null)
+//         {
+//            for (UIComponent uicomponent : list)
+//            {
+//               if (uicomponent instanceof UIPortlet)
+//                  uiPortlets.add((UIPortlet)uicomponent);
+//               else
+//                  uiDataComponents.add(uicomponent);
+//            }
+//         }
+         w.write("<div class=\"PortalResponse\">");
+         w.write("<div class=\"PortalResponseData\">");
+         if (list != null)
+         {
+            for (UIComponent uicomponent : list)
+            {
+               if (log.isDebugEnabled())
+               {
+                  log.debug("AJAX call: Need to refresh the UI component " + uicomponent.getName());
+               }
+               renderBlockToUpdate(uicomponent, context, w);
+            }
+         }
+         w.write("</div>");
+
+//         if (!context.getFullRender())
+//         {
+//            for (UIPortlet uiPortlet : uiPortlets)
+//            {
+//               if (log.isDebugEnabled())
+//                  log.debug("AJAX call: Need to refresh the Portlet " + uiPortlet.getId());
+//
+//               w.write("<div class=\"PortletResponse\" style=\"display: none\">");
+//               w.append("<div class=\"PortletResponsePortletId\">" + uiPortlet.getId() + "</div>");
+//               w.append("<div class=\"PortletResponseData\">");
+//
+//               /*
+//                * If the portlet is using our UI framework or supports it then
+//                * it will return a set of block to updates. If there is not
+//                * block to update the javascript client will see that as a full
+//                * refresh of the content part
+//                */
+//               uiPortlet.processRender(context);
+//
+//               w.append("</div>");
+//               w.append("<div class=\"PortletResponseScript\"></div>");
+//               w.write("</div>");
+//            }
+//         }
+
+         w.write("<div class=\"PortalResponseScript\">");
+         pcontext.getJavascriptManager().writeJavascript(w);
+         w.write("eXo.core.Browser.onLoad();\n");
+         pcontext.getJavascriptManager().writeCustomizedOnLoadScript(w);
+         w.write("</div>");
+         w.write("</div>");
+      }
+   }
+
+    public Collection<String> getJavascriptURLs()
+   {
+      JavascriptConfigService service = getApplicationComponent(JavascriptConfigService.class);
+      return service.getAvailableScriptsPaths();
+   }
+
+   public Collection<Skin> getPortalSkins()
+   {
+      SkinService skinService = getApplicationComponent(SkinService.class);
+      Collection<Skin> skins = new ArrayList<Skin>(skinService.getPortalSkins(skin_));
+//      Collection<Skin> skins = new ArrayList<Skin>();
+      return skins;
+   }
+
+   public Set<Skin> getPortletSkins()
+   {
+      Set<Skin> skins = new HashSet<Skin>();
+      return skins;
+   }
+   
+   public boolean isSessionOpen()
+   {
+      return isSessionOpen;
+   }
+
+   public void setSessionOpen(boolean isSessionOpen)
+   {
+      this.isSessionOpen = isSessionOpen;
+   }
+
+   public String getSkin()
+   {
+      return skin_;
+   }
+
+   public Orientation getOrientation()
+   {
+      return orientation_;
+   }
+
+   public void setOrientation(Orientation orientation)
+   {
+      this.orientation_ = orientation;
+   }
+
+   public Locale getLocale()
+   {
+      return locale_;
+   }
+
+   public void setLocale(Locale locale)
+   {
+      locale_ = locale;
+   }
+
+   public void setModeState(int mode)
+   {
+      this.modeState = mode;
+   }
+
+   public int getModeState()
+   {
+      return modeState;
+   }
+}

Added: exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplicationLifecycle.java
===================================================================
--- exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplicationLifecycle.java	                        (rev 0)
+++ exo/portal/branches/standalone/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIStandaloneApplicationLifecycle.java	2010-11-25 17:08:47 UTC (rev 5276)
@@ -0,0 +1,132 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.webui.workspace;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.exoplatform.commons.utils.PortalPrinter;
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.webui.application.UIStandaloneAppContainer;
+import org.exoplatform.resolver.ResourceResolver;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.core.lifecycle.Lifecycle;
+import org.exoplatform.webui.core.lifecycle.WebuiBindingContext;
+
+/**
+ * Created by The eXo Platform SAS
+ * May 8, 2006
+ */
+public class UIStandaloneApplicationLifecycle extends Lifecycle<UIStandaloneApplication>
+{
+
+   public void processDecode(UIStandaloneApplication uicomponent, WebuiRequestContext context) throws Exception
+   {
+      String componentId = context.getRequestParameter(context.getUIComponentIdParameterName());
+      if (componentId == null)
+      {
+         return;
+      }
+      UIComponent uiTarget = uicomponent.findComponentById(componentId);
+      if (uiTarget == null)
+      {
+         context.addUIComponentToUpdateByAjax(uicomponent.getChild(UIStandaloneAppContainer.class));
+         return;
+      }
+      if (uiTarget == uicomponent)
+      {
+         super.processDecode(uicomponent, context);
+      }
+      uiTarget.processDecode(context);
+   }
+
+   public void processAction(UIStandaloneApplication uicomponent, WebuiRequestContext context) throws Exception
+   {
+      String componentId = context.getRequestParameter(context.getUIComponentIdParameterName());
+      if (componentId == null)
+      {
+         return;
+      }
+      UIComponent uiTarget = uicomponent.findComponentById(componentId);
+      if (uiTarget == null)
+      {
+         return;
+      }
+      if (uiTarget == uicomponent)
+      {
+         super.processAction(uicomponent, context);
+      }
+      uiTarget.processAction(context);
+   }
+
+   public void processRender(UIStandaloneApplication uicomponent,
+                             WebuiRequestContext context) throws Exception
+   {
+
+      PortalRequestContext prc = (PortalRequestContext)context;
+      OutputStream responseOutputStream = prc.getResponse().getOutputStream();
+
+      PortalPrinter parentWriter = new PortalPrinter(responseOutputStream, true, 5000);
+      PortalPrinter childWriter = new PortalPrinter(responseOutputStream, true, 25000, true);
+
+      context.setWriter(childWriter);
+      processRender(uicomponent, context, "system:/groovy/portal/webui/workspace/UIPortalApplicationChildren.gtmpl");
+
+      context.setWriter(parentWriter);
+      processRender(uicomponent, context, "system:/groovy/portal/webui/workspace/UIPortalApplication.gtmpl");
+
+      try
+      {
+         //flush the parent writer to the output stream so that we are really to accept the child content
+         parentWriter.flushOutputStream();
+         //now that the parent has been flushed, we can flush the contents of the child to the output
+         childWriter.flushOutputStream();
+      }
+      catch (IOException ioe)
+      {
+         //We want to ignore the ClientAbortException since this is caused by the users
+         //browser closing the connection and is not something we should be logging.
+         if (!ioe.getClass().toString().contains("ClientAbortException"))
+         {
+            throw ioe;
+         }
+
+      }
+   }
+
+   public void processRender(UIStandaloneApplication uicomponent, WebuiRequestContext context, String template) throws Exception
+   {
+      // Fail if we have no template
+      if (template == null)
+      {
+         throw new IllegalStateException("uicomponent " + uicomponent + " with class " + uicomponent.getClass().getName() +
+            " has no template for rendering");
+      }
+
+      //
+      ResourceResolver resolver = uicomponent.getTemplateResourceResolver(context, template);
+      WebuiBindingContext bcontext = new WebuiBindingContext(resolver, context.getWriter(), uicomponent, context);
+      bcontext.put(UIComponent.UICOMPONENT, uicomponent);
+      bcontext.put(uicomponent.getUIComponentName(), uicomponent);
+      renderTemplate(template, bcontext);
+   }
+
+}



More information about the gatein-commits mailing list