diff options
author | Henri Sara <henri.sara@itmill.com> | 2009-07-06 13:35:58 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2009-07-06 13:35:58 +0000 |
commit | 25047bbcb40fd5c46d1625393b69122d158d7693 (patch) | |
tree | 2067a17f0e3e709fec9f2d72254288999f18bb4d | |
parent | dfa6fd30ec68a1f9b2c8491757ebfb68a61c4d27 (diff) | |
download | vaadin-framework-25047bbcb40fd5c46d1625393b69122d158d7693.tar.gz vaadin-framework-25047bbcb40fd5c46d1625393b69122d158d7693.zip |
#3113: Support for shared default theme for whole portal (loaded exactly once if any Vaadin portlets are displayed). Portlet-specific themes should not inherit the default theme but only do their own definitions.
svn changeset:8331/svn branch:6.0
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java | 71 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java | 60 |
2 files changed, 101 insertions, 30 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index e16a7e439a..53b2fb5cca 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -113,6 +113,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet { .getName() + ".widgetset"; /** + * If set, do not load the default theme but assume that loading it is + * handled e.g. by ApplicationPortlet. + * + * The default theme should be located in + * REQUEST_DEFAULT_THEME_URI/THEME_DIRECTORY_PATH/getDefaultTheme() . + */ + public static final String REQUEST_DEFAULT_THEME_URI = ApplicationServlet.class + .getName() + + ".defaultThemeUri"; + /** * This request attribute is used to add styles to the main element. E.g * "height:500px" generates a style="height:500px" to the main element, * useful from some embedding situations (e.g portlet include.) @@ -424,7 +434,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet { return; } - String themeName = getThemeForWindow(request, window); + String defaultThemeUri = null; + Object reqObj = request.getAttribute(REQUEST_DEFAULT_THEME_URI); + if (reqObj instanceof String) { + defaultThemeUri = (String) reqObj; + } + + String themeName = getThemeForWindow(request, window, + defaultThemeUri != null); // Handles theme resource requests if (handleResourceRequest(request, response, themeName)) { @@ -432,7 +449,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet { } // Send initial AJAX page that kickstarts a Vaadin application - writeAjaxPage(request, response, window, themeName, application); + writeAjaxPage(request, response, window, themeName, + defaultThemeUri, application); } catch (final SessionExpired e) { // Session has expired, notify user @@ -806,14 +824,15 @@ public abstract class AbstractApplicationServlet extends HttpServlet { } - private String getThemeForWindow(HttpServletRequest request, Window window) { + private String getThemeForWindow(HttpServletRequest request, Window window, + boolean ignoreDefaultTheme) { // Finds theme name String themeName = window.getTheme(); if (request.getParameter(URL_PARAMETER_THEME) != null) { themeName = request.getParameter(URL_PARAMETER_THEME); } - if (themeName == null) { + if (!ignoreDefaultTheme && themeName == null) { themeName = getDefaultTheme(); } @@ -1191,8 +1210,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet { */ private void writeAjaxPage(HttpServletRequest request, HttpServletResponse response, Window window, String themeName, - Application application) throws IOException, MalformedURLException, - ServletException { + String defaultThemeUri, Application application) + throws IOException, MalformedURLException, ServletException { // e.g portlets only want a html fragment boolean fragment = (request.getAttribute(REQUEST_FRAGMENT) != null); @@ -1249,10 +1268,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet { : staticFilePath; // Default theme does not use theme URI - String themeUri = null; + String themeBaseUri; + String themeUri; if (themeName != null) { // Using custom theme - themeUri = staticFilePath + "/" + THEME_DIRECTORY_PATH + themeName; + themeBaseUri = staticFilePath; + themeUri = themeBaseUri + "/" + THEME_DIRECTORY_PATH + themeName; + } else { + themeBaseUri = defaultThemeUri; + themeUri = themeBaseUri + "/" + THEME_DIRECTORY_PATH + + getDefaultTheme(); } if (!fragment) { @@ -1346,7 +1371,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet { page.write("windowName: '" + window.getName() + "', "); } page.write("themeUri:"); - page.write(themeUri != null ? "'" + themeUri + "'" : "null"); + page + .write(themeBaseUri != null ? "'" + themeBaseUri + "'" + : "null"); page.write(", versionInfo : {vaadinVersion:\""); page.write(VERSION); page.write("\",applicationVersion:\""); @@ -1419,7 +1446,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet { page.write("windowName: '" + window.getName() + "', "); } page.write("themeUri:"); - page.write(themeUri != null ? "'" + themeUri + "'" : "null"); + page + .write(themeBaseUri != null ? "'" + themeBaseUri + "'" + : "null"); page.write(", versionInfo : {vaadinVersion:\""); page.write(VERSION); page.write("\",applicationVersion:\""); @@ -1483,10 +1512,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet { if (reqParam != null) { style = "style=\"" + reqParam + "\""; } - /*- Add classnames; - * .v-app + /*- Add classnames; + * .v-app * .v-app-loading - * .v-app-<simpleName for app class> + * .v-app-<simpleName for app class> * .v-theme-<themeName, remove non-alphanum> */ String appClass = "v-app-"; @@ -1500,6 +1529,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet { String themeClass = ""; if (themeName != null) { themeClass = "v-theme-" + themeName.replaceAll("[^a-zA-Z0-9]", ""); + } else { + themeClass = "v-theme-" + + getDefaultTheme().replaceAll("[^a-zA-Z0-9]", ""); } page.write("<div id=\"" + appId + "\" class=\"v-app v-app-loading " @@ -1551,7 +1583,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet { private boolean handleResourceRequest(HttpServletRequest request, HttpServletResponse response, String themeName) throws ServletException { - // If the resource path is unassigned, initialize it if (resourcePath == null) { resourcePath = request.getContextPath() + request.getServletPath() @@ -1567,6 +1598,18 @@ public abstract class AbstractApplicationServlet extends HttpServlet { return false; } + if (themeName == null) { + try { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } catch (final java.io.IOException e) { + // FIXME: Handle exception + System.err.println("Returning error code failed: " + + request.getRequestURI() + ". (" + e.getMessage() + + ")"); + } + return true; + } + // Checks the resource type resourceId = resourceId.substring(RESOURCE_URI.length()); InputStream data = null; diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java index 9c16806882..2c8246cd1f 100644 --- a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java @@ -28,7 +28,7 @@ public class ApplicationPortlet implements Portlet, Serializable { // portal configuration parameters
private static final String PORTAL_PARAMETER_VAADIN_WIDGETSET = "vaadin.widgetset";
- private static final String PORTAL_PARAMETER_VAADIN_WIDGETSET_PATH = "vaadin.widgetset.path";
+ private static final String PORTAL_PARAMETER_VAADIN_RESOURCE_PATH = "vaadin.resources.path";
private static final String PORTAL_PARAMETER_VAADIN_THEME = "vaadin.theme";
// The application to show
@@ -95,6 +95,18 @@ public class ApplicationPortlet implements Portlet, Serializable { String portalWidgetset = getPortalProperty(
PORTAL_PARAMETER_VAADIN_WIDGETSET, portalCtx);
+ // location of the widgetset(s) and default theme (to which
+ // /VAADIN/widgetsets/...
+ // is appended)
+ String portalResourcePath = getPortalProperty(
+ PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, portalCtx);
+
+ // by default on LifeRay, widgetset and default theme is in
+ // /html/VAADIN/widgetsets/...
+ if (isLifeRay && portalResourcePath == null) {
+ portalResourcePath = "/html";
+ }
+
// - if the user has specified a widgetset for this portlet, use
// it from the portlet (not fully supported)
// - otherwise, if specified, use the portal-wide widgetset
@@ -102,23 +114,11 @@ public class ApplicationPortlet implements Portlet, Serializable { // - finally, default to use the default widgetset if nothing
// else is found
if (portalWidgetset != null) {
- // location of the widgetset(s) (to which
- // /VAADIN/widgetsets/...
- // is appended)
- String portalWidgetsetPath = getPortalProperty(
- PORTAL_PARAMETER_VAADIN_WIDGETSET_PATH, portalCtx);
-
- // by default on LifeRay, widgetset is in
- // <root>/VAADIN/widgetsets/...
- if (isLifeRay && portalWidgetsetPath == null) {
- portalWidgetsetPath = "/html";
- }
-
- if (portalWidgetsetPath != null) {
+ if (portalResourcePath != null) {
request
.setAttribute(
ApplicationServlet.REQUEST_VAADIN_WIDGETSET_PATH,
- portalWidgetsetPath);
+ portalResourcePath);
}
request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,
@@ -133,6 +133,16 @@ public class ApplicationPortlet implements Portlet, Serializable { style);
}
+ String themeUri = null;
+ if (portalTheme != null) {
+ themeUri = portalResourcePath + "/"
+ + AbstractApplicationServlet.THEME_DIRECTORY_PATH
+ + portalTheme;
+ request.setAttribute(
+ ApplicationServlet.REQUEST_DEFAULT_THEME_URI,
+ themeUri);
+ }
+
dispatcher.include(request, response);
if (isLifeRay) {
@@ -147,6 +157,7 @@ public class ApplicationPortlet implements Portlet, Serializable { * some custom session configurations.
*/
OutputStream out = response.getPortletOutputStream();
+
String lifeRaySessionHearbeatHack = ("<script type=\"text/javascript\">"
+ "if(!vaadin.postRequestHooks) {"
+ " vaadin.postRequestHooks = {};"
@@ -162,7 +173,24 @@ public class ApplicationPortlet implements Portlet, Serializable { * Make sure LifeRay default Vaadin theme is included
* exactly once in DOM.
*/
- // TODO implement this
+ if (portalTheme != null) {
+ // Using portal-wide theme
+ String loadDefaultTheme = ("<script type=\"text/javascript\">\n"
+ + "if(!vaadin.themesLoaded['"
+ + portalTheme
+ + "']) {\n"
+ + "var stylesheet = document.createElement('link');\n"
+ + "stylesheet.setAttribute('rel', 'stylesheet');\n"
+ + "stylesheet.setAttribute('type', 'text/css');\n"
+ + "stylesheet.setAttribute('href', '"
+ + themeUri
+ + "/styles.css');\n"
+ + "document.getElementsByTagName('head')[0].appendChild(stylesheet);\n"
+ + "vaadin.themesLoaded['"
+ + portalTheme
+ + "'] = true;\n}\n" + "</script>\n");
+ out.write(loadDefaultTheme.getBytes());
+ }
}
} catch (PortletException e) {
|