[portal-commits] JBoss Portal SVN: r9018 - in branches/UIServer: uiserver/src/main/org/jboss/portal/presentation and 2 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Sun Nov 18 19:37:38 EST 2007


Author: julien at jboss.com
Date: 2007-11-18 19:37:38 -0500 (Sun, 18 Nov 2007)
New Revision: 9018

Added:
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java
Removed:
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/controller/
Modified:
   branches/UIServer/core-uiserver/src/resources/presentation-sar/META-INF/jboss-service.xml
Log:
move the controller to the client package

Modified: branches/UIServer/core-uiserver/src/resources/presentation-sar/META-INF/jboss-service.xml
===================================================================
--- branches/UIServer/core-uiserver/src/resources/presentation-sar/META-INF/jboss-service.xml	2007-11-19 00:08:14 UTC (rev 9017)
+++ branches/UIServer/core-uiserver/src/resources/presentation-sar/META-INF/jboss-service.xml	2007-11-19 00:37:38 UTC (rev 9018)
@@ -25,7 +25,7 @@
 <server>
 
    <mbean
-       code="org.jboss.portal.presentation.controller.UIController"
+       code="org.jboss.portal.presentation.client.controller.UIController"
        name="portal:service=Controller,type=Presentation"
        xmbean-dd=""
        xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">

Copied: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller (from rev 9013, branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/controller)

