Author: sohil.shah(a)jboss.com
Date: 2007-11-13 12:25:35 -0500 (Tue, 13 Nov 2007)
New Revision: 8908
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortalEntryPoint.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortletServiceImpl.java
Removed:
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/ajax/
Modified:
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/AsyncPages.gwt.xml
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PartialRefresh.gwt.xml
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PortalLayout.gwt.xml
branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-INF/web.xml
Log:
refactoring
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortalEntryPoint.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortalEntryPoint.java
(rev 0)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortalEntryPoint.java 2007-11-13
17:25:35 UTC (rev 8908)
@@ -0,0 +1,224 @@
+package org.jboss.portal.presentation.impl.ajax.service;
+
+
+import java.util.Map;
+import java.util.List;
+import java.util.HashMap;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanServerLocator;
+
+import org.jboss.portal.common.invocation.InterceptorStackFactory;
+import org.jboss.portal.server.RequestControllerFactory;
+import org.jboss.portal.server.Server;
+import org.jboss.portal.server.ServerInvocationContext;
+import org.jboss.portal.server.impl.ServerInvocationContextImpl;
+import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.server.ServerRequest;
+import org.jboss.portal.server.ServerResponse;
+import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portal.server.RequestController;
+import org.jboss.portal.server.RequestControllerDispatcher;
+
+import org.jboss.portal.uiserver.ajax.client.service.PortalRPC;
+import org.jboss.portal.uiserver.ajax.client.protocol.Page;
+import org.jboss.portal.uiserver.ajax.client.protocol.Window;
+import org.jboss.portal.presentation.server.ProcessorResponse;
+import org.jboss.portal.uiserver.service.EntryPoint;
+
+import com.google.gwt.user.client.rpc.SerializationException;
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+/**
+ * This serves as the Portal Entry Point for AJAX (Asynchronous) RPC calls being made by
the
+ * client-side Ajax agent of the Presentation Framework
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class PortalEntryPoint extends RemoteServiceServlet implements
+PortalRPC
+{
+ /** The logger. */
+ private Logger log = Logger.getLogger(getClass());
+
+ /**
+ *
+ */
+ private EntryPoint entryPoint = null;
+
+ /** Configure the as default servlet. */
+ public void init() throws ServletException
+ {
+ try
+ {
+ MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+ this.entryPoint = (EntryPoint) MBeanProxy.get(EntryPoint.class, new ObjectName(
+ this.getInitParameter("entryPointServiceName")),
+ mbeanServer);
+ }
+ catch (Exception e)
+ {
+ this.entryPoint = null;
+ String msg = "Portal Entry Point could not be created";
+ log.error(msg, e);
+ throw new UnavailableException(msg);
+ }
+ }
+
+ /**
+ *
+ */
+ public String processCall(String payload) throws SerializationException
+ {
+ HttpServletRequest request = this.getThreadLocalRequest();
+
+ //Perform the remote procedure call
+ String returnVal = super.processCall(payload);
+
+ //Perform any post-processing after calling the actual remote method that will
perform
+ //the functionality for this particular remote procedure call
+ if(request.getAttribute("processorResponse") != null)
+ {
+ ProcessorResponse processorResponse =
(ProcessorResponse)request.getAttribute("processorResponse");
+ request.getSession().setAttribute("processorResponse",
processorResponse);
+ }
+
+ return returnVal;
+ }
+ //
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ * Loads the initial Portal Page at the start of a Portal session
+ *
+ * @return The Initial Portal Page
+ */
+ public Page loadPortal()
+ {
+ try
+ {
+ Page display = null;
+ HttpServletRequest request = this.getThreadLocalRequest();
+ this.callPortalServer();
+ display =
this.getDisplay((ProcessorResponse)request.getAttribute("processorResponse"));
+ return display;
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * @return The Page of the Portal that should be currently displayed
+ */
+ public Page getCurrentPage()
+ {
+ Page currentPage = null;
+
+ HttpServletRequest request = this.getThreadLocalRequest();
+
+ ProcessorResponse processorResponse = (ProcessorResponse)
request.getSession().getAttribute("processorResponse");
+
+ currentPage = this.getDisplay(processorResponse);
+
+ return currentPage;
+ }
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ * @param processorResponse
+ * @return
+ */
+ private Page getDisplay(ProcessorResponse processorResponse)
+ {
+ Page display = null;
+
+ org.jboss.portal.presentation.model.Page portalPage = processorResponse
+ .findDisplayedPage();
+
+ // Construct the ajax currentPage object from the portalPage that has been
+ // chosen to be displayed
+ if (portalPage != null)
+ {
+ display = new Page();
+ display.setName(portalPage.getName());
+ List pageWindows = portalPage.getWindows();
+ if(pageWindows != null && pageWindows.size()>0)
+ {
+ Window[] windows = new Window[pageWindows.size()];
+ display.setWindows(windows);
+ for(int i=0; i<pageWindows.size(); i++)
+ {
+ org.jboss.portal.presentation.model.Window pageWindow =
(org.jboss.portal.presentation.model.Window)pageWindows.get(i);
+ Window window = new Window();
+ window.setName(pageWindow.getName());
+ window.setContent(pageWindow.getContent());
+ windows[i] = window;
+ }
+ }
+ }
+
+ return display;
+ }
+
+ /**
+ *
+ *
+ */
+ private void callPortalServer() throws Exception
+ {
+ HttpServletRequest req = this.getThreadLocalRequest();
+ HttpServletResponse resp = this.getThreadLocalResponse();
+ String requestURI = req.getRequestURI();
+ String contextPath = req.getContextPath();
+ String portalHost = req.getServerName();
+ String portalRequestPath = requestURI.substring(contextPath.length());
+ String portalContextPath = requestURI.substring(0, contextPath.length());
+ Map queryParameterMap = new HashMap();
+ URLContext urlContext = URLContext.newInstance(req.isSecure(), req.getRemoteUser()
!= null);
+
+ Server server = this.entryPoint.getPortalServer();
+
+ //
+ ServerInvocationContext invocationCtx = new ServerInvocationContextImpl(
+ req,
+ resp,
+ portalHost,
+ portalRequestPath,
+ portalContextPath,
+ queryParameterMap,
+ null, //body parameter map is not applicable for asynchronous RPC calls
+ urlContext,
+ null //media type information is not applicable for asynchronous RPC calls
+ );
+
+ //
+ ServerRequest request = new ServerRequest(invocationCtx);
+ request.setServer(server);
+
+ //
+ ServerResponse response = new ServerResponse(request, invocationCtx);
+
+ //
+ ServerInvocation invocation = new ServerInvocation(invocationCtx);
+ invocation.setRequest(request);
+ invocation.setResponse(response);
+
+ //
+ RequestControllerFactory controllerFactory =
this.entryPoint.getControllerFactory();
+ RequestController controller =
controllerFactory.createRequestController(invocation);
+ invocation.setHandler(new RequestControllerDispatcher(controller));
+
+ InterceptorStackFactory stack = this.entryPoint.getInterceptorStackFactory();
+ invocation.invoke(stack.getInterceptorStack());
+ }
+}
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortletServiceImpl.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortletServiceImpl.java
(rev 0)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/ajax/service/PortletServiceImpl.java 2007-11-13
17:25:35 UTC (rev 8908)
@@ -0,0 +1,232 @@
+package org.jboss.portal.presentation.impl.ajax.service;
+
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.jboss.portal.uiserver.ajax.client.PortletService;
+import org.jboss.portal.uiserver.ajax.client.protocol.Page;
+import org.jboss.portal.uiserver.ajax.client.protocol.Window;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+/**
+ * This is just a STUB server side component to test the client side components
+ * of the GWT-based AJAX UI
+ *
+ * Only used for Prototyping stuff
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class PortletServiceImpl extends RemoteServiceServlet implements
+ PortletService
+{
+ /**
+ *
+ */
+ public String getPortlet(String portletId)
+ {
+ String portletContent = null;
+
+ String contentPath = portletId;
+ InputStream is = null;
+ try
+ {
+ is = Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream(contentPath);
+ StringBuffer contentBuffer = new StringBuffer();
+ int bytesRead = 0;
+ byte[] data = new byte[1024];
+ while ((bytesRead = is.read(data)) != -1)
+ {
+ byte[] cour = new byte[bytesRead];
+ System.arraycopy(data, 0, cour, 0, bytesRead);
+ contentBuffer.append(new String(cour));
+ }
+ portletContent = contentBuffer.toString();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+
+ return portletContent;
+ }
+
+ /**
+ *
+ * @param pageId
+ * @return
+ */
+ public Page getPage(String pageId)
+ {
+ Page page = new Page();
+ page.setName(pageId);
+
+ if (pageId.equals("index") || pageId.equals("Page 1"))
+ {
+ String weatherContent = this.getPortlet("weatherPortlet.html");
+ String cmsContent = this.getPortlet("cmsPortlet.html");
+ Window[] windows = new Window[2];
+ page.setWindows(windows);
+
+ Window weatherWindow = new Window();
+ weatherWindow.setName("weatherPortlet");
+ weatherWindow.setContent(weatherContent);
+
+ Window cmsWindow = new Window();
+ cmsWindow.setName("cmsPortlet");
+ cmsWindow.setContent(cmsContent);
+
+ windows[0] = weatherWindow;
+ windows[1] = cmsWindow;
+ }
+ else if (pageId.equals("Page 2"))
+ {
+ String weatherContent = this.getPortlet("weatherPortlet.html");
+ Window[] windows = new Window[1];
+ page.setWindows(windows);
+
+ Window weatherWindow = new Window();
+ weatherWindow.setName("weatherPortlet");
+ weatherWindow.setContent(weatherContent);
+
+ windows[0] = weatherWindow;
+ }
+ else if (pageId.equals("Page 3"))
+ {
+ String cmsContent = this.getPortlet("cmsPortlet.html");
+ Window[] windows = new Window[1];
+ page.setWindows(windows);
+
+ Window cmsWindow = new Window();
+ cmsWindow.setName("cmsPortlet");
+ cmsWindow.setContent(cmsContent);
+
+ windows[0] = cmsWindow;
+ }
+
+ HttpServletRequest request = this.getThreadLocalRequest();
+ request.getSession().setAttribute("currentPage", page);
+
+ return page;
+ }
+
+ /**
+ *
+ * @param window
+ * @param state
+ */
+ public Page setState(String window, String newState)
+ {
+ HttpServletRequest request = this.getThreadLocalRequest();
+ Page page = (Page) request.getSession().getAttribute("currentPage");
+
+ Window selectedWindow = this.findWindow(page, window);
+ selectedWindow.setState(newState);
+ if (selectedWindow.getState().equals(Window.NORMAL))
+ {
+ if (selectedWindow.getName().equals("cmsPortlet"))
+ {
+ selectedWindow.setContent(this.getPortlet("cmsPortlet.html"));
+ }
+ else
+ {
+ selectedWindow.setContent(this.getPortlet("weatherPortlet.html"));
+ }
+ this.hideWindows(page.getWindows(), null, false);
+ }
+ else if (selectedWindow.getState().equals(Window.MINIMIZED))
+ {
+ selectedWindow.setContent("");
+ this.hideWindows(page.getWindows(), null, false);
+ }
+ if (selectedWindow.getState().equals(Window.MAXIMIZED))
+ {
+ if (selectedWindow.getName().equals("cmsPortlet"))
+ {
+ selectedWindow.setContent(this.getPortlet("cmsPortlet.html"));
+ }
+ else
+ {
+ selectedWindow.setContent(this.getPortlet("weatherPortlet.html"));
+ }
+ this.hideWindows(page.getWindows(), selectedWindow, true);
+ }
+
+ return page;
+ }
+
+ /**
+ *
+ * @param window
+ * @param state
+ */
+ public Page setMode(String window, String newMode)
+ {
+ HttpServletRequest request = this.getThreadLocalRequest();
+ Page page = (Page) request.getSession().getAttribute("currentPage");
+
+ Window selectedWindow = this.findWindow(page, window);
+ selectedWindow.setMode(newMode);
+
+ return page;
+ }
+
+ /**
+ *
+ * @param page
+ * @param windowName
+ * @return
+ */
+ private Window findWindow(Page page, String windowName)
+ {
+ Window window = null;
+
+ Window[] windows = page.getWindows();
+ for (int i = 0; i < windows.length; i++)
+ {
+ if (windows[i].getName().equals(windowName))
+ {
+ window = windows[i];
+ break;
+ }
+ }
+
+ return window;
+ }
+
+ /**
+ *
+ * @param excludedWindow
+ * @param hide
+ */
+ private void hideWindows(Window[] windows, Window excludedWindow,
+ boolean hide)
+ {
+ for (int i = 0; i < windows.length; i++)
+ {
+ if (excludedWindow != null
+ && windows[i].getName().equals(excludedWindow.getName()))
+ {
+ continue;
+ }
+
+ windows[i].setVisible(!hide);
+ }
+ }
+}
Modified:
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/AsyncPages.gwt.xml
===================================================================
---
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/AsyncPages.gwt.xml 2007-11-13
17:19:15 UTC (rev 8907)
+++
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/AsyncPages.gwt.xml 2007-11-13
17:25:35 UTC (rev 8908)
@@ -8,5 +8,5 @@
<entry-point class="org.jboss.portal.uiserver.ajax.client.AsyncPages"/>
<!-- RPC related configuration -->
- <servlet path="/portletService"
class="org.jboss.portal.uiserver.service.ajax.PortletServiceImpl"/>
+ <servlet path="/portletService"
class="org.jboss.portal.presentation.impl.ajax.service.PortletServiceImpl"/>
</module>
Modified:
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PartialRefresh.gwt.xml
===================================================================
---
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PartialRefresh.gwt.xml 2007-11-13
17:19:15 UTC (rev 8907)
+++
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PartialRefresh.gwt.xml 2007-11-13
17:25:35 UTC (rev 8908)
@@ -6,5 +6,5 @@
<entry-point
class="org.jboss.portal.uiserver.ajax.client.PartialRefresh"/>
<!-- RPC related configuration -->
- <servlet path="/portletService"
class="org.jboss.portal.uiserver.service.ajax.PortletServiceImpl"/>
+ <servlet path="/portletService"
class="org.jboss.portal.presentation.impl.ajax.service.PortletServiceImpl"/>
</module>
Modified:
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PortalLayout.gwt.xml
===================================================================
---
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PortalLayout.gwt.xml 2007-11-13
17:19:15 UTC (rev 8907)
+++
branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/portal/uiserver/ajax/PortalLayout.gwt.xml 2007-11-13
17:25:35 UTC (rev 8908)
@@ -6,5 +6,5 @@
<entry-point
class="org.jboss.portal.uiserver.ajax.client.PortalLayout"/>
<!-- RPC related configuration -->
- <servlet path="/portletService"
class="org.jboss.portal.uiserver.service.ajax.PortletServiceImpl"/>
+ <servlet path="/portletService"
class="org.jboss.portal.presentation.impl.ajax.service.PortletServiceImpl"/>
</module>
Modified: branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-INF/web.xml
===================================================================
---
branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-INF/web.xml 2007-11-13
17:19:15 UTC (rev 8907)
+++
branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-INF/web.xml 2007-11-13
17:25:35 UTC (rev 8908)
@@ -74,7 +74,7 @@
<!-- Asynchronous service request processor -->
<servlet>
<servlet-name>AjaxPortalEntryPoint</servlet-name>
-
<servlet-class>org.jboss.portal.uiserver.service.ajax.PortalEntryPoint</servlet-class>
+
<servlet-class>org.jboss.portal.presentation.impl.ajax.service.PortalEntryPoint</servlet-class>
<init-param>
<param-name>asDefaultServlet</param-name>
<param-value>false</param-value>