Author: trong.tran
Date: 2010-10-06 03:01:13 -0400 (Wed, 06 Oct 2010)
New Revision: 4517
Added:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProviderFilter.java
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/ControllerContext.java
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml
portal/branches/navcontroller/web/portal/src/main/webapp/index.jsp
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/url/PortalURL.java
Log:
Implement a PortalURLProvider to create the Portal URL from outside of portal context
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/ControllerContext.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/ControllerContext.java 2010-10-06
04:46:50 UTC (rev 4516)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/ControllerContext.java 2010-10-06
07:01:13 UTC (rev 4517)
@@ -49,7 +49,7 @@
/** . */
private SimpleRenderContext renderContext;
- ControllerContext(
+ public ControllerContext(
WebAppController controller,
HttpServletRequest request,
HttpServletResponse response,
Modified: portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml 2010-10-06
04:46:50 UTC (rev 4516)
+++ portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml 2010-10-06
07:01:13 UTC (rev 4517)
@@ -69,8 +69,6 @@
<filter-class>org.exoplatform.services.security.web.SetCurrentIdentityFilter</filter-class>
</filter>
-
-
<filter>
<filter-name>RestEncodingFilter</filter-name>
<filter-class>org.exoplatform.services.rest.servlet.RestEncodingFilter</filter-class>
@@ -94,7 +92,12 @@
<filter-name>ClusteredSSOFilter</filter-name>
<filter-class>org.exoplatform.web.login.ClusteredSSOFilter</filter-class>
</filter>
-
+
+ <filter>
+ <filter-name>PortalURLProviderFilter</filter-name>
+
<filter-class>org.exoplatform.portal.url.PortalURLProviderFilter</filter-class>
+ </filter>
+
<filter-mapping>
<filter-name>RememberMeFilter</filter-name>
<servlet-name>portal</servlet-name>
@@ -163,6 +166,11 @@
<filter-name>RestEncodingFilter</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
+
+ <filter-mapping>
+ <filter-name>PortalURLProviderFilter</filter-name>
+ <url-pattern>*.jsp</url-pattern>
+ </filter-mapping>
<!-- ================================================================== -->
<!-- LISTENER -->
Modified: portal/branches/navcontroller/web/portal/src/main/webapp/index.jsp
===================================================================
--- portal/branches/navcontroller/web/portal/src/main/webapp/index.jsp 2010-10-06 04:46:50
UTC (rev 4516)
+++ portal/branches/navcontroller/web/portal/src/main/webapp/index.jsp 2010-10-06 07:01:13
UTC (rev 4517)
@@ -21,9 +21,16 @@
<%@ page import="org.exoplatform.container.PortalContainer"%>
<%@ page
import="org.exoplatform.portal.config.UserPortalConfigService"%>
+<%@ page import="org.exoplatform.portal.url.PortalURLProvider"%>
+<%@ page
import="org.exoplatform.portal.url.navigation.NavigationResource"%>
+<%@ page import="org.exoplatform.web.url.ControllerURL"%>
+
<%
PortalContainer manager =
PortalContainer.getCurrentInstance(session.getServletContext()) ;
UserPortalConfigService userPortalConfigService = (UserPortalConfigService)
manager.getComponentInstanceOfType(UserPortalConfigService.class) ;
- response.sendRedirect(request.getContextPath() +
"/public/"+userPortalConfigService.getDefaultPortal()+"/");
+ PortalURLProvider provider = PortalURLProvider.getCurrentPortalURLProvider();
+ ControllerURL portalURL = provider.createPortalURL("public",
userPortalConfigService.getDefaultPortal(),
org.exoplatform.portal.url.navigation.NavigationLocator.TYPE);
+
+ response.sendRedirect(portalURL.setResource(new NavigationResource(null,
null)).toString());
%>
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-10-06
04:46:50 UTC (rev 4516)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-10-06
07:01:13 UTC (rev 4517)
@@ -267,7 +267,7 @@
@Override
public <R, L extends ResourceLocator<R>> ControllerURL<R, L>
newURL(ResourceType<R, L> resourceType, L locator)
{
- return new PortalURL<R, L>(this, locator, false, portalOwner_, access);
+ return new PortalURL<R, L>(controllerContext, locator, false, portalOwner_,
access);
}
public ControllerContext getControllerContext()
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-10-06
04:46:50 UTC (rev 4516)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-10-06
07:01:13 UTC (rev 4517)
@@ -19,8 +19,8 @@
package org.exoplatform.portal.url;
-import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.application.PortalRequestHandler;
+import org.exoplatform.web.ControllerContext;
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.web.controller.router.SimpleRenderContext;
@@ -38,7 +38,7 @@
{
/** . */
- private final PortalRequestContext requestContext;
+ private final ControllerContext controllerContext;
/** . */
private final String access;
@@ -52,7 +52,7 @@
/** . */
private SimpleRenderContext renderContext;
- public PortalURL(PortalRequestContext requestContext, L locator, Boolean ajax, String
siteName, String access)
+ public PortalURL(ControllerContext requestContext, L locator, Boolean ajax, String
siteName, String access)
{
super(locator, ajax);
@@ -64,7 +64,7 @@
//
this.siteName = siteName;
- this.requestContext = requestContext;
+ this.controllerContext = requestContext;
this.access = access;
}
@@ -128,7 +128,7 @@
}
//
- requestContext.getControllerContext().renderURL(parameters, renderContext);
+ controllerContext.renderURL(parameters, renderContext);
//
boolean questionMarkDone = false;
Added:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java
(rev 0)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProvider.java 2010-10-06
07:01:13 UTC (rev 4517)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2010 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.url;
+
+import org.exoplatform.web.ControllerContext;
+import org.exoplatform.web.url.LocatorProvider;
+import org.exoplatform.web.url.ResourceLocator;
+import org.exoplatform.web.url.ResourceType;
+
+/**
+ * @author <a href="trongtt(a)gmail.com">Trong Tran</a>
+ * @version $Revision$
+ */
+public class PortalURLProvider
+{
+ private static ThreadLocal<PortalURLProvider> currentProvider = new
ThreadLocal<PortalURLProvider>();
+
+ private ControllerContext controllerContext;
+
+ private LocatorProvider locatorProvider;
+
+ public PortalURLProvider(ControllerContext controllerCtx, LocatorProvider
locatorService)
+ {
+ this.controllerContext = controllerCtx;
+ this.locatorProvider = locatorService;
+ }
+
+ public static void setCurrentPortalURLProvider(PortalURLProvider provider)
+ {
+ currentProvider.set(provider);
+ }
+
+ public static PortalURLProvider getCurrentPortalURLProvider()
+ {
+ return currentProvider.get();
+ }
+
+ public final <R, L extends ResourceLocator<R>> PortalURL<R, L>
createPortalURL(String access, String siteName, ResourceType<R, L> resourceType)
+ {
+ PortalURLProvider portalURLProvider = currentProvider.get();
+ if (portalURLProvider != null)
+ {
+ L newLocator = locatorProvider.newLocator(resourceType);
+ return new PortalURL<R, L>(controllerContext, newLocator, false, siteName,
access);
+ }
+ return null;
+ }
+}
Added:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProviderFilter.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProviderFilter.java
(rev 0)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURLProviderFilter.java 2010-10-06
07:01:13 UTC (rev 4517)
@@ -0,0 +1,74 @@
+/*
+ * 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.url;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.web.AbstractFilter;
+import org.exoplatform.web.ControllerContext;
+import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.url.LocatorProvider;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="trongtt(a)gmail.com">Trong Tran</a>
+ * @version $Revision$
+ */
+public class PortalURLProviderFilter extends AbstractFilter
+{
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+
+ ExoContainer container = getContainer();
+
+ WebAppController webAppController =
(WebAppController)container.getComponentInstanceOfType(WebAppController.class);
+
+ LocatorProvider locatorProvider =
(LocatorProvider)container.getComponentInstanceOfType(LocatorProvider.class);
+
+ HttpServletRequest httpRequest = (HttpServletRequest)request;
+
+ HttpServletResponse httpResponse = (HttpServletResponse)response;
+ try
+ {
+ ControllerContext controllerCtx = new ControllerContext(webAppController,
httpRequest, httpResponse, null);
+ PortalURLProvider urlProvider = new PortalURLProvider(controllerCtx,
locatorProvider);
+ PortalURLProvider.setCurrentPortalURLProvider(urlProvider);
+ chain.doFilter(httpRequest, httpResponse);
+ }
+ finally
+ {
+ PortalURLProvider.setCurrentPortalURLProvider(null);
+ }
+
+ }
+
+ @Override
+ public void destroy()
+ {
+ }
+}