Deleted: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/controller/UIController.java	2007-11-18 20:00:55 UTC (rev 9013)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java	2007-11-19 00:37:38 UTC (rev 9018)
@@ -1,539 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
- * contributors as indicated by the @authors tag. See the                     *
- * copyright.txt in the distribution for a full listing of                    *
- * individual contributors.                                                   *
- *                                                                            *
- * 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.jboss.portal.presentation.controller;
-
-import java.io.PrintWriter;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.portal.presentation.client.PresentationContext;
-import org.jboss.portal.presentation.protocol.ShowUIObjectResponse;
-import org.jboss.portal.presentation.impl.PresentationContextImpl;
-import org.jboss.portal.presentation.server.ProcessorRequest;
-import org.jboss.portal.presentation.server.ProcessorResponse;
-import org.jboss.portal.presentation.server.PresentationServer;
-import org.jboss.portal.presentation.protocol.ServerAction;
-import org.jboss.portal.presentation.protocol.ServerResponse;
-import org.jboss.portal.presentation.protocol.ViewUIObjectAction;
-import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.content.WindowContent;
-
-import org.jboss.portal.server.RequestController;
-import org.jboss.portal.server.ServerException;
-import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.ServerInvocationContext;
-
-
-/**
- * The UIServer is responsible for generating the output that is sent back to the client based on the Portal state of a particular Portal Request
- * 
- * The UIServer provides various UI level services like Page Aggregation, Page Layout, Web 2.0 client interactions etc.
- * 
- * Typically the Core component of the Portal delegates all UI specific functions to this component
- * 
- * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
- *
- */
-public class UIController implements RequestController
-{
-   /**
-    * 
-    */
-   private PresentationServer presentationServer = null;
-      
-   
-   /**
-    * 
-    *
-    */
-   public UIController()
-   {      
-   }
-      
-   
-   /**
-    * handle is the entry point for handling an incoming Portal request. The request is handed over
-    * from the Http Layer via the main Portal Servlet
-    *
-    */  
-   public void handle(ServerInvocation invocation) throws ServerException
-   { 
-      try
-      { 
-         HttpServletRequest request = invocation.getServerContext().getClientRequest();
-         
-         /**
-          * TODO: decouple the implementation via factory pattern
-          */         
-         PresentationContext presentationContext = new PresentationContextImpl(this.presentationServer,
-         invocation);
-         request.setAttribute("requestContext", presentationContext);
-         
-         /**
-          * TODO: move this functionality to another component like a UIPresenter etc
-          */
-         ServerAction serverAction = this.getServerAction(presentationContext, invocation);
-         
-         ProcessorRequest processorRequest = new ProcessorRequest(serverAction);         
-         ProcessorResponse processorResponse = this.presentationServer.getProcessor().process(presentationContext,
-         processorRequest);
-                  
-         //Process the response from the Processor
-         ServerResponse serverResponse = processorResponse.getResponse();
-         this.handle(presentationContext, serverResponse, invocation);
-      }
-      catch(Exception e)
-      {
-         throw new ServerException(e);
-      }
-   }   
-   
-   /**
-    * 
-    * @param serverResponse
-    * @throws ServerException
-    */
-   private void handle(PresentationContext presentationContext, ServerResponse serverResponse, ServerInvocation invocation) throws ServerException
-   {
-      try
-      {
-         HttpServletResponse response = invocation.getServerContext().getClientResponse();
-         if(serverResponse instanceof ShowUIObjectResponse)
-         {
-            ShowUIObjectResponse show = (ShowUIObjectResponse)serverResponse;
-            String targetId = show.getTargetId();
-            
-            //Load the objects in the UITree            
-            UIObject uiObject = presentationContext.getUIContext().getObject(targetId);
-            
-            if(uiObject instanceof UIPage)
-            {
-               UIPage page = (UIPage)uiObject;
-               //Populate the state of the Windows in the Page that is being displayed
-               //inside the UITree
-               List<UIObject> windows = page.getChildren();
-               if(windows != null)
-               {
-                  for(int i=0; i<windows.size(); i++)
-                  {
-                     UIObject cour = windows.get(i);
-                     
-                     if(cour instanceof UIWindow)
-                     {
-                        UIWindow window = (UIWindow)cour;
-                        WindowContent windowContent = this.presentationServer.render(presentationContext, window);
-                        
-                        /**
-                         * TODO: decouple this from the model implementation by moving the functinality
-                         * to another component like a UIPresenter etc
-                         */
-                        ((org.jboss.portal.presentation.impl.model.UIWindowImpl)window).
-                        setContent(windowContent);
-                     }
-                  }
-               }               
-               this.render(response.getWriter(), presentationContext.getUIContext(), targetId);
-            }
-         }
-      }
-      catch(Exception e)
-      {
-         throw new ServerException(e);
-      }
-   }
-   
-   /**
-    * 
-    *
-    */
-   public void start()
-   {
-      
-   }
-   
-   /**
-    * 
-    *
-    */
-   public void stop()
-   {
-      
-   }
-   //-----------------------------------------------------------------------------------------------------------------------------------------------------------
-   /**
-    * 
-    */
-   public PresentationServer getPresentationServer()
-   {
-      return presentationServer;
-   }
-
-   /**
-    * 
-    * @param presentationServer
-    */
-   public void setPresentationServer(PresentationServer presentationServer)
-   {
-      this.presentationServer = presentationServer;
-   }  
-   //--------------------------------------------------------------------------------------------------------------------------------------------------------------
-   /**
-    * 
-    */
-   private ServerAction getServerAction(PresentationContext presentationContext, ServerInvocation invocation)
-   {
-      ServerAction serverAction = null;
-      
-      ServerInvocationContext invocationContext = invocation.getServerContext();
-      HttpServletRequest request = invocationContext.getClientRequest();
-            
-      //Just use ViewUIObject command for now until URL interpretation/mapping
-      //to ServiceAction is implemented
-      serverAction = new ViewUIObjectAction("/default/default");
-            
-      /*if(targetPortalObject instanceof UIPage)
-      {         
-         serverAction = new ViewUIObjectAction(targetPortalObject.getId());
-      }
-      else if(targetPortalObject instanceof UIWindow)
-      {
-         if(request.getMethod().equals("GET"))
-         {
-            GetActivation get = new GetActivation();
-            get.setUrl(request.getRequestURL().toString());
-            get.setContentType(invocationContext.getMediaType());
-            get.setQueryParameters(invocationContext.getQueryParameterMap());
-            get.setPortal(targetPortal);
-            get.setTarget(targetPortalObject);
-            serverAction = get;
-         }
-         else if(request.getMethod().equals("POST"))
-         {
-            PostActivation post = new PostActivation();
-            post.setUrl(request.getRequestURL().toString());
-            post.setContentType(invocationContext.getMediaType());
-            post.setQueryParameters(invocationContext.getQueryParameterMap());
-            post.setBodyParameters(invocationContext.getBodyParameterMap());
-            post.setPortal(targetPortal);
-            post.setTarget(targetPortalObject);
-            serverAction = post;
-         }
-      }*/
-      
-      return serverAction;
-   }
-   
-   /**
-    * 
-    * @param portalRequestPath
-    * @return
-    */
-   /*private UIPortal getTargetPortal(RequestContext requestContext,String portalRequestPath)
-   {
-      UIPortal targetPortal = null;
-      
-      //Parse the portalRequestPath and find the targetted Portal           
-      StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
-      StringBuffer buffer = new StringBuffer("/");
-      while(st.hasMoreTokens())
-      {
-         String token = st.nextToken();         
-         buffer.append(token);
-         String id = buffer.toString();
-         ObjectState objectState = this.presentationServer.getModelLoader().loadState(id);
-         if(objectState != null && objectState.getType() == UIPortal.class)
-         {
-            targetPortal = (UIPortal)requestContext.getUIContext().getObject(id);
-            break;
-         }
-         buffer.append("/");
-      }
-      
-      return targetPortal;
-   }*/
-   
-   /**
-    * 
-    * @param portalRequestPath
-    * @return
-    */
-   /*private UIObject getTargetPortalObject(RequestContext requestContext,String portalRequestPath)
-   {
-      UIObject targetPortalObject = null;
-      
-      //Parse the portalRequestPath and find the targetted Portal Object (Page or Window)           
-      StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
-      StringBuffer buffer = new StringBuffer("/");
-      while(st.hasMoreTokens())
-      {
-         String token = st.nextToken();         
-         buffer.append(token);
-         String id = buffer.toString();
-         ObjectState objectState = this.presentationServer.getModelLoader().loadState(id);
-         if(objectState != null)
-         {
-            if(objectState.getType() == UIPage.class)
-            {
-               targetPortalObject = (UIPage)requestContext.getUIContext().getObject(id);
-            }
-            else if(objectState.getType() == UIWindow.class)
-            {
-               targetPortalObject = (UIWindow)requestContext.getUIContext().getObject(id);
-            }
-         }
-         buffer.append("/");
-      }
-      
-      return targetPortalObject;
-   }*/
-   //-----------------------------------------------------------------------------------------------------------------------------------------------------------
-   /**
-    * TODO: this should be used only in classic UI case...eventually when Controller is abstracted, this will be moved to
-    * the ClassicController implementation
-    */
-   private void render(PrintWriter clientConnection, UIContext uiContext, String targetId)
-   {         
-      StringBuffer responseBuffer = new StringBuffer();
-      UIObject uiObject = (UIObject)uiContext.getObject(targetId);
-      
-      //Display the page to the client
-      if(uiObject instanceof UIPage)
-      {
-         UIPage page = (UIPage)uiObject;
-         List<UIObject> windows = page.getChildren();
-         for(int i=0; i<windows.size(); i++)
-         {
-            UIObject cour = windows.get(i);
-            if(cour instanceof UIWindow)
-            {
-               org.jboss.portal.presentation.impl.model.UIWindowImpl window = (org.jboss.portal.presentation.impl.model.UIWindowImpl)cour;
-               if(window.getContent() != null)
-               {
-                  responseBuffer.append("<div>");
-                  responseBuffer.append("<div id=\"title\">"+window.getContent().getTitle()+"</div>");
-                  responseBuffer.append("<div id=\"content\">"+window.getContent().getMarkup()+"</div>");
-                  responseBuffer.append("</div><br/><br/>");
-               }
-            }
-         }
-      }
-      
-      //Create the final output...Also hardcoded without any preprocessing/postprocessing etc
-      StringBuffer buffer = new StringBuffer();      
-      buffer.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>JBoss Portal UIServer</title><link rel=\"stylesheet\" id=\"dyna_css\" href=\"/portal-ajax/dyna/style.css\" type=\"text/css\"/><link rel=\"stylesheet\" type=\"text/css\" id=\"main_css\" href=\"/portal-core/themes/renaissance/portal_style.css\"/><link rel=\"shortcut icon\" href=\"/portal-core/themes/renaissance/images/favicon.ico\" /><link rel=\"icon\" type=\"image/gif\" href=\"/portal-core/themes/renaissance/images/animated_favicon1.gif\" /></head><body id=\"body\">\n");
-      buffer.append(responseBuffer.toString());
-      buffer.append("</body></html>\n");
-      
-      
-      //Sending the results back to the Client
-      clientConnection.write(buffer.toString());
-      clientConnection.flush();
-   }
-
-   // ---------All these are just helper methods for the prototype-----------------------------------------------------------------------------------------------
-   //----It containts mostly hard coded logic for the prototype-------------------------------------------------------------------------------------------------
-   /**
-    *
-    */
-   /*private Object[] getFlexibleGridLayoutManager(Page pageResult)
-   {
-
-      Page page = new Page();
-      Container header = new Container("header");
-      Container leftPanel = new Container("leftPanel");
-      Container mainPanel = new Container("mainPanel");
-      Window headerTabsWindow = new Window("header-tabs-window");
-      Window menuWindow = new Window("menu-window");
-      Window leftPanelWindow1 = new Window("left-panel-window1");
-      Window leftPanelWindow2 = new Window("left-panel-window2");
-      Window mainPanelWindow = new Window("main-panel-window");
-      header.addComponent(headerTabsWindow);
-      header.addComponent(menuWindow);
-      leftPanel.addComponent(leftPanelWindow1);
-      leftPanel.addComponent(leftPanelWindow2);
-      mainPanel.addComponent(mainPanelWindow);
-
-      //Setup the Grid for headerTabs container
-      page.addContainer(header);
-      FlexibleGrid headerGrid = this.getGrid("header", 1, 2);
-      FlexibleGridConstraints[] headerTabConstraints  = { this.getConstraints("header-tabs-window", "100", 0, 0, 10, 0, 0, 0),
-      this.getConstraints("menu-window", "100", 0, 0, 0, 0, 0, 1) };
-      headerGrid.setConstraints(headerTabConstraints);
-
-      //Setup the Grid for left panel container
-      page.addContainer(leftPanel);
-      FlexibleGrid leftPanelGrid = this.getGrid("leftPanel", 2, 1);
-      FlexibleGridConstraints[] leftPanelConstraints  = { this.getConstraints("left-panel-window1", "75", 0, 0, 0, 0, 0, 0),
-      this.getConstraints("left-panel-window2", "75", 0, 0, 0, 0, 1, 0) };
-      leftPanelGrid.setConstraints(leftPanelConstraints);
-
-      //Setup the Grid for main panel container
-      page.addContainer(mainPanel);
-      FlexibleGrid mainPanelGrid = this.getGrid("mainPanel", 1, 1);
-      FlexibleGridConstraints[] mainPanelConstraints  = { this.getConstraints("main-panel-window", "100", 0, 0, 0, 0, 0, 0) };
-      mainPanelGrid.setConstraints(mainPanelConstraints);
-
-      //Setup the FlexibleGrid Layout Manager with the different grids
-      FlexibleGrid[] row1 = { headerGrid };
-      FlexibleGrid[] row2 = { leftPanelGrid, mainPanelGrid };
-      FlexibleGridLayoutManager layoutManager = new FlexibleGridLayoutManager();
-      layoutManager.addRowOfGrids(row1);
-      layoutManager.addRowOfGrids(row2);
-
-      //Populate the grid windows with proper content
-      List windows = pageResult.getWindows();
-      int counter = 0;
-      for(Iterator itr=windows.iterator();itr.hasNext();)
-      {
-         Window result = (Window)itr.next();
-
-         switch(counter)
-         {
-            case 0:
-               leftPanelWindow1.setContent(result.getContent());
-            break;
-
-            case 1:
-               leftPanelWindow2.setContent(result.getContent());
-            break;
-
-            case 2:
-               mainPanelWindow.setContent(result.getContent());
-            break;
-
-            case 3:
-               menuWindow.setContent(result.getContent());
-            break;
-
-            case 4:
-               headerTabsWindow.setContent(result.getContent());
-            break;
-         }
-
-         counter++;
-      }
-
-      return new Object[]{page, layoutManager};
-   }*/
-
-
-   /**
-    *
-    * @param containerId
-    * @param rows
-    * @param columns
-    * @return
-    */
-   /*private FlexibleGrid getGrid(String containerId,int rows, int columns)
-   {
-      FlexibleGrid grid = new FlexibleGrid(containerId);
-      grid.setRows(rows);
-      grid.setColumns(columns);
-      return grid;
-   }*/
-
-   /**
-    *
-    * @param componentId
-    * @param widthPercentage
-    * @param top
-    * @param bottom
-    * @param left
-    * @param right
-    */
-   /*private FlexibleGridConstraints getConstraints(String componentId, String widthPercentage, int top, int bottom, int left, int right, int row, int column)
-   {
-      FlexibleGridConstraints constraints = new FlexibleGridConstraints();
-      constraints.setComponentId(componentId);
-      constraints.setWidthPercentage(widthPercentage);
-      constraints.setRow(row);
-      constraints.setColumn(column);
-      constraints.setTop(top);
-      constraints.setBottom(bottom);
-      constraints.setLeft(left);
-      constraints.setRight(right);
-      return constraints;
-   }*/
-
-   /**
-    *
-    * @param pageResult
-    * @return
-    */
-   /*private Object[] getRegionBasedLayoutManager(Page pageResult)
-   {
-      Page page = new Page();
-      Container left = new Container("left");
-      Container center = new Container("center");
-      page.addContainer(left);
-      page.addContainer(center);
-
-      //Populate the grid windows with proper content
-      List windows = pageResult.getWindows();
-      int counter = 0;
-      for(Iterator itr=windows.iterator();itr.hasNext();)
-      {
-         Window result = (Window)itr.next();
-         Window uiWindow = new Window(result.getId());
-         uiWindow.setContent(result.getContent());
-         switch(counter)
-         {
-            case 0:
-               left.addComponent(uiWindow);
-            break;
-
-            case 1:
-               left.addComponent(uiWindow);
-            break;
-
-            case 2:
-               center.addComponent(uiWindow);
-            break;
-
-            case 3:
-               center.addComponent(uiWindow);
-            break;
-
-            case 4:
-               left.addComponent(uiWindow);
-            break;
-         }
-
-         counter++;
-      }
-
-      RegionLayoutManager layoutManager = new RegionLayoutManager();
-      RegionConstraints leftConstraints = new RegionConstraints("left", RegionConstraints.LEFT);
-      RegionConstraints centerConstraints = new RegionConstraints("center", RegionConstraints.CENTER);
-      layoutManager.addRegionConstraints(leftConstraints);
-      layoutManager.addRegionConstraints(centerConstraints);
-
-      return new Object[]{page, layoutManager};
-   }*/
-
-}

