]> source.dussan.org Git - vaadin-framework.git/commitdiff
Portlet integration refactoring, ApplicationServlet changes.
authorMarc Englund <marc.englund@itmill.com>
Tue, 15 Apr 2008 12:12:15 +0000 (12:12 +0000)
committerMarc Englund <marc.englund@itmill.com>
Tue, 15 Apr 2008 12:12:15 +0000 (12:12 +0000)
svn changeset:4179/svn branch:trunk

WebContent/WEB-INF/portlet.xml
portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java [new file with mode: 0644]
portlet-src/com/itmill/toolkit/terminal/gwt/server/ITMillApplicationPortlet.java [deleted file]
portlet-src/com/itmill/toolkit/terminal/gwt/server/PortletApplicationContext.java
src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java

index dc48102bc539c87759043d2d75d131f01a5987db..6edf435c807efa079b467ec32e974b580dcce04c 100644 (file)
@@ -7,7 +7,7 @@
        <portlet>\r
                <portlet-name>PortletDemoPortlet</portlet-name>\r
                <display-name>IT Mill Toolkit PortletDemo</display-name>\r
-               <portlet-class>com.itmill.toolkit.terminal.gwt.server.ITMillApplicationPortlet</portlet-class>\r
+               <portlet-class>com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet</portlet-class>\r
                <init-param>\r
                        <name>application</name>\r
                        <value>PortletDemo</value>\r
@@ -39,7 +39,7 @@
        <portlet>\r
                <portlet-name>FeatureBrowserPortlet</portlet-name>\r
                <display-name>IT Mill Toolkit FeatureBrowser</display-name>\r
-               <portlet-class>com.itmill.toolkit.terminal.gwt.server.ITMillApplicationPortlet</portlet-class>\r
+               <portlet-class>com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet</portlet-class>\r
                <init-param>\r
                        <name>application</name>\r
                        <value>FeatureBrowser</value>\r
@@ -71,7 +71,7 @@
        <portlet>\r
                <portlet-name>CalcPortlet</portlet-name>\r
                <display-name>IT Mill Toolkit Calc</display-name>\r
