From: Marc Englund Date: Tue, 15 Apr 2008 12:12:15 +0000 (+0000) Subject: Portlet integration refactoring, ApplicationServlet changes. X-Git-Tag: 6.7.0.beta1~4893 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=177ffe19adb272f841d543e6d1a178d59d363226;p=vaadin-framework.git Portlet integration refactoring, ApplicationServlet changes. svn changeset:4179/svn branch:trunk --- diff --git a/WebContent/WEB-INF/portlet.xml b/WebContent/WEB-INF/portlet.xml index dc48102bc5..6edf435c80 100644 --- a/WebContent/WEB-INF/portlet.xml +++ b/WebContent/WEB-INF/portlet.xml @@ -7,7 +7,7 @@ PortletDemoPortlet IT Mill Toolkit PortletDemo - com.itmill.toolkit.terminal.gwt.server.ITMillApplicationPortlet + com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet application PortletDemo @@ -39,7 +39,7 @@ FeatureBrowserPortlet IT Mill Toolkit FeatureBrowser - com.itmill.toolkit.terminal.gwt.server.ITMillApplicationPortlet + com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet application FeatureBrowser @@ -71,7 +71,7 @@ CalcPortlet IT Mill Toolkit Calc - com.itmill.toolkit.terminal.gwt.server.ITMillApplicationPortlet + com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet application Calc diff --git a/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java new file mode 100644 index 0000000000..e21a1b01f1 --- /dev/null +++ b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java @@ -0,0 +1,92 @@ +package com.itmill.toolkit.terminal.gwt.server; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.Portlet; +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.PortletSession; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import com.itmill.toolkit.Application; + +public class ApplicationPortlet implements Portlet { + // The application to show + protected String app = "Calc"; + // some applications might require that the height is specified + protected String height = null; // e.g "200px" + + private PortletConfig config; + + public void destroy() { + config = null; + } + + public void init(PortletConfig config) throws PortletException { + this.config = config; + app = config.getInitParameter("application"); + if (app == null) { + app = "PortletDemo"; + } + height = config.getInitParameter("height"); + } + + public void processAction(ActionRequest request, ActionResponse response) + throws PortletException, IOException { + PortletApplicationContext.dispatchRequest(this, request, response); + } + + public void render(RenderRequest request, RenderResponse response) + throws PortletException, IOException { + + // display the IT Mill Toolkit application + writeAjaxWindow(request, response); + } + + protected void writeAjaxWindow(RenderRequest request, + RenderResponse response) throws IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + if (app != null) { + PortletSession sess = request.getPortletSession(); + PortletApplicationContext ctx = PortletApplicationContext + .getApplicationContext(sess); + + /*- TODO store som info somewhere? + PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/" + + app + (app.endsWith("/") ? "" : "/"), request + .getPortletMode(), request.getWindowState(), request + .getUserPrincipal(), (Map) request + .getAttribute(PortletRequest.USER_INFO), config); + -*/ + + PortletRequestDispatcher dispatcher = sess.getPortletContext() + .getRequestDispatcher("/" + app); + + try { + // TODO height + dispatcher.include(request, response); + + } catch (PortletException e) { + out.print("

Servlet include failed!

"); + out.print("
" + e + "
"); + ctx.setPortletApplication(this, null); + return; + } + + Application app = (Application) request + .getAttribute(Application.class.getName()); + ctx.setPortletApplication(this, app); + ctx.firePortletRenderRequest(this, request, response); + + } + } + +} diff --git a/portlet-src/com/itmill/toolkit/terminal/gwt/server/ITMillApplicationPortlet.java b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ITMillApplicationPortlet.java deleted file mode 100644 index 7c744dc4c2..0000000000 --- a/portlet-src/com/itmill/toolkit/terminal/gwt/server/ITMillApplicationPortlet.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.itmill.toolkit.terminal.gwt.server; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.portlet.ActionRequest; -import javax.portlet.ActionResponse; -import javax.portlet.Portlet; -import javax.portlet.PortletConfig; -import javax.portlet.PortletException; -import javax.portlet.PortletRequestDispatcher; -import javax.portlet.PortletSession; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; - -import com.itmill.toolkit.Application; - -public class ITMillApplicationPortlet implements Portlet { - // The application to show - protected String app = "Calc"; - // some applications might require that the height is specified - protected String height = null; // e.g "200px" - - private PortletConfig config; - - public void destroy() { - config = null; - } - - public void init(PortletConfig config) throws PortletException { - this.config = config; - app = config.getInitParameter("application"); - if (app == null) { - app = "PortletDemo"; - } - height = config.getInitParameter("height"); - } - - public void processAction(ActionRequest request, ActionResponse response) - throws PortletException, IOException { - PortletApplicationContext.dispatchRequest(this, request, response); - } - - public void render(RenderRequest request, RenderResponse response) - throws PortletException, IOException { - - /*- - PortletPreferences prefs = request.getPreferences(); - app = prefs.getValue("application", app); - theme = prefs.getValue("theme", "default"); - height = prefs.getValue("height", null); - -*/ - - // display the IT Mill Toolkit application - writeAjaxWindow(request, response); - } - - protected void writeAjaxWindow(RenderRequest request, - RenderResponse response) throws IOException { - - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - - if (app != null) { - PortletSession sess = request.getPortletSession(); - PortletApplicationContext ctx = PortletApplicationContext - .getApplicationContext(sess); - - /*- TODO store som info somewhere? - PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/" - + app + (app.endsWith("/") ? "" : "/"), request - .getPortletMode(), request.getWindowState(), request - .getUserPrincipal(), (Map) request - .getAttribute(PortletRequest.USER_INFO), config); - -*/ - - PortletRequestDispatcher dispatcher = sess.getPortletContext() - .getRequestDispatcher("/" + app); - - try { - // TODO remove: - - System.err.println(request.getContextPath() + " (portlet ctx)"); - // TODO height - dispatcher.include(request, response); - - } catch (PortletException e) { - out.print("

Servlet include failed!

"); - out.print("
" + e + "
"); - ctx.setPortletApplication(this, null); - return; - } - - Application app = (Application) request - .getAttribute(Application.class.getName()); - ctx.setPortletApplication(this, app); - ctx.firePortletRenderRequest(this, request, response); - - } - } - -} diff --git a/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java b/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java index 46c28e72ca..4ddbabdb96 100644 --- a/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java +++ b/portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java @@ -42,7 +42,6 @@ public class PortletApplicationContext extends WebApplicationContext { static public PortletApplicationContext getApplicationContext( PortletSession session) { - System.err.println("PortletApplicationContext.getApplicationContext"); WebApplicationContext cx = (WebApplicationContext) session .getAttribute(WebApplicationContext.class.getName(), PortletSession.APPLICATION_SCOPE); diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java index 63ec172b8c..88103d90bf 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java @@ -651,12 +651,24 @@ public class ApplicationServlet extends HttpServlet { String[] urlParts; try { urlParts = getApplicationUrl(request).toString().split("\\/"); + // TODO remove: + System.err.println(getApplicationUrl(request).toString() + + " parts: " + urlParts.length); + System.err.println(request.getContextPath() + "(servlet ctx)"); appUrl = ""; widgetsetUrl = ""; // if context is specified add it to widgetsetUrl + String ctxPath = request.getContextPath(); + if (ctxPath.length() == 0 + && request + .getAttribute("javax.servlet.include.context_path") != null) { + // include request (e.g portlet), get contex path from + // attribute + ctxPath = (String) request + .getAttribute("javax.servlet.include.context_path"); + } if (urlParts.length > 3 - && urlParts[3].equals(request.getContextPath() - .replaceAll("\\/", ""))) { + && urlParts[3].equals(ctxPath.replaceAll("\\/", ""))) { widgetsetUrl += "/" + urlParts[3]; } for (int i = 3; i < urlParts.length; i++) { @@ -1066,8 +1078,18 @@ public class ApplicationServlet extends HttpServlet { .getServerPort() == 80) ? "" : ":" + request.getServerPort()) + request.getRequestURI()); - String servletPath = request.getContextPath() - + request.getServletPath(); + String servletPath = ""; + if (request.getAttribute("javax.servlet.include.servlet_path") != null) { + // this is an include request + servletPath = request.getAttribute( + "javax.servlet.include.context_path").toString() + + request + .getAttribute("javax.servlet.include.servlet_path"); + + } else { + servletPath = request.getContextPath() + + request.getServletPath(); + } if (servletPath.length() == 0 || servletPath.charAt(servletPath.length() - 1) != '/') { servletPath = servletPath + "/";