[portal-commits] JBoss Portal SVN: r8910 - in branches/UIServer/uiserver/src/main/org/jboss/portal/presentation: service and 1 other directory.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Tue Nov 13 12:51:49 EST 2007


Author: sohil.shah at jboss.com
Date: 2007-11-13 12:51:48 -0500 (Tue, 13 Nov 2007)
New Revision: 8910

Added:
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPoint.java
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPointImpl.java
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/GWTClientFilter.java
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/PortalEntryPoint.java
   branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/UIServer.java
Log:
refactoring

Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPoint.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPoint.java	                        (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPoint.java	2007-11-13 17:51:48 UTC (rev 8910)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * 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.service;
+
+import org.jboss.portal.server.RequestControllerFactory;
+import org.jboss.portal.server.Server;
+import org.jboss.portal.common.invocation.InterceptorStackFactory;
+
+/**
+ * A Utility Service used by different Portal Server Entry Points
+ * 
+ * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
+ *
+ */
+public interface EntryPoint
+{
+   /**
+    * 
+    * @return
+    */
+   public Server getPortalServer();
+   
+   /**
+    * 
+    * @return
+    */
+   public RequestControllerFactory getControllerFactory();
+   
+   /**
+    * 
+    * @return
+    */
+   public InterceptorStackFactory getInterceptorStackFactory();
+   
+   /**
+    * 
+    * @param contentType
+    * @return
+    */
+   public String retrieveMediaType(String contentType);
+}

Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPointImpl.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPointImpl.java	                        (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/EntryPointImpl.java	2007-11-13 17:51:48 UTC (rev 8910)
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * 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.service;
+
+import org.jboss.portal.common.invocation.InterceptorStackFactory;
+import org.jboss.portal.server.RequestControllerFactory;
+import org.jboss.portal.server.Server;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+/**
+ * Implementation of an Entry Point Utility
+ * 
+ * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
+ *
+ */
+public class EntryPointImpl extends AbstractJBossService implements EntryPoint
+{
+   /** The interceptor stack. */
+   private InterceptorStackFactory interceptorStackFactory = null;
+
+   /** The controller for this servlet. */
+   private RequestControllerFactory controllerFactory = null;
+   
+   /**
+    * 
+    */
+   private Server portalServer = null;
+
+         
+   /**
+    * 
+    * @return
+    */
+   public RequestControllerFactory getControllerFactory()
+   {
+      return controllerFactory;
+   }
+
+
+   /**
+    * 
+    * @param controllerFactory
+    */
+   public void setControllerFactory(RequestControllerFactory controllerFactory)
+   {
+      this.controllerFactory = controllerFactory;
+   }
+
+   
+   /**
+    * 
+    * @return
+    */
+   public InterceptorStackFactory getInterceptorStackFactory()
+   {
+      return interceptorStackFactory;
+   }
+
+
+   /**
+    * 
+    * @param interceptorStackFactory
+    */
+   public void setInterceptorStackFactory(
+         InterceptorStackFactory interceptorStackFactory)
+   {
+      this.interceptorStackFactory = interceptorStackFactory;
+   }
+   
+   /**
+    * 
+    * @return
+    */
+   public Server getPortalServer()
+   {
+      return portalServer;
+   }
+
+
+   /**
+    * 
+    * @param portalServer
+    */
+   public void setPortalServer(Server portalServer)
+   {
+      this.portalServer = portalServer;
+   }
+
+
+   /**
+    * 
+    * @param contentType
+    * @return
+    */
+   public String retrieveMediaType(String contentType)
+   {
+      String mediaType = contentType;
+
+      //
+      if (mediaType != null)
+      {
+         // Remove any parameters
+         int index = mediaType.indexOf(';');
+         if (index != -1)
+         {
+            mediaType = contentType.substring(0, index);
+         }
+
+         // Trim
+         mediaType = mediaType.trim();
+
+         // Media type matching is case insensitive, so we convert to lower case
+         mediaType = mediaType.toLowerCase();
+      }
+      return mediaType;
+   }
+}

Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/GWTClientFilter.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/GWTClientFilter.java	                        (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/GWTClientFilter.java	2007-11-13 17:51:48 UTC (rev 8910)
@@ -0,0 +1,154 @@
+/******************************************************************************
+ * 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.service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * This filter is activated or deactivated depending on whether the Portal needs to runs in Ajax mode or Classic Html mode
+ * 
+ * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
+ *
+ */
+public class GWTClientFilter implements Filter
+{
+   /**
+    * 
+    */
+   public void init(FilterConfig arg0) throws ServletException
+   {  
+   }
+   
+   /**
+    * 
+    */
+   public void destroy()
+   {  
+   }
+
+   /**
+    * 
+    */
+   public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
+   { 
+      HttpServletRequest request = (HttpServletRequest)servletRequest;
+      HttpServletResponse response = (HttpServletResponse)servletResponse;
+      String contextPath = request.getContextPath();
+      
+      //Extract the resource that is being accessed
+      String resource = request.getRequestURI().replaceFirst(contextPath, "");
+      while(resource.startsWith("/"))
+      {
+         if(resource.length() > 1)
+         {
+            resource = resource.substring(1);
+         }
+         else
+         {
+            resource = "";
+         }
+      }
+      
+      if(resource == null || resource.trim().length() == 0)
+      {
+         response.sendRedirect("index.html");
+         return;
+      }
+      
+      //Now make sure the resource requested is a GWT resource
+      if(   resource.equals("index.html") ||
+            resource.equals("portal.css") ||
+            resource.equals("mygwt-all.css") ||
+            resource.equals("mygwt-all-gray.css") ||
+            resource.equals("gwt.js") ||
+            resource.equals("prototype.js") ||
+            resource.contains(".cache.") ||
+            resource.contains(".nocache.") ||
+            resource.contains(".gwt.rpc") ||
+            resource.contains("images/default") ||
+            resource.contains("images/gray")
+      )
+      {
+         byte[] gwtResource = this.readContent(resource);
+         response.getOutputStream().write(gwtResource);
+         response.getOutputStream().flush();
+         return;
+      }
+   }
+   
+   /**
+    * 
+    * @param path
+    * @return
+    */
+   private byte[] readContent(String path)
+   {
+      byte[] content = null;
+        
+      InputStream is = null;
+      ByteArrayOutputStream bos = null;
+      try
+      {
+         bos = new ByteArrayOutputStream();
+         is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
+         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);
+            bos.write(cour);
+            bos.flush();
+         }         
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+      finally
+      {
+         if(is != null)
+         {
+            try{is.close();}catch(Exception e){}
+         }
+         if(bos != null)
+         {
+            content = bos.toByteArray();
+            try{bos.close();}catch(Exception e){}
+         }
+      }
+      
+      return content;
+   }
+}

Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/PortalEntryPoint.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/PortalEntryPoint.java	                        (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/PortalEntryPoint.java	2007-11-13 17:51:48 UTC (rev 8910)
@@ -0,0 +1,633 @@
+/******************************************************************************
+ * 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.service;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.UnavailableException;
+
+import org.apache.log4j.Logger;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.portal.common.http.QueryStringParser;
+import org.jboss.portal.common.invocation.InterceptorStackFactory;
+import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.net.URLTools;
+import org.jboss.portal.common.util.Exceptions;
+import org.jboss.portal.server.PortalConstants;
+import org.jboss.portal.server.RequestController;
+import org.jboss.portal.server.RequestControllerDispatcher;
+import org.jboss.portal.server.RequestControllerFactory;
+import org.jboss.portal.server.Server;
+import org.jboss.portal.server.ServerException;
+import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portal.server.ServerInvocationContext;
+import org.jboss.portal.server.ServerRequest;
+import org.jboss.portal.server.ServerResponse;
+import org.jboss.portal.server.impl.ServerInvocationContextImpl;
+import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.presentation.layout.LayoutManager;
+import org.jboss.portal.presentation.impl.classic.layout.FlexibleGrid;
+import org.jboss.portal.presentation.impl.classic.layout.FlexibleGridConstraints;
+import org.jboss.portal.presentation.impl.classic.layout.FlexibleGridLayoutManager;
+import org.jboss.portal.presentation.impl.classic.layout.RegionConstraints;
+import org.jboss.portal.presentation.impl.classic.layout.RegionLayoutManager;
+import org.jboss.portal.presentation.model.Container;
+import org.jboss.portal.presentation.model.Page;
+import org.jboss.portal.presentation.model.Window;
+import org.jboss.portal.presentation.server.ProcessorResponse;
+
+/**
+ * The Portal Server Entry Point for classic html mode
+ * 
+ * @author <a href="mailto:sshah at redhat.com">Sohil Shah</a>
+ *
+ */
+public class PortalEntryPoint extends HttpServlet
+{
+   /**
+    * 
+    */
+   private Logger log = Logger.getLogger(getClass());
+   
+   /** . */
+   private static final int GET_METHOD = 0;
+
+   /** . */
+   private static final int POST_METHOD = 1;
+
+   /** Describes a default servlet mapping. */
+   private static final int DEFAULT_SERVLET_MAPPING = 0;
+
+   /** Describes a root path mapping. */
+   private static final int ROOT_PATH_MAPPING = 1;
+
+   /** Describes a path mapping. */
+   private static final int PATH_MAPPING = 2;
+   
+   /** Are we or not the default servlet ? */
+   private boolean asDefaultServlet = false;
+   
+   /**
+    * 
+    */
+   private EntryPoint entryPoint = null;
+   
+   /** Configure the as default servlet. */
+   public void init() throws ServletException
+   {
+      asDefaultServlet = getAsDefaultServletInitValue();
+      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);
+      }
+   }
+   
+   /**
+    * 
+    */
+   protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      //
+      String servletPath = req.getServletPath();
+      String requestURI = req.getRequestURI();
+      String contextPath = req.getContextPath();
+      
+      String resource = req.getRequestURI().replaceFirst(contextPath, "");
+      while(resource.startsWith("/"))
+      {
+         if(resource.length() > 1)
+         {
+            resource = resource.substring(1);
+         }
+         else
+         {
+            resource = "";
+         }
+      }
+      
+      if(resource == null || resource.trim().length() == 0)
+      {
+         resp.sendRedirect("index.html");
+         return;
+      }
+      
+      int method;
+      if ("GET".equals(req.getMethod()))
+      {
+         method = GET_METHOD;
+      }
+      else if ("POST".equals(req.getMethod()))
+      {
+         method = POST_METHOD;
+      }
+      else
+      {
+         throw new ServletException();
+      }
+
+      // Compute the media type in the content type
+      String mediaType = this.entryPoint.retrieveMediaType(req.getContentType());
+
+      // Only affect the charset encoding if the servlet container will decode the request
+      if (method == POST_METHOD && PortalConstants.APPLICATION_X_WWW_FORM_URLENCODED.equals(mediaType))
+      {
+         // Now we must ensure that we have either an equals or a trailing space after the media-type
+         String characterEncoding = req.getCharacterEncoding();
+         if (characterEncoding == null)
+         {
+            // Set out charset for the portal request
+            req.setCharacterEncoding(PortalConstants.UTF_8.name());
+         }
+         else
+         {
+            Charset charset = Charset.forName(characterEncoding);
+            if (!PortalConstants.UTF_8.equals(charset))
+            {
+               throw new ServletException("Unaccepted charset " + characterEncoding);
+            }
+         }
+      }
+
+      // Determine the mapping we have
+      int mapping = DEFAULT_SERVLET_MAPPING;
+      if (!asDefaultServlet)
+      {
+         if (servletPath.length() == 0)
+         {
+            mapping = ROOT_PATH_MAPPING;
+         }
+         else
+         {
+            mapping = PATH_MAPPING;
+         }
+      }
+
+      // Determine the host for this request
+      String portalHost = req.getServerName();
+
+      // Determine the request path
+      String portalRequestPath = null;
+      String portalContextPath = null;
+      switch (mapping)
+      {
+         case DEFAULT_SERVLET_MAPPING:
+            portalRequestPath = requestURI.substring(contextPath.length());
+            portalContextPath = requestURI.substring(0, contextPath.length());
+            break;
+         case ROOT_PATH_MAPPING:
+            portalRequestPath = requestURI.substring(contextPath.length());
+            portalContextPath = requestURI.substring(0, contextPath.length());
+            break;
+         case PATH_MAPPING:
+            portalRequestPath = requestURI.substring(contextPath.length() + servletPath.length());
+            portalContextPath = requestURI.substring(0, contextPath.length() + servletPath.length());
+            break;
+      }
+
+      // Apply the url decoding
+      portalRequestPath = URLTools.decodeXWWWFormURL(portalRequestPath);
+      portalContextPath = URLTools.decodeXWWWFormURL(portalContextPath);
+
+      //
+      URLContext urlContext = URLContext.newInstance(req.isSecure(), req.getRemoteUser() != null);
+
+      // ***************
+      // ***************
+      // ***************
+      // ***************
+
+      // Parse the query string to have the get parameters
+      // The resulting map has its parameters decoded from the x-www-form-url encoding
+      Map queryParameterMap = Collections.EMPTY_MAP;
+      String queryString = req.getQueryString();
+      if (queryString != null)
+      {
+         queryParameterMap = QueryStringParser.parseQueryString(queryString);
+      }
+
+      //
+      Map bodyParameterMap = null;
+      if (method == POST_METHOD && PortalConstants.APPLICATION_X_WWW_FORM_URLENCODED.equals(mediaType))
+      {
+         bodyParameterMap = Collections.EMPTY_MAP;
+         for (Iterator i = req.getParameterMap().entrySet().iterator(); i.hasNext();)
+         {
+            Map.Entry entry = (Map.Entry)i.next();
+
+            // Get param name
+            String paramName = (String)entry.getKey();
+
+            // Values that are aggregated from the query string and the body
+            String[] paramValues = (String[])entry.getValue();
+
+            // Values decoded from the query string
+            String[] queryValues = (String[])queryParameterMap.get(paramName);
+            if (queryValues != null)
+            {
+               int bodyValuesLength = paramValues.length - queryValues.length;
+               if (bodyValuesLength > 0)
+               {
+                  String[] bodyValues = new String[bodyValuesLength];
+                  System.arraycopy(paramValues, queryValues.length, bodyValues, 0, bodyValuesLength);
+                  if (bodyParameterMap.isEmpty())
+                  {
+                     bodyParameterMap = new HashMap();
+                  }
+                  bodyParameterMap.put(paramName, bodyValues);
+               }
+            }
+            else
+            {
+               if (bodyParameterMap.isEmpty())
+               {
+                  bodyParameterMap = new HashMap();
+               }
+               bodyParameterMap.put(paramName, paramValues);
+            }
+         }
+
+         // Make the map unmodifiable
+         bodyParameterMap = bodyParameterMap.isEmpty() ? bodyParameterMap : Collections.unmodifiableMap(bodyParameterMap);
+      }
+
+      // ***************
+      // ***************
+      // ***************
+      // ***************
+
+      //
+      Server server = this.entryPoint.getPortalServer();
+
+      //
+      ServerInvocationContext invocationCtx = new ServerInvocationContextImpl(
+         req,
+         resp,
+         portalHost,
+         portalRequestPath,
+         portalContextPath,
+         queryParameterMap,
+         bodyParameterMap,
+         urlContext,
+         mediaType);
+
+      //
+      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));
+
+      //
+      try
+      {
+         InterceptorStackFactory stack = this.entryPoint.getInterceptorStackFactory();
+         invocation.invoke(stack.getInterceptorStack());
+         ProcessorResponse processorResponse = (ProcessorResponse)req.getAttribute("processorResponse");
+         if(processorResponse != null)
+         {
+            Page displayedPage = processorResponse.findDisplayedPage();
+            if(displayedPage != null)
+            {
+               this.render(invocation.getServerContext().getClientResponse().getWriter(), 
+               displayedPage);
+            }
+         }
+      }
+      catch (ServerException e)
+      {
+         log.error("Server exception", e);
+         Throwable nested = Exceptions.unwrap(e);
+         throw new ServletException(nested);
+      }
+      catch (InvocationException e)
+      {
+         log.error("Invocation exception", e);
+         Throwable nested = Exceptions.unwrap(e);
+         throw new ServletException(nested);
+      }
+      catch (ServletException e)
+      {
+         throw e;
+      }
+      catch (IOException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         log.error("Unexpected exception", e);
+         Throwable nested = Exceptions.unwrap(e);
+         throw new ServletException(nested);
+      }
+   } 
+   
+   /**
+    * Return the value for the servlet mapping. This implementation get the
+    * value from an init parameter of the servlet called <b>asDefaultServlet</b>
+    */
+   private boolean getAsDefaultServletInitValue()
+   {
+      ServletConfig config = getServletConfig();
+      String value = config.getInitParameter("asDefaultServlet");
+      if ("true".equalsIgnoreCase(value))
+      {
+         log.debug("Servlet loaded as default servlet mapping");
+         return true;
+      }
+      else if ("false".equalsIgnoreCase(value))
+      {
+         log.debug("Servlet loaded as path mapping servlet");
+         return false;
+      }
+      else
+      {
+         log.warn("Servlet mapping cannot be determined with init parameter value="
+                     + value);
+         return false;
+      }
+   }   
+   // ---------All these are just helper methods for the prototype-----------------------------------------------------------------------------------------------
+   //----It containts mostly hard coded logic for the prototype-------------------------------------------------------------------------------------------------
+   /**
+    * Based on the latest design discussion, this method is not needed.
+    * 
+    * This will be an implementation detail of the UIServer processing the Response that is sent back to it
+    * from the Core Portal Processor
+    * 
+    * @param clientConnection
+    * @param page
+    */
+   private void render(PrintWriter clientConnection, Page pageResult)
+   {
+      /**
+       * Special Note: Currently this prototype code and layout configuration including page result creation is hard coded for the purpose
+       * of getting the architecture right
+       * 
+       * In the real implementation, LayoutState would be fetched dynamically based on the Page State/Configuration being rendered
+       * Even type of Client considerations would be handled here
+       * 
+       * Basically the UIServer would delegate functions to its various components and then send back the result to the client
+       * 
+       */      
+      //Some flexible grid layout testing code
+      Object[] gridData = this.getFlexibleGridLayoutManager(pageResult);
+      Page page = (Page)gridData[0];
+      LayoutManager layoutManager = (LayoutManager)gridData[1]; 
+      
+      //Some region layout testing code
+      //Object[] regionData = this.getRegionBasedLayoutManager(pageResult);
+      //Page page = (Page)regionData[0];
+      //LayoutManager layoutManager = (LayoutManager)regionData[1];
+            
+      //Peform Page Layout
+      String output = layoutManager.doLayout(page);
+      
+      
+      //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(output);
+      buffer.append("</body></html>\n");
+      
+      
+      //Sending the results back to the Client
+      clientConnection.write(buffer.toString());
+      clientConnection.flush();
+   }
+   
+   /**
+    * 
+    */
+   private Object[] getFlexibleGridLayoutManager(Page pageResult)
+   {
+      /**
+       * Hard coding the FlexibleGridLayout Management here
+       */
+      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};
+   }
+}

Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/UIServer.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/UIServer.java	                        (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/service/UIServer.java	2007-11-13 17:51:48 UTC (rev 8910)
@@ -0,0 +1,233 @@
+/******************************************************************************
+ * 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.service;
+
+import java.util.StringTokenizer;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+import org.jboss.portal.presentation.RequestContext;
+
+import org.jboss.portal.presentation.model.Portal;
+import org.jboss.portal.presentation.model.PortalObject;
+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.action.server.ServerAction;
+import org.jboss.portal.presentation.action.server.LinkActivation;
+import org.jboss.portal.presentation.action.server.GetActivation;
+import org.jboss.portal.presentation.action.server.PostActivation;
+
+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 UIServer implements RequestController
+{
+   /**
+    * 
+    */
+   private PresentationServer presentationServer = null;
+      
+   
+   /**
+    * 
+    *
+    */
+   public UIServer()
+   {      
+   }
+      
+   
+   /**
+    * 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
+      {                
+         ServerAction serverAction = this.getServerAction(invocation);
+         ProcessorRequest processorRequest = new ProcessorRequest(serverAction, invocation);
+         RequestContext requestContext = null; //Just use null until proper implementation is provided
+         ProcessorResponse processorResponse = this.presentationServer.getProcessor().process(requestContext,
+         processorRequest);
+                  
+         //Go ahead and render to the client based on ProcessorResponse received from the core Portal 
+         if(processorResponse != null)
+         {
+            invocation.getServerContext().getClientRequest().setAttribute("processorResponse", processorResponse);                        
+         }                  
+      }
+      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(ServerInvocation invocation)
+   {
+      ServerAction serverAction = null;
+      
+      ServerInvocationContext invocationContext = invocation.getServerContext();
+      HttpServletRequest request = invocationContext.getClientRequest();
+      if(request.getMethod().equals("GET"))
+      {
+         GetActivation get = new GetActivation();
+         get.setUrl(request.getRequestURL().toString());
+         get.setContentType(invocationContext.getMediaType());
+         get.setQueryParameters(invocationContext.getQueryParameterMap());
+         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());
+         serverAction = post;
+      }  
+      
+      //If this is a link activation, then interpret the Portal and the PortalObject that
+      //this link is targetted for
+      if(serverAction instanceof LinkActivation)
+      {
+         String portalRequestPath = invocation.getServerContext().getPortalRequestPath();
+         
+         //Process the incoming request and produce a proper ProcessorRequest to be
+         //processed by the core Portal component            
+         Portal portal = null;
+         PortalObject target = null;
+         StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
+         StringBuffer buffer = new StringBuffer("/");
+         while(st.hasMoreTokens())
+         {
+            String token = st.nextToken();         
+            if(portal == null)
+            {
+               portal = this.presentationServer.getPortalObjectReader().findPortal(token);
+               if(portal != null)
+               {
+                  buffer.append(token);
+                  if(st.hasMoreTokens())
+                  {
+                     buffer.append("/");
+                  }
+               }
+            }
+            else
+            {
+               buffer.append(token);
+               String id = buffer.toString();
+               if(st.hasMoreTokens())
+               {
+                  buffer.append("/");
+               }
+               
+               if(target == null)
+               {
+                  target = portal.findChild(id);
+                  if(target == null)
+                  {
+                     target = this.presentationServer.getPortalObjectReader().findPortalObject(portal, id);
+                  }
+               }
+               else
+               {
+                  PortalObject cour = target.findChild(id);
+                  if(cour == null)
+                  {
+                     target = this.presentationServer.getPortalObjectReader().findPortalObject(target, id);
+                  }
+                  else
+                  {
+                     target = cour;
+                  }
+               }
+            }         
+         }
+         
+         //Setting up the proper targets for this link
+         ((LinkActivation)serverAction).setPortal(portal);
+         ((LinkActivation)serverAction).setTarget(target);
+      }
+      
+      
+      return serverAction;
+   }
+   
+   
+}




More information about the portal-commits mailing list