From portal-commits at lists.jboss.org Tue Nov 13 12:25:36 2007 Content-Type: multipart/mixed; boundary="===============3277421485558951372==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r8908 - in branches/UIServer/uiserver/src: main/org/jboss/portal/presentation/impl/ajax/service and 3 other directories. Date: Tue, 13 Nov 2007 12:25:35 -0500 Message-ID: --===============3277421485558951372== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/a= jax/service/ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/a= jax/service/PortalEntryPoint.java branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/a= jax/service/PortletServiceImpl.java Removed: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/aj= ax/ Modified: branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/porta= l/uiserver/ajax/AsyncPages.gwt.xml branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/porta= l/uiserver/ajax/PartialRefresh.gwt.xml branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/porta= l/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/im= pl/ajax/service/PortalEntryPoint.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 Sohil Shah + * = + */ +public class PortalEntryPoint extends RemoteServiceServlet implements = +PortalRPC +{ + /** The logger. */ + private Logger log =3D Logger.getLogger(getClass()); + + /** + * = + */ + private EntryPoint entryPoint =3D null; + + /** Configure the as default servlet. */ + public void init() throws ServletException + { + try + { + MBeanServer mbeanServer =3D MBeanServerLocator.locateJBoss(); + this.entryPoint =3D (EntryPoint) MBeanProxy.get(EntryPoint.class,= new ObjectName( + this.getInitParameter("entryPointServiceName")), + mbeanServer); + } + catch (Exception e) + { + this.entryPoint =3D null; + String msg =3D "Portal Entry Point could not be created"; + log.error(msg, e); + throw new UnavailableException(msg); + } + } + = + /** + * = + */ + public String processCall(String payload) throws SerializationException + { + HttpServletRequest request =3D this.getThreadLocalRequest(); + = + //Perform the remote procedure call + String returnVal =3D 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") !=3D null) + { + ProcessorResponse processorResponse =3D (ProcessorResponse)reques= t.getAttribute("processorResponse"); + request.getSession().setAttribute("processorResponse", processorR= esponse); + } + = + 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 =3D null; + HttpServletRequest request =3D this.getThreadLocalRequest(); + this.callPortalServer(); + display =3D this.getDisplay((ProcessorResponse)request.getAttribu= te("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 =3D null; + + HttpServletRequest request =3D this.getThreadLocalRequest(); + + ProcessorResponse processorResponse =3D (ProcessorResponse) request.= getSession().getAttribute("processorResponse"); + = + currentPage =3D this.getDisplay(processorResponse); + + return currentPage; + } = + //---------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------- + /** + * = + * @param processorResponse + * @return + */ + private Page getDisplay(ProcessorResponse processorResponse) + { + Page display =3D null; + = + org.jboss.portal.presentation.model.Page portalPage =3D processorRes= ponse + .findDisplayedPage(); + + // Construct the ajax currentPage object from the portalPage that ha= s been + // chosen to be displayed + if (portalPage !=3D null) + { + display =3D new Page(); + display.setName(portalPage.getName()); + List pageWindows =3D portalPage.getWindows(); + if(pageWindows !=3D null && pageWindows.size()>0) + { + Window[] windows =3D new Window[pageWindows.size()]; + display.setWindows(windows); + for(int i=3D0; iSohil Shah + * = + */ +public class PortletServiceImpl extends RemoteServiceServlet implements + PortletService +{ + /** + * = + */ + public String getPortlet(String portletId) + { + String portletContent =3D null; + + String contentPath =3D portletId; + InputStream is =3D null; + try + { + is =3D Thread.currentThread().getContextClassLoader() + .getResourceAsStream(contentPath); + StringBuffer contentBuffer =3D new StringBuffer(); + int bytesRead =3D 0; + byte[] data =3D new byte[1024]; + while ((bytesRead =3D is.read(data)) !=3D -1) + { + byte[] cour =3D new byte[bytesRead]; + System.arraycopy(data, 0, cour, 0, bytesRead); + contentBuffer.append(new String(cour)); + } + portletContent =3D contentBuffer.toString(); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + finally + { + if (is !=3D null) + { + try + { + is.close(); + } + catch (Exception e) + { + } + } + } + + return portletContent; + } + + /** + * = + * @param pageId + * @return + */ + public Page getPage(String pageId) + { + Page page =3D new Page(); + page.setName(pageId); + + if (pageId.equals("index") || pageId.equals("Page 1")) + { + String weatherContent =3D this.getPortlet("weatherPortlet.html"); + String cmsContent =3D this.getPortlet("cmsPortlet.html"); + Window[] windows =3D new Window[2]; + page.setWindows(windows); + + Window weatherWindow =3D new Window(); + weatherWindow.setName("weatherPortlet"); + weatherWindow.setContent(weatherContent); + + Window cmsWindow =3D new Window(); + cmsWindow.setName("cmsPortlet"); + cmsWindow.setContent(cmsContent); + + windows[0] =3D weatherWindow; + windows[1] =3D cmsWindow; + } + else if (pageId.equals("Page 2")) + { + String weatherContent =3D this.getPortlet("weatherPortlet.html"); + Window[] windows =3D new Window[1]; + page.setWindows(windows); + + Window weatherWindow =3D new Window(); + weatherWindow.setName("weatherPortlet"); + weatherWindow.setContent(weatherContent); + + windows[0] =3D weatherWindow; + } + else if (pageId.equals("Page 3")) + { + String cmsContent =3D this.getPortlet("cmsPortlet.html"); + Window[] windows =3D new Window[1]; + page.setWindows(windows); + + Window cmsWindow =3D new Window(); + cmsWindow.setName("cmsPortlet"); + cmsWindow.setContent(cmsContent); + + windows[0] =3D cmsWindow; + } + + HttpServletRequest request =3D this.getThreadLocalRequest(); + request.getSession().setAttribute("currentPage", page); + + return page; + } + + /** + * = + * @param window + * @param state + */ + public Page setState(String window, String newState) + { + HttpServletRequest request =3D this.getThreadLocalRequest(); + Page page =3D (Page) request.getSession().getAttribute("currentPage"= ); + + Window selectedWindow =3D 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 =3D this.getThreadLocalRequest(); + Page page =3D (Page) request.getSession().getAttribute("currentPage"= ); + + Window selectedWindow =3D this.findWindow(page, window); + selectedWindow.setMode(newMode); + + return page; + } + + /** + * = + * @param page + * @param windowName + * @return + */ + private Window findWindow(Page page, String windowName) + { + Window window =3D null; + + Window[] windows =3D page.getWindows(); + for (int i =3D 0; i < windows.length; i++) + { + if (windows[i].getName().equals(windowName)) + { + window =3D windows[i]; + break; + } + } + + return window; + } + + /** + * = + * @param excludedWindow + * @param hide + */ + private void hideWindows(Window[] windows, Window excludedWindow, + boolean hide) + { + for (int i =3D 0; i < windows.length; i++) + { + if (excludedWindow !=3D null + && windows[i].getName().equals(excludedWindow.getName())) + { + continue; + } + + windows[i].setVisible(!hide); + } + } +} Modified: branches/UIServer/uiserver/src/resources/client/ajax/src/org/jbos= s/portal/uiserver/ajax/AsyncPages.gwt.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/port= al/uiserver/ajax/AsyncPages.gwt.xml 2007-11-13 17:19:15 UTC (rev 8907) +++ branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/port= al/uiserver/ajax/AsyncPages.gwt.xml 2007-11-13 17:25:35 UTC (rev 8908) @@ -8,5 +8,5 @@ = = = - + Modified: branches/UIServer/uiserver/src/resources/client/ajax/src/org/jbos= s/portal/uiserver/ajax/PartialRefresh.gwt.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/port= al/uiserver/ajax/PartialRefresh.gwt.xml 2007-11-13 17:19:15 UTC (rev 8907) +++ branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/port= al/uiserver/ajax/PartialRefresh.gwt.xml 2007-11-13 17:25:35 UTC (rev 8908) @@ -6,5 +6,5 @@ = = - + Modified: branches/UIServer/uiserver/src/resources/client/ajax/src/org/jbos= s/portal/uiserver/ajax/PortalLayout.gwt.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/port= al/uiserver/ajax/PortalLayout.gwt.xml 2007-11-13 17:19:15 UTC (rev 8907) +++ branches/UIServer/uiserver/src/resources/client/ajax/src/org/jboss/port= al/uiserver/ajax/PortalLayout.gwt.xml 2007-11-13 17:25:35 UTC (rev 8908) @@ -6,5 +6,5 @@ = = - + Modified: branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-= INF/web.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-INF/we= b.xml 2007-11-13 17:19:15 UTC (rev 8907) +++ branches/UIServer/uiserver/src/resources/portal-uiserver.war/WEB-INF/we= b.xml 2007-11-13 17:25:35 UTC (rev 8908) @@ -74,7 +74,7 @@ AjaxPortalEntryPoint - org.jboss.portal.uiserver.service.ajax.PortalEntryPoi= nt + org.jboss.portal.presentation.impl.ajax.service.Porta= lEntryPoint asDefaultServlet false --===============3277421485558951372==--