From: Petter Holmström Date: Wed, 4 Nov 2009 07:57:53 +0000 (+0000) Subject: More refactorings. X-Git-Tag: 6.7.0.beta1~2266^2~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c2c9ed7777d68a0babb79ffb93945632f04eb8e3;p=vaadin-framework.git More refactorings. svn changeset:9610/svn branch:portlet_2.0 --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index b4157d4f12..398b4d8414 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -369,7 +369,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet final String resourceID = request.getResourceID(); final PortletContext pc = getPortletContext(); -// System.out.println("Trying to load resource [" + resourceID + "]"); + // System.out.println("Trying to load resource [" + resourceID + "]"); InputStream is = pc.getResourceAsStream(resourceID); if (is != null) { @@ -547,31 +547,66 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet return null; } + protected String getWidgetsetURL(String widgetset) { + // TODO The widgetset URL is currently hard-corded for LifeRay + return "/html/" + WIDGETSET_DIRECTORY_PATH + widgetset + "/" + + widgetset + ".nocache.js?" + new Date().getTime(); + } + + protected String getThemeURI(String themeName) { + // TODO The theme URI is currently hard-corded for LifeRay + return "/html/" + THEME_DIRECTORY_PATH + themeName; + } + protected void writeAjaxPage(RenderRequest request, RenderResponse response, Window window, Application application) throws IOException, MalformedURLException, PortletException { -// System.out.println("AbstractApplicationPortlet.writeAjaxPage()"); + // System.out.println("AbstractApplicationPortlet.writeAjaxPage()"); response.setContentType("text/html"); final BufferedWriter page = new BufferedWriter(new OutputStreamWriter( response.getPortletOutputStream(), "UTF-8")); - // TODO The widgetset URL is currently hard-corded for LifeRay + String requestWidgetset = (String) request + .getAttribute(AbstractApplicationServlet.REQUEST_WIDGETSET); + String sharedWidgetset = (String) request + .getAttribute(AbstractApplicationServlet.REQUEST_SHARED_WIDGETSET); + if (requestWidgetset == null && sharedWidgetset == null) { + requestWidgetset = getApplicationOrSystemProperty( + PARAMETER_WIDGETSET, DEFAULT_WIDGETSET); + } + String widgetset; + if (requestWidgetset != null) { + widgetset = requestWidgetset; + } else { + widgetset = sharedWidgetset; + } + + // TODO Currently, we can only load widgetsets and themes from the portal + + String themeName = getThemeForWindow(request, window); - String widgetsetURL = "/html/" + WIDGETSET_DIRECTORY_PATH - + DEFAULT_WIDGETSET + "/" + DEFAULT_WIDGETSET + ".nocache.js?" - + new Date().getTime(); + String widgetsetURL = getWidgetsetURL(widgetset); + String themeURI = getThemeURI(themeName); - String themeURI = "/html/" + THEME_DIRECTORY_PATH + DEFAULT_THEME_NAME; + // Get system messages + Application.SystemMessages systemMessages = null; + try { + systemMessages = getSystemMessages(); + } catch (SystemMessageException e) { + // failing to get the system messages is always a problem + throw new PortletException("CommunicationError!", e); + } page.write("\n"); - // if (themeName != null) { - // Custom theme's stylesheet, load only once, in different - // script - // tag to be dominate styles injected by widget - // set page.write("\n"); - // } // TODO Warn if widgetset has not been loaded after 15 seconds @@ -638,9 +680,8 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet appClass += "unknown"; e.printStackTrace(); } - // TODO Add support for flexible theme names String themeClass = "v-theme-" - + DEFAULT_THEME_NAME.replaceAll("[^a-zA-Z0-9]", ""); + + themeName.replaceAll("[^a-zA-Z0-9]", ""); String classNames = "v-app v-app-loading " + themeClass + " " + appClass; @@ -651,6 +692,38 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet page.close(); } + /** + * Returns the theme for given request/window + * + * @param request + * @param window + * @return + */ + private String getThemeForWindow(PortletRequest request, Window window) { + // Finds theme name + String themeName; + + if (request.getParameter(URL_PARAMETER_THEME) != null) { + themeName = request.getParameter(URL_PARAMETER_THEME); + } else { + themeName = window.getTheme(); + } + + if (themeName == null) { + // no explicit theme for window defined + if (request + .getAttribute(AbstractApplicationServlet.REQUEST_DEFAULT_THEME) != null) { + // the default theme is defined in request (by portal) + themeName = (String) request + .getAttribute(AbstractApplicationServlet.REQUEST_DEFAULT_THEME); + } else { + // using the default theme defined by Vaadin + themeName = DEFAULT_THEME_NAME; + } + } + return themeName; + } + protected abstract Class getApplicationClass() throws ClassNotFoundException;