Copied: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java (from rev 9017, branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/controller/UIController.java)
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java	                        (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/client/controller/UIController.java	2007-11-19 00:37:38 UTC (rev 9018)
@@ -0,0 +1,581 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * 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.jboss.portal.presentation.client.controller;
+
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.portal.presentation.client.PresentationContext;
+import org.jboss.portal.presentation.protocol.ShowUIObjectResponse;
+import org.jboss.portal.presentation.impl.PresentationContextImpl;
+import org.jboss.portal.presentation.server.ProcessorRequest;
+import org.jboss.portal.presentation.server.ProcessorResponse;
+import org.jboss.portal.presentation.server.PresentationServer;
+import org.jboss.portal.presentation.protocol.ServerAction;
+import org.jboss.portal.presentation.protocol.ServerResponse;
+import org.jboss.portal.presentation.protocol.ViewUIObjectAction;
+import org.jboss.portal.presentation.protocol.GetActivation;
+import org.jboss.portal.presentation.protocol.PostActivation;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.model.content.WindowContent;
+
+import org.jboss.portal.server.RequestController;
+import org.jboss.portal.server.ServerException;
+import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portal.server.ServerInvocationContext;
+
+/**
+ * The UIServer is responsible for generating the output that is sent back to the client based on the Portal state of a particular Portal Request
+ * 
+ * The UIServer provides various UI level services like Page Aggregation, Page Layout, Web 2.0 client interactions etc.
+ * 
+ * Typically the Core component of the Portal delegates all UI specific functions to this component
+ * 
+ * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
+ *
+ */
+public class UIController implements RequestController
+{
+   /**
+    * 
+    */
+   private PresentationServer presentationServer = null;
+      
+   
+   /**
+    * 
+    *
+    */
+   public UIController()
+   {      
+   }
+      
+   
+   /**
+    * handle is the entry point for handling an incoming Portal request. The request is handed over
+    * from the Http Layer via the main Portal Servlet
+    *
+    */  
+   public void handle(ServerInvocation invocation) throws ServerException
+   { 
+      try
+      { 
+         HttpServletRequest request = invocation.getServerContext().getClientRequest();
+         
+         /**
+          * TODO: decouple the implementation via factory pattern
+          */         
+         PresentationContext presentationContext = new PresentationContextImpl(this.presentationServer,
+         invocation);
+         request.setAttribute("requestContext", presentationContext);
+         
+         /**
+          * TODO: move this functionality to another component like a UIPresenter etc
+          */
+         ServerAction serverAction = this.getServerAction(presentationContext, invocation);
+         
+         ProcessorRequest processorRequest = new ProcessorRequest(serverAction);         
+         ProcessorResponse processorResponse = this.presentationServer.getProcessor().process(presentationContext,
+         processorRequest);
+                  
+         //Process the response from the Processor
+         ServerResponse serverResponse = processorResponse.getResponse();
+         this.handle(presentationContext, serverResponse, invocation);
+      }
+      catch(Exception e)
+      {
+         throw new ServerException(e);
+      }
+   }   
+   
+   /**
+    * 
+    * @param serverResponse
+    * @throws ServerException
+    */
+   private void handle(PresentationContext presentationContext, ServerResponse serverResponse, ServerInvocation invocation) throws ServerException
+   {
+      try
+      {
+         HttpServletResponse response = invocation.getServerContext().getClientResponse();
+         if(serverResponse instanceof ShowUIObjectResponse)
+         {
+            ShowUIObjectResponse show = (ShowUIObjectResponse)serverResponse;
+            String targetId = show.getTargetId();
+            
+            //Load the objects in the UITree            
+            UIObject uiObject = presentationContext.getUIContext().getObject(targetId);
+            
+            if(uiObject instanceof UIPage)
+            {
+               UIPage page = (UIPage)uiObject;
+               //Populate the state of the Windows in the Page that is being displayed
+               //inside the UITree
+               List<UIObject> windows = page.getChildren();
+               if(windows != null)
+               {
+                  for(int i=0; i<windows.size(); i++)
+                  {
+                     UIObject cour = windows.get(i);
+                     
+                     if(cour instanceof UIWindow)
+                     {
+                        UIWindow window = (UIWindow)cour;
+                        WindowContent windowContent = this.presentationServer.render(presentationContext, window);
+                        
+                        /**
+                         * TODO: decouple this from the model implementation by moving the functinality
+                         * to another component like a UIPresenter etc
+                         */
+                        ((org.jboss.portal.presentation.impl.model.UIWindowImpl)window).
+                        setContent(windowContent);
+                     }
+                  }
+               }               
+               this.render(response.getWriter(), presentationContext.getUIContext(), targetId);
+            }
+         }
+      }
+      catch(Exception e)
+      {
+         throw new ServerException(e);
+      }
+   }
+   
+   /**
+    * 
+    *
+    */
+   public void start()
+   {
+      
+   }
+   
+   /**
+    * 
+    *
+    */
+   public void stop()
+   {
+      
+   }
+   //-----------------------------------------------------------------------------------------------------------------------------------------------------------
+   /**
+    * 
+    */
+   public PresentationServer getPresentationServer()
+   {
+      return presentationServer;
+   }
+
+   /**
+    * 
+    * @param presentationServer
+    */
+   public void setPresentationServer(PresentationServer presentationServer)
+   {
+      this.presentationServer = presentationServer;
+   }  
+   //--------------------------------------------------------------------------------------------------------------------------------------------------------------
+   /**
+    * 
+    */
+   private ServerAction getServerAction(PresentationContext presentationContext, ServerInvocation invocation)
+   {
+      ServerInvocationContext invocationContext = invocation.getServerContext();
+      String requestPath = invocation.getServerContext().getPortalRequestPath();
+
+      //
+      if (requestPath.startsWith("/invoke/"))
+      {
+         UIObject target = presentationContext.getUIContext();
+
+         //
+         int from = "/invoke/".length();
+         while (true)
+         {
+            int pos = requestPath.indexOf('/', from);
+            if (pos == -1)
+            {
+               String name = requestPath.substring(from);
+               target = target.getChild(name);
+               break;
+            }
+            else
+            {
+               String name = requestPath.substring(from, pos);
+               target = target.getChild(name);
+            }
+            if (target == null)
+            {
+               break;
+            }
+            from = pos + 1;
+         }
+
+         //
+         if (target != null)
+         {
+            Map queryParameters = invocationContext.getQueryParameterMap();
+            Map bodyParameters = invocationContext.getBodyParameterMap();
+            if (bodyParameters != null)
+            {
+               return new PostActivation(target.getId(), queryParameters, bodyParameters);
+            }
+            else
+            {
+               return new GetActivation(target.getId(), queryParameters);
+            }
+         }
+      }
+            
+      //Just use ViewUIObject command for now until URL interpretation/mapping
+      //to ServiceAction is implemented
+      return new ViewUIObjectAction("/default/default");
+
+      /*if(targetPortalObject instanceof UIPage)
+      {         
+         serverAction = new ViewUIObjectAction(targetPortalObject.getId());
+      }
+      else if(targetPortalObject instanceof UIWindow)
+      {
+         if(request.getMethod().equals("GET"))
+         {
+            GetActivation get = new GetActivation();
+            get.setUrl(request.getRequestURL().toString());
+            get.setContentType(invocationContext.getMediaType());
+            get.setQueryParameters(invocationContext.getQueryParameterMap());
+            get.setPortal(targetPortal);
+            get.setTarget(targetPortalObject);
+            serverAction = get;
+         }
+         else if(request.getMethod().equals("POST"))
+         {
+            PostActivation post = new PostActivation();
+            post.setUrl(request.getRequestURL().toString());
+            post.setContentType(invocationContext.getMediaType());
+            post.setQueryParameters(invocationContext.getQueryParameterMap());
+            post.setBodyParameters(invocationContext.getBodyParameterMap());
+            post.setPortal(targetPortal);
+            post.setTarget(targetPortalObject);
+            serverAction = post;
+         }
+      }*/
+   }
+   
+   /**
+    * 
+    * @param portalRequestPath
+    * @return
+    */
+   /*private UIPortal getTargetPortal(RequestContext requestContext,String portalRequestPath)
+   {
+      UIPortal targetPortal = null;
+      
+      //Parse the portalRequestPath and find the targetted Portal           
+      StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
+      StringBuffer buffer = new StringBuffer("/");
+      while(st.hasMoreTokens())
+      {
+         String token = st.nextToken();         
+         buffer.append(token);
+         String id = buffer.toString();
+         ObjectState objectState = this.presentationServer.getModelLoader().loadState(id);
+         if(objectState != null && objectState.getType() == UIPortal.class)
+         {
+            targetPortal = (UIPortal)requestContext.getUIContext().getObject(id);
+            break;
+         }
+         buffer.append("/");
+      }
+      
+      return targetPortal;
+   }*/
+   
+   /**
+    * 
+    * @param portalRequestPath
+    * @return
+    */
+   /*private UIObject getTargetPortalObject(RequestContext requestContext,String portalRequestPath)
+   {
+      UIObject targetPortalObject = null;
+      
+      //Parse the portalRequestPath and find the targetted Portal Object (Page or Window)           
+      StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
+      StringBuffer buffer = new StringBuffer("/");
+      while(st.hasMoreTokens())
+      {
+         String token = st.nextToken();         
+         buffer.append(token);
+         String id = buffer.toString();
+         ObjectState objectState = this.presentationServer.getModelLoader().loadState(id);
+         if(objectState != null)
+         {
+            if(objectState.getType() == UIPage.class)
+            {
+               targetPortalObject = (UIPage)requestContext.getUIContext().getObject(id);
+            }
+            else if(objectState.getType() == UIWindow.class)
+            {
+               targetPortalObject = (UIWindow)requestContext.getUIContext().getObject(id);
+            }
+         }
+         buffer.append("/");
+      }
+      
+      return targetPortalObject;
+   }*/
+   //-----------------------------------------------------------------------------------------------------------------------------------------------------------
+   /**
+    * TODO: this should be used only in classic UI case...eventually when Controller is abstracted, this will be moved to
+    * the ClassicController implementation
+    */
+   private void render(PrintWriter clientConnection, UIContext uiContext, String targetId)
+   {         
+      StringBuffer responseBuffer = new StringBuffer();
+      UIObject uiObject = (UIObject)uiContext.getObject(targetId);
+      
+      //Display the page to the client
+      if(uiObject instanceof UIPage)
+      {
+         UIPage page = (UIPage)uiObject;
+         List<UIObject> windows = page.getChildren();
+         for(int i=0; i<windows.size(); i++)
+         {
+            UIObject cour = windows.get(i);
+            if(cour instanceof UIWindow)
+            {
+               org.jboss.portal.presentation.impl.model.UIWindowImpl window = (org.jboss.portal.presentation.impl.model.UIWindowImpl)cour;
+               if(window.getContent() != null)
+               {
+                  responseBuffer.append("<div>");
+                  responseBuffer.append("<div id=\"title\">"+window.getContent().getTitle()+"</div>");
+                  responseBuffer.append("<div id=\"content\">"+window.getContent().getMarkup()+"</div>");
+                  responseBuffer.append("</div><br/><br/>");
+               }
+            }
+         }
+      }
+      
+      //Create the final output...Also hardcoded without any preprocessing/postprocessing etc
+      StringBuffer buffer = new StringBuffer();      
+      buffer.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>JBoss Portal UIServer</title><link rel=\"stylesheet\" id=\"dyna_css\" href=\"/portal-ajax/dyna/style.css\" type=\"text/css\"/><link rel=\"stylesheet\" type=\"text/css\" id=\"main_css\" href=\"/portal-core/themes/renaissance/portal_style.css\"/><link rel=\"shortcut icon\" href=\"/portal-core/themes/renaissance/images/favicon.ico\" /><link rel=\"icon\" type=\"image/gif\" href=\"/portal-core/themes/renaissance/images/animated_favicon1.gif\" /></head><body id=\"body\">\n");
+      buffer.append(responseBuffer.toString());
+      buffer.append("</body></html>\n");
+      
+      
+      //Sending the results back to the Client
+      clientConnection.write(buffer.toString());
+      clientConnection.flush();
+   }
+
+   // ---------All these are just helper methods for the prototype-----------------------------------------------------------------------------------------------
+   //----It containts mostly hard coded logic for the prototype-------------------------------------------------------------------------------------------------
+   /**
+    *
+    */
+   /*private Object[] getFlexibleGridLayoutManager(Page pageResult)
+   {
+
+      Page page = new Page();
+      Container header = new Container("header");
+      Container leftPanel = new Container("leftPanel");
+      Container mainPanel = new Container("mainPanel");
+      Window headerTabsWindow = new Window("header-tabs-window");
+      Window menuWindow = new Window("menu-window");
+      Window leftPanelWindow1 = new Window("left-panel-window1");
+      Window leftPanelWindow2 = new Window("left-panel-window2");
+      Window mainPanelWindow = new Window("main-panel-window");
+      header.addComponent(headerTabsWindow);
+      header.addComponent(menuWindow);
+      leftPanel.addComponent(leftPanelWindow1);
+      leftPanel.addComponent(leftPanelWindow2);
+      mainPanel.addComponent(mainPanelWindow);
+
+      //Setup the Grid for headerTabs container
+      page.addContainer(header);
+      FlexibleGrid headerGrid = this.getGrid("header", 1, 2);
+      FlexibleGridConstraints[] headerTabConstraints  = { this.getConstraints("header-tabs-window", "100", 0, 0, 10, 0, 0, 0),
+      this.getConstraints("menu-window", "100", 0, 0, 0, 0, 0, 1) };
+      headerGrid.setConstraints(headerTabConstraints);
+
+      //Setup the Grid for left panel container
+      page.addContainer(leftPanel);
+      FlexibleGrid leftPanelGrid = this.getGrid("leftPanel", 2, 1);
+      FlexibleGridConstraints[] leftPanelConstraints  = { this.getConstraints("left-panel-window1", "75", 0, 0, 0, 0, 0, 0),
+      this.getConstraints("left-panel-window2", "75", 0, 0, 0, 0, 1, 0) };
+      leftPanelGrid.setConstraints(leftPanelConstraints);
+
+      //Setup the Grid for main panel container
+      page.addContainer(mainPanel);
+      FlexibleGrid mainPanelGrid = this.getGrid("mainPanel", 1, 1);
+      FlexibleGridConstraints[] mainPanelConstraints  = { this.getConstraints("main-panel-window", "100", 0, 0, 0, 0, 0, 0) };
+      mainPanelGrid.setConstraints(mainPanelConstraints);
+
+      //Setup the FlexibleGrid Layout Manager with the different grids
+      FlexibleGrid[] row1 = { headerGrid };
+      FlexibleGrid[] row2 = { leftPanelGrid, mainPanelGrid };
+      FlexibleGridLayoutManager layoutManager = new FlexibleGridLayoutManager();
+      layoutManager.addRowOfGrids(row1);
+      layoutManager.addRowOfGrids(row2);
+
+      //Populate the grid windows with proper content
+      List windows = pageResult.getWindows();
+      int counter = 0;
+      for(Iterator itr=windows.iterator();itr.hasNext();)
+      {
+         Window result = (Window)itr.next();
+
+         switch(counter)
+         {
+            case 0:
+               leftPanelWindow1.setContent(result.getContent());
+            break;
+
+            case 1:
+               leftPanelWindow2.setContent(result.getContent());
+            break;
+
+            case 2:
+               mainPanelWindow.setContent(result.getContent());
+            break;
+
+            case 3:
+               menuWindow.setContent(result.getContent());
+            break;
+
+            case 4:
+               headerTabsWindow.setContent(result.getContent());
+            break;
+         }
+
+         counter++;
+      }
+
+      return new Object[]{page, layoutManager};
+   }*/
+
+
+   /**
+    *
+    * @param containerId
+    * @param rows
+    * @param columns
+    * @return
+    */
+   /*private FlexibleGrid getGrid(String containerId,int rows, int columns)
+   {
+      FlexibleGrid grid = new FlexibleGrid(containerId);
+      grid.setRows(rows);
+      grid.setColumns(columns);
+      return grid;
+   }*/
+
+   /**
+    *
+    * @param componentId
+    * @param widthPercentage
+    * @param top
+    * @param bottom
+    * @param left
+    * @param right
+    */
+   /*private FlexibleGridConstraints getConstraints(String componentId, String widthPercentage, int top, int bottom, int left, int right, int row, int column)
+   {
+      FlexibleGridConstraints constraints = new FlexibleGridConstraints();
+      constraints.setComponentId(componentId);
+      constraints.setWidthPercentage(widthPercentage);
+      constraints.setRow(row);
+      constraints.setColumn(column);
+      constraints.setTop(top);
+      constraints.setBottom(bottom);
+      constraints.setLeft(left);
+      constraints.setRight(right);
+      return constraints;
+   }*/
+
+   /**
+    *
+    * @param pageResult
+    * @return
+    */
+   /*private Object[] getRegionBasedLayoutManager(Page pageResult)
+   {
+      Page page = new Page();
+      Container left = new Container("left");
+      Container center = new Container("center");
+      page.addContainer(left);
+      page.addContainer(center);
+
+      //Populate the grid windows with proper content
+      List windows = pageResult.getWindows();
+      int counter = 0;
+      for(Iterator itr=windows.iterator();itr.hasNext();)
+      {
+         Window result = (Window)itr.next();
+         Window uiWindow = new Window(result.getId());
+         uiWindow.setContent(result.getContent());
+         switch(counter)
+         {
+            case 0:
+               left.addComponent(uiWindow);
+            break;
+
+            case 1:
+               left.addComponent(uiWindow);
+            break;
+
+            case 2:
+               center.addComponent(uiWindow);
+            break;
+
+            case 3:
+               center.addComponent(uiWindow);
+            break;
+
+            case 4:
+               left.addComponent(uiWindow);
+            break;
+         }
+
+         counter++;
+      }
+
+      RegionLayoutManager layoutManager = new RegionLayoutManager();
+      RegionConstraints leftConstraints = new RegionConstraints("left", RegionConstraints.LEFT);
+      RegionConstraints centerConstraints = new RegionConstraints("center", RegionConstraints.CENTER);
+      layoutManager.addRegionConstraints(leftConstraints);
+      layoutManager.addRegionConstraints(centerConstraints);
+
+      return new Object[]{page, layoutManager};
+   }*/
+
+}




More information about the portal-commits mailing list