-               <portlet-class>com.itmill.toolkit.terminal.gwt.server.ITMillApplicationPortlet</portlet-class>\r
+               <portlet-class>com.itmill.toolkit.terminal.gwt.server.ApplicationPortlet</portlet-class>\r
                <init-param>\r
                        <name>application</name>\r
                        <value>Calc</value>\r
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 (file)
index 0000000..e21a1b0
--- /dev/null
@@ -0,0 +1,92 @@
+package com.itmill.toolkit.terminal.gwt.server;\r
+\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+\r
+import javax.portlet.ActionRequest;\r
+import javax.portlet.ActionResponse;\r
+import javax.portlet.Portlet;\r
+import javax.portlet.PortletConfig;\r
+import javax.portlet.PortletException;\r
+import javax.portlet.PortletRequestDispatcher;\r
+import javax.portlet.PortletSession;\r
+import javax.portlet.RenderRequest;\r
+import javax.portlet.RenderResponse;\r
+\r
+import com.itmill.toolkit.Application;\r
+\r
+public class ApplicationPortlet implements Portlet {\r
+    // The application to show\r
+    protected String app = "Calc";\r
+    // some applications might require that the height is specified\r
+    protected String height = null; // e.g "200px"\r
+\r
+    private PortletConfig config;\r
+\r
+    public void destroy() {\r
+        config = null;\r
+    }\r
+\r
+    public void init(PortletConfig config) throws PortletException {\r
+        this.config = config;\r
+        app = config.getInitParameter("application");\r
+        if (app == null) {\r
+            app = "PortletDemo";\r
+        }\r
+        height = config.getInitParameter("height");\r
+    }\r
+\r
+    public void processAction(ActionRequest request, ActionResponse response)\r
+            throws PortletException, IOException {\r
+        PortletApplicationContext.dispatchRequest(this, request, response);\r
+    }\r
+\r
+    public void render(RenderRequest request, RenderResponse response)\r
+            throws PortletException, IOException {\r
+\r
+        // display the IT Mill Toolkit application\r
+        writeAjaxWindow(request, response);\r
+    }\r
+\r
+    protected void writeAjaxWindow(RenderRequest request,\r
+            RenderResponse response) throws IOException {\r
+\r
+        response.setContentType("text/html");\r
+        PrintWriter out = response.getWriter();\r
+\r
+        if (app != null) {\r
+            PortletSession sess = request.getPortletSession();\r
+            PortletApplicationContext ctx = PortletApplicationContext\r
+                    .getApplicationContext(sess);\r
+\r
+            /*- TODO store som info somewhere?\r
+            PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/"\r
+                    + app + (app.endsWith("/") ? "" : "/"), request\r
+                    .getPortletMode(), request.getWindowState(), request\r
+                    .getUserPrincipal(), (Map) request\r
+                    .getAttribute(PortletRequest.USER_INFO), config);\r
+            -*/\r
+\r
+            PortletRequestDispatcher dispatcher = sess.getPortletContext()\r
+                    .getRequestDispatcher("/" + app);\r
+\r
+            try {\r
+                // TODO height\r
+                dispatcher.include(request, response);\r
+\r
+            } catch (PortletException e) {\r
+                out.print("<h1>Servlet include failed!</h1>");\r
+                out.print("<div>" + e + "</div>");\r
+                ctx.setPortletApplication(this, null);\r
+                return;\r
+            }\r
+\r
+            Application app = (Application) request\r
+                    .getAttribute(Application.class.getName());\r
+            ctx.setPortletApplication(this, app);\r
+            ctx.firePortletRenderRequest(this, request, response);\r
+\r
+        }\r
+    }\r
+\r
+}\r
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 (file)
index 7c744dc..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.server;\r
-\r
-import java.io.IOException;\r
-import java.io.PrintWriter;\r
-\r
-import javax.portlet.ActionRequest;\r
-import javax.portlet.ActionResponse;\r
-import javax.portlet.Portlet;\r
-import javax.portlet.PortletConfig;\r
-import javax.portlet.PortletException;\r
-import javax.portlet.PortletRequestDispatcher;\r
-import javax.portlet.PortletSession;\r
-import javax.portlet.RenderRequest;\r
-import javax.portlet.RenderResponse;\r
-\r
-import com.itmill.toolkit.Application;\r
-\r
-public class ITMillApplicationPortlet implements Portlet {\r
-    // The application to show\r
-    protected String app = "Calc";\r
-    // some applications might require that the height is specified\r
-    protected String height = null; // e.g "200px"\r
-\r
-    private PortletConfig config;\r
-\r
-    public void destroy() {\r
-        config = null;\r
-    }\r
-\r
-    public void init(PortletConfig config) throws PortletException {\r
-        this.config = config;\r
-        app = config.getInitParameter("application");\r
-        if (app == null) {\r
-            app = "PortletDemo";\r
-        }\r
-        height = config.getInitParameter("height");\r
-    }\r
-\r
-    public void processAction(ActionRequest request, ActionResponse response)\r
-            throws PortletException, IOException {\r
-        PortletApplicationContext.dispatchRequest(this, request, response);\r
-    }\r
-\r
-    public void render(RenderRequest request, RenderResponse response)\r
-            throws PortletException, IOException {\r
-\r
-        /*-\r
-        PortletPreferences prefs = request.getPreferences();\r
-        app = prefs.getValue("application", app);\r
-        theme = prefs.getValue("theme", "default");\r
-        height = prefs.getValue("height", null);\r
-        -*/\r
-\r
-        // display the IT Mill Toolkit application\r
-        writeAjaxWindow(request, response);\r
-    }\r
-\r
-    protected void writeAjaxWindow(RenderRequest request,\r
-            RenderResponse response) throws IOException {\r
-\r
-        response.setContentType("text/html");\r
-        PrintWriter out = response.getWriter();\r
-\r
-        if (app != null) {\r
-            PortletSession sess = request.getPortletSession();\r
-            PortletApplicationContext ctx = PortletApplicationContext\r
-                    .getApplicationContext(sess);\r
-\r
-            /*- TODO store som info somewhere?\r
-            PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/"\r
-                    + app + (app.endsWith("/") ? "" : "/"), request\r
-                    .getPortletMode(), request.getWindowState(), request\r
-                    .getUserPrincipal(), (Map) request\r
-                    .getAttribute(PortletRequest.USER_INFO), config);\r
-            -*/\r
-\r
-            PortletRequestDispatcher dispatcher = sess.getPortletContext()\r
-                    .getRequestDispatcher("/" + app);\r
-\r
-            try {\r
-                // TODO remove:\r
-\r
-                System.err.println(request.getContextPath() + " (portlet ctx)");\r
-                // TODO height\r
-                dispatcher.include(request, response);\r
-\r
-            } catch (PortletException e) {\r
-                out.print("<h1>Servlet include failed!</h1>");\r
-                out.print("<div>" + e + "</div>");\r
-                ctx.setPortletApplication(this, null);\r
-                return;\r
-            }\r
-\r
-            Application app = (Application) request\r
-                    .getAttribute(Application.class.getName());\r
-            ctx.setPortletApplication(this, app);\r
-            ctx.firePortletRenderRequest(this, request, response);\r
-\r
-        }\r
-    }\r
-\r
-}\r
index 46c28e72ca0b2d263b5999ce7cc5aabb508a6587..4ddbabdb962fef9d855233f8beff33967428b11f 100644 (file)
@@ -42,7 +42,6 @@ public class PortletApplicationContext extends WebApplicationContext {
 \r
     static public PortletApplicationContext getApplicationContext(\r
             PortletSession session) {\r
-        System.err.println("PortletApplicationContext.getApplicationContext");\r
         WebApplicationContext cx = (WebApplicationContext) session\r
                 .getAttribute(WebApplicationContext.class.getName(),\r
                         PortletSession.APPLICATION_SCOPE);\r
index 63ec172b8c46326a9b8d4ac011e8c40af1b8be1c..88103d90bf587658df633417d13a6cf94c6d57a4 100644 (file)
@@ -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 + "/";