From portal-commits at lists.jboss.org Tue Nov 13 12:54:40 2007 Content-Type: multipart/mixed; boundary="===============0071251952900699961==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r8910 - in branches/UIServer/uiserver/src/main/org/jboss/portal/presentation: service and 1 other directory. Date: Tue, 13 Nov 2007 12:51:49 -0500 Message-ID: --===============0071251952900699961== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: sohil.shah(a)jboss.com Date: 2007-11-13 12:51:48 -0500 (Tue, 13 Nov 2007) New Revision: 8910 Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servic= e/ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servic= e/EntryPoint.java branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servic= e/EntryPointImpl.java branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servic= e/GWTClientFilter.java branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servic= e/PortalEntryPoint.java branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servic= e/UIServer.java Log: refactoring Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/se= rvice/EntryPoint.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/EntryPoint.java (rev 0) +++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/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 Sohil Shah + * + */ +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/se= rvice/EntryPointImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/EntryPointImpl.java (rev 0) +++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/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 Sohil Shah + * + */ +public class EntryPointImpl extends AbstractJBossService implements EntryP= oint +{ + /** The interceptor stack. */ + private InterceptorStackFactory interceptorStackFactory =3D null; + + /** The controller for this servlet. */ + private RequestControllerFactory controllerFactory =3D null; + = + /** + * = + */ + private Server portalServer =3D null; + + = + /** + * = + * @return + */ + public RequestControllerFactory getControllerFactory() + { + return controllerFactory; + } + + + /** + * = + * @param controllerFactory + */ + public void setControllerFactory(RequestControllerFactory controllerFac= tory) + { + this.controllerFactory =3D controllerFactory; + } + + = + /** + * = + * @return + */ + public InterceptorStackFactory getInterceptorStackFactory() + { + return interceptorStackFactory; + } + + + /** + * = + * @param interceptorStackFactory + */ + public void setInterceptorStackFactory( + InterceptorStackFactory interceptorStackFactory) + { + this.interceptorStackFactory =3D interceptorStackFactory; + } + = + /** + * = + * @return + */ + public Server getPortalServer() + { + return portalServer; + } + + + /** + * = + * @param portalServer + */ + public void setPortalServer(Server portalServer) + { + this.portalServer =3D portalServer; + } + + + /** + * = + * @param contentType + * @return + */ + public String retrieveMediaType(String contentType) + { + String mediaType =3D contentType; + + // + if (mediaType !=3D null) + { + // Remove any parameters + int index =3D mediaType.indexOf(';'); + if (index !=3D -1) + { + mediaType =3D contentType.substring(0, index); + } + + // Trim + mediaType =3D mediaType.trim(); + + // Media type matching is case insensitive, so we convert to lowe= r case + mediaType =3D mediaType.toLowerCase(); + } + return mediaType; + } +} Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/se= rvice/GWTClientFilter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/GWTClientFilter.java (rev 0) +++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/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 Sohil Shah + * + */ +public class GWTClientFilter implements Filter +{ + /** + * = + */ + public void init(FilterConfig arg0) throws ServletException + { = + } + = + /** + * = + */ + public void destroy() + { = + } + + /** + * = + */ + public void doFilter(ServletRequest servletRequest, ServletResponse ser= vletResponse, FilterChain filterChain) throws IOException, ServletException + { = + HttpServletRequest request =3D (HttpServletRequest)servletRequest; + HttpServletResponse response =3D (HttpServletResponse)servletRespons= e; + String contextPath =3D request.getContextPath(); + = + //Extract the resource that is being accessed + String resource =3D request.getRequestURI().replaceFirst(contextPath= , ""); + while(resource.startsWith("/")) + { + if(resource.length() > 1) + { + resource =3D resource.substring(1); + } + else + { + resource =3D ""; + } + } + = + if(resource =3D=3D null || resource.trim().length() =3D=3D 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 =3D this.readContent(resource); + response.getOutputStream().write(gwtResource); + response.getOutputStream().flush(); + return; + } + } + = + /** + * = + * @param path + * @return + */ + private byte[] readContent(String path) + { + byte[] content =3D null; + = + InputStream is =3D null; + ByteArrayOutputStream bos =3D null; + try + { + bos =3D new ByteArrayOutputStream(); + is =3D Thread.currentThread().getContextClassLoader().getResource= AsStream(path); + int bytesRead =3D 0; + byte[] data =3D new byte[1024]; + while((bytesRead=3Dis.read(data)) !=3D -1) + { + byte[] cour =3D 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 !=3D null) + { + try{is.close();}catch(Exception e){} + } + if(bos !=3D null) + { + content =3D bos.toByteArray(); + try{bos.close();}catch(Exception e){} + } + } + = + return content; + } +} Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/se= rvice/PortalEntryPoint.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/PortalEntryPoint.java (rev 0) +++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/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.FlexibleGridConst= raints; +import org.jboss.portal.presentation.impl.classic.layout.FlexibleGridLayou= tManager; +import org.jboss.portal.presentation.impl.classic.layout.RegionConstraints; +import org.jboss.portal.presentation.impl.classic.layout.RegionLayoutManag= er; +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 Sohil Shah + * + */ +public class PortalEntryPoint extends HttpServlet +{ + /** + * = + */ + private Logger log =3D Logger.getLogger(getClass()); + = + /** . */ + private static final int GET_METHOD =3D 0; + + /** . */ + private static final int POST_METHOD =3D 1; + + /** Describes a default servlet mapping. */ + private static final int DEFAULT_SERVLET_MAPPING =3D 0; + + /** Describes a root path mapping. */ + private static final int ROOT_PATH_MAPPING =3D 1; + + /** Describes a path mapping. */ + private static final int PATH_MAPPING =3D 2; + = + /** Are we or not the default servlet ? */ + private boolean asDefaultServlet =3D false; + = + /** + * = + */ + private EntryPoint entryPoint =3D null; + = + /** Configure the as default servlet. */ + public void init() throws ServletException + { + asDefaultServlet =3D getAsDefaultServletInitValue(); + try + { + MBeanServer mbeanServer =3D MBeanServerLocator.locateJBoss(); + this.entryPoint =3D (EntryPoint) MBeanProxy.get(EntryPoint.class,= new ObjectName( + this.getInitParameter("entryPointServiceName")), + mbeanServer); + } + catch (Exception e) + { + this.entryPoint =3D null; + String msg =3D "Portal Entry Point could not be created"; + log.error(msg, e); + throw new UnavailableException(msg); + } + } + = + /** + * = + */ + protected void service(HttpServletRequest req, HttpServletResponse resp= ) throws ServletException, IOException + { + // + String servletPath =3D req.getServletPath(); + String requestURI =3D req.getRequestURI(); + String contextPath =3D req.getContextPath(); + = + String resource =3D req.getRequestURI().replaceFirst(contextPath, ""= ); + while(resource.startsWith("/")) + { + if(resource.length() > 1) + { + resource =3D resource.substring(1); + } + else + { + resource =3D ""; + } + } + = + if(resource =3D=3D null || resource.trim().length() =3D=3D 0) + { + resp.sendRedirect("index.html"); + return; + } + = + int method; + if ("GET".equals(req.getMethod())) + { + method =3D GET_METHOD; + } + else if ("POST".equals(req.getMethod())) + { + method =3D POST_METHOD; + } + else + { + throw new ServletException(); + } + + // Compute the media type in the content type + String mediaType =3D this.entryPoint.retrieveMediaType(req.getConten= tType()); + + // Only affect the charset encoding if the servlet container will de= code the request + if (method =3D=3D POST_METHOD && PortalConstants.APPLICATION_X_WWW_F= ORM_URLENCODED.equals(mediaType)) + { + // Now we must ensure that we have either an equals or a trailing= space after the media-type + String characterEncoding =3D req.getCharacterEncoding(); + if (characterEncoding =3D=3D null) + { + // Set out charset for the portal request + req.setCharacterEncoding(PortalConstants.UTF_8.name()); + } + else + { + Charset charset =3D Charset.forName(characterEncoding); + if (!PortalConstants.UTF_8.equals(charset)) + { + throw new ServletException("Unaccepted charset " + characte= rEncoding); + } + } + } + + // Determine the mapping we have + int mapping =3D DEFAULT_SERVLET_MAPPING; + if (!asDefaultServlet) + { + if (servletPath.length() =3D=3D 0) + { + mapping =3D ROOT_PATH_MAPPING; + } + else + { + mapping =3D PATH_MAPPING; + } + } + + // Determine the host for this request + String portalHost =3D req.getServerName(); + + // Determine the request path + String portalRequestPath =3D null; + String portalContextPath =3D null; + switch (mapping) + { + case DEFAULT_SERVLET_MAPPING: + portalRequestPath =3D requestURI.substring(contextPath.length(= )); + portalContextPath =3D requestURI.substring(0, contextPath.leng= th()); + break; + case ROOT_PATH_MAPPING: + portalRequestPath =3D requestURI.substring(contextPath.length(= )); + portalContextPath =3D requestURI.substring(0, contextPath.leng= th()); + break; + case PATH_MAPPING: + portalRequestPath =3D requestURI.substring(contextPath.length(= ) + servletPath.length()); + portalContextPath =3D requestURI.substring(0, contextPath.leng= th() + servletPath.length()); + break; + } + + // Apply the url decoding + portalRequestPath =3D URLTools.decodeXWWWFormURL(portalRequestPath); + portalContextPath =3D URLTools.decodeXWWWFormURL(portalContextPath); + + // + URLContext urlContext =3D URLContext.newInstance(req.isSecure(), req= .getRemoteUser() !=3D 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 =3D Collections.EMPTY_MAP; + String queryString =3D req.getQueryString(); + if (queryString !=3D null) + { + queryParameterMap =3D QueryStringParser.parseQueryString(queryStr= ing); + } + + // + Map bodyParameterMap =3D null; + if (method =3D=3D POST_METHOD && PortalConstants.APPLICATION_X_WWW_F= ORM_URLENCODED.equals(mediaType)) + { + bodyParameterMap =3D Collections.EMPTY_MAP; + for (Iterator i =3D req.getParameterMap().entrySet().iterator(); = i.hasNext();) + { + Map.Entry entry =3D (Map.Entry)i.next(); + + // Get param name + String paramName =3D (String)entry.getKey(); + + // Values that are aggregated from the query string and the bo= dy + String[] paramValues =3D (String[])entry.getValue(); + + // Values decoded from the query string + String[] queryValues =3D (String[])queryParameterMap.get(param= Name); + if (queryValues !=3D null) + { + int bodyValuesLength =3D paramValues.length - queryValues.l= ength; + if (bodyValuesLength > 0) + { + String[] bodyValues =3D new String[bodyValuesLength]; + System.arraycopy(paramValues, queryValues.length, bodyVa= lues, 0, bodyValuesLength); + if (bodyParameterMap.isEmpty()) + { + bodyParameterMap =3D new HashMap(); + } + bodyParameterMap.put(paramName, bodyValues); + } + } + else + { + if (bodyParameterMap.isEmpty()) + { + bodyParameterMap =3D new HashMap(); + } + bodyParameterMap.put(paramName, paramValues); + } + } + + // Make the map unmodifiable + bodyParameterMap =3D bodyParameterMap.isEmpty() ? bodyParameterMa= p : Collections.unmodifiableMap(bodyParameterMap); + } + + // *************** + // *************** + // *************** + // *************** + + // + Server server =3D this.entryPoint.getPortalServer(); + + // + ServerInvocationContext invocationCtx =3D new ServerInvocationContex= tImpl( + req, + resp, + portalHost, + portalRequestPath, + portalContextPath, + queryParameterMap, + bodyParameterMap, + urlContext, + mediaType); + + // + ServerRequest request =3D new ServerRequest(invocationCtx); + request.setServer(server); + + // + ServerResponse response =3D new ServerResponse(request, invocationCt= x); + + // + ServerInvocation invocation =3D new ServerInvocation(invocationCtx); + invocation.setRequest(request); + invocation.setResponse(response); + + // + RequestControllerFactory controllerFactory =3D this.entryPoint.getCo= ntrollerFactory(); + RequestController controller =3D controllerFactory.createRequestCont= roller(invocation); + invocation.setHandler(new RequestControllerDispatcher(controller)); + + // + try + { + InterceptorStackFactory stack =3D this.entryPoint.getInterceptorS= tackFactory(); + invocation.invoke(stack.getInterceptorStack()); + ProcessorResponse processorResponse =3D (ProcessorResponse)req.ge= tAttribute("processorResponse"); + if(processorResponse !=3D null) + { + Page displayedPage =3D processorResponse.findDisplayedPage(); + if(displayedPage !=3D null) + { + this.render(invocation.getServerContext().getClientResponse= ().getWriter(), = + displayedPage); + } + } + } + catch (ServerException e) + { + log.error("Server exception", e); + Throwable nested =3D Exceptions.unwrap(e); + throw new ServletException(nested); + } + catch (InvocationException e) + { + log.error("Invocation exception", e); + Throwable nested =3D 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 =3D 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 asDefaultServl= et + */ + private boolean getAsDefaultServletInitValue() + { + ServletConfig config =3D getServletConfig(); + String value =3D 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 paramete= r value=3D" + + 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 configurat= ion including page result creation is hard coded for the purpose + * of getting the architecture right + * = + * In the real implementation, LayoutState would be fetched dynamica= lly 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 co= mponents and then send back the result to the client + * = + */ = + //Some flexible grid layout testing code + Object[] gridData =3D this.getFlexibleGridLayoutManager(pageResult); + Page page =3D (Page)gridData[0]; + LayoutManager layoutManager =3D (LayoutManager)gridData[1]; = + = + //Some region layout testing code + //Object[] regionData =3D this.getRegionBasedLayoutManager(pageResul= t); + //Page page =3D (Page)regionData[0]; + //LayoutManager layoutManager =3D (LayoutManager)regionData[1]; + = + //Peform Page Layout + String output =3D layoutManager.doLayout(page); + = + = + //Create the final output...Also hardcoded without any preprocessing= /postprocessing etc + StringBuffer buffer =3D new StringBuffer(); = + buffer.append("JBoss Portal UIServer= <= /head>\n"); + buffer.append(output); + buffer.append("\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 =3D new Page(); + Container header =3D new Container("header"); + Container leftPanel =3D new Container("leftPanel"); + Container mainPanel =3D new Container("mainPanel"); + Window headerTabsWindow =3D new Window("header-tabs-window"); + Window menuWindow =3D new Window("menu-window"); + Window leftPanelWindow1 =3D new Window("left-panel-window1"); + Window leftPanelWindow2 =3D new Window("left-panel-window2"); + Window mainPanelWindow =3D 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 =3D this.getGrid("header", 1, 2); + FlexibleGridConstraints[] headerTabConstraints =3D { this.getConstr= aints("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 =3D this.getGrid("leftPanel", 2, 1); + FlexibleGridConstraints[] leftPanelConstraints =3D { this.getConstr= aints("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 =3D this.getGrid("mainPanel", 1, 1); + FlexibleGridConstraints[] mainPanelConstraints =3D { this.getConstr= aints("main-panel-window", "100", 0, 0, 0, 0, 0, 0) }; + mainPanelGrid.setConstraints(mainPanelConstraints); + = + //Setup the FlexibleGrid Layout Manager with the different grids + FlexibleGrid[] row1 =3D { headerGrid }; + FlexibleGrid[] row2 =3D { leftPanelGrid, mainPanelGrid }; + FlexibleGridLayoutManager layoutManager =3D new FlexibleGridLayoutMa= nager(); + layoutManager.addRowOfGrids(row1); + layoutManager.addRowOfGrids(row2); + = + //Populate the grid windows with proper content = + List windows =3D pageResult.getWindows(); + int counter =3D 0; + for(Iterator itr=3Dwindows.iterator();itr.hasNext();) + { + Window result =3D (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 =3D 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, Stri= ng widthPercentage, int top, int bottom, int left, int right, int row, int = column) + { + FlexibleGridConstraints constraints =3D 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 =3D new Page(); + Container left =3D new Container("left"); + Container center =3D new Container("center"); + page.addContainer(left); + page.addContainer(center); + = + //Populate the grid windows with proper content = + List windows =3D pageResult.getWindows(); + int counter =3D 0; + for(Iterator itr=3Dwindows.iterator();itr.hasNext();) + { + Window result =3D (Window)itr.next(); + Window uiWindow =3D 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 =3D new RegionLayoutManager(); + RegionConstraints leftConstraints =3D new RegionConstraints("left", = RegionConstraints.LEFT); + RegionConstraints centerConstraints =3D new RegionConstraints("cente= r", RegionConstraints.CENTER); + layoutManager.addRegionConstraints(leftConstraints); + layoutManager.addRegionConstraints(centerConstraints); + = + return new Object[]{page, layoutManager}; + } +} Added: branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/se= rvice/UIServer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/UIServer.java (rev 0) +++ branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/servi= ce/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 fu= nctions to this component + * = + * @author Sohil Shah + * + */ +public class UIServer implements RequestController +{ + /** + * = + */ + private PresentationServer presentationServer =3D null; + = + = + /** + * = + * + */ + public UIServer() + { = + } + = + = + /** + * handle is the entry point for handling an incoming Portal request. T= he request is handed over + * from the Http Layer via the main Portal Servlet + * + */ = + public void handle(ServerInvocation invocation) throws ServerException + { = + try + { = + ServerAction serverAction =3D this.getServerAction(invocation); + ProcessorRequest processorRequest =3D new ProcessorRequest(server= Action, invocation); + RequestContext requestContext =3D null; //Just use null until pro= per implementation is provided + ProcessorResponse processorResponse =3D this.presentationServer.g= etProcessor().process(requestContext, + processorRequest); + = + //Go ahead and render to the client based on ProcessorResponse re= ceived from the core Portal = + if(processorResponse !=3D 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 =3D presentationServer; + } = + //---------------------------------------------------------------------= ---------------------------------------------------------------------------= -------------- + /** + * = + */ + private ServerAction getServerAction(ServerInvocation invocation) + { + ServerAction serverAction =3D null; + = + ServerInvocationContext invocationContext =3D invocation.getServerCo= ntext(); + HttpServletRequest request =3D invocationContext.getClientRequest(); + if(request.getMethod().equals("GET")) + { + GetActivation get =3D new GetActivation(); + get.setUrl(request.getRequestURL().toString()); + get.setContentType(invocationContext.getMediaType()); + get.setQueryParameters(invocationContext.getQueryParameterMap()); + serverAction =3D get; + } + else if(request.getMethod().equals("POST")) + { + PostActivation post =3D new PostActivation(); + post.setUrl(request.getRequestURL().toString()); + post.setContentType(invocationContext.getMediaType()); + post.setQueryParameters(invocationContext.getQueryParameterMap()); + post.setBodyParameters(invocationContext.getBodyParameterMap()); + serverAction =3D post; + } = + = + //If this is a link activation, then interpret the Portal and the Po= rtalObject that + //this link is targetted for + if(serverAction instanceof LinkActivation) + { + String portalRequestPath =3D invocation.getServerContext().getPor= talRequestPath(); + = + //Process the incoming request and produce a proper ProcessorRequ= est to be + //processed by the core Portal component = + Portal portal =3D null; + PortalObject target =3D null; + StringTokenizer st =3D new StringTokenizer(portalRequestPath, "/"= ); + StringBuffer buffer =3D new StringBuffer("/"); + while(st.hasMoreTokens()) + { + String token =3D st.nextToken(); = + if(portal =3D=3D null) + { + portal =3D this.presentationServer.getPortalObjectReader().= findPortal(token); + if(portal !=3D null) + { + buffer.append(token); + if(st.hasMoreTokens()) + { + buffer.append("/"); + } + } + } + else + { + buffer.append(token); + String id =3D buffer.toString(); + if(st.hasMoreTokens()) + { + buffer.append("/"); + } + = + if(target =3D=3D null) + { + target =3D portal.findChild(id); + if(target =3D=3D null) + { + target =3D this.presentationServer.getPortalObjectRea= der().findPortalObject(portal, id); + } + } + else + { + PortalObject cour =3D target.findChild(id); + if(cour =3D=3D null) + { + target =3D this.presentationServer.getPortalObjectRea= der().findPortalObject(target, id); + } + else + { + target =3D cour; + } + } + } = + } + = + //Setting up the proper targets for this link + ((LinkActivation)serverAction).setPortal(portal); + ((LinkActivation)serverAction).setTarget(target); + } + = + = + return serverAction; + } + = + = +} --===============0071251952900699961==--