From 2e7b257ac0a834ed4818a545b5d5e0af0d10bfba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 20 Dec 2011 16:18:46 +0200 Subject: [PATCH] Enable finding theme resources without a Callback instance --- .../gwt/server/AbstractApplicationPortlet.java | 8 -------- .../gwt/server/AbstractApplicationServlet.java | 8 -------- .../server/AbstractCommunicationManager.java | 18 ++++++++---------- .../gwt/server/CommunicationManager.java | 15 +++++++++++++++ .../server/PortletCommunicationManager.java | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 08b608db0d..a28b9e53ec 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -188,14 +188,6 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet (MimeResponse) portletResponse, cap, msg, details, outOfSyncURL); } - - public InputStream getThemeResourceAsStream(String themeName, - String resource) throws IOException { - return portlet.getPortletContext().getResourceAsStream( - "/" + AbstractApplicationPortlet.THEME_DIRECTORY_PATH - + themeName + "/" + resource); - } - } /** diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index afdaabcee0..b2d3a7f89f 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -81,14 +81,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements .getHttpServletResponse(), cap, msg, details, outOfSyncURL); } - - public InputStream getThemeResourceAsStream(String themeName, - String resource) throws IOException { - return servlet.getServletContext().getResourceAsStream( - "/" + AbstractApplicationServlet.THEME_DIRECTORY_PATH - + themeName + "/" + resource); - } - } // TODO Move some (all?) of the constants to a separate interface (shared diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index a2f3fb72dd..71a783f125 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -106,10 +106,6 @@ public abstract class AbstractCommunicationManager implements public void criticalNotification(WrappedRequest request, WrappedResponse response, String cap, String msg, String details, String outOfSyncURL) throws IOException; - - public InputStream getThemeResourceAsStream(String themeName, - String resource) throws IOException; - } static class UploadInterruptedException extends Exception { @@ -714,7 +710,7 @@ public abstract class AbstractCommunicationManager implements outWriter.print(getSecurityKeyUIDL(request)); } - writeUidlResponce(callback, repaintAll, outWriter, root, analyzeLayouts); + writeUidlResponce(repaintAll, outWriter, root, analyzeLayouts); closeJsonMessage(outWriter); @@ -757,7 +753,7 @@ public abstract class AbstractCommunicationManager implements return seckey; } - public void writeUidlResponce(Callback callback, boolean repaintAll, + public void writeUidlResponce(boolean repaintAll, final PrintWriter outWriter, Root root, boolean analyzeLayouts) throws PaintException { outWriter.print("\"changes\":["); @@ -970,8 +966,7 @@ public abstract class AbstractCommunicationManager implements final String resource = (String) i.next(); InputStream is = null; try { - is = callback - .getThemeResourceAsStream(getTheme(root), resource); + is = getThemeResourceAsStream(root, getTheme(root), resource); } catch (final Exception e) { // FIXME: Handle exception logger.log(Level.FINER, "Failed to get theme resource stream.", @@ -1037,12 +1032,15 @@ public abstract class AbstractCommunicationManager implements } } + protected abstract InputStream getThemeResourceAsStream(Root root, + String themeName, String resource); + private int getTimeoutInterval() { return maxInactiveInterval; } private String getTheme(Root root) { - String themeName = null;// window.getTheme(); + String themeName = root.getApplication().getThemeForRoot(root); String requestThemeName = getRequestTheme(); if (requestThemeName != null) { @@ -2041,7 +2039,7 @@ public abstract class AbstractCommunicationManager implements if (isXSRFEnabled(root.getApplication())) { pWriter.print(getSecurityKeyUIDL(request)); } - writeUidlResponce(null, true, pWriter, root, false); + writeUidlResponce(true, pWriter, root, false); pWriter.print("}"); String initialUIDL = sWriter.toString(); return initialUIDL; diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index 2e908ae12a..05b852445c 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -5,11 +5,14 @@ package com.vaadin.terminal.gwt.server; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import javax.servlet.ServletContext; + import com.vaadin.Application; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.Paintable; @@ -238,4 +241,16 @@ public class CommunicationManager extends AbstractCommunicationManager { } }; } + + @Override + protected InputStream getThemeResourceAsStream(Root root, String themeName, + String resource) { + WebApplicationContext context = (WebApplicationContext) root + .getApplication().getContext(); + ServletContext servletContext = context.getHttpSession() + .getServletContext(); + return servletContext.getResourceAsStream("/" + + AbstractApplicationServlet.THEME_DIRECTORY_PATH + themeName + + "/" + resource); + } } diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java index 61a9dbc821..8f999ade5a 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java @@ -4,10 +4,12 @@ package com.vaadin.terminal.gwt.server; import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.portlet.MimeResponse; +import javax.portlet.PortletContext; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; import javax.portlet.RenderRequest; @@ -230,4 +232,16 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } + @Override + protected InputStream getThemeResourceAsStream(Root root, String themeName, + String resource) { + PortletApplicationContext2 context = (PortletApplicationContext2) root + .getApplication().getContext(); + PortletContext portletContext = context.getPortletSession() + .getPortletContext(); + return portletContext.getResourceAsStream("/" + + AbstractApplicationPortlet.THEME_DIRECTORY_PATH + themeName + + "/" + resource); + } + } -- 2.39.5