diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2014-03-13 13:27:23 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-03-26 12:54:16 +0200 |
commit | 437f4e9c2478750e53ef3c6bff03bdd25e547432 (patch) | |
tree | e876846447df2ca05d9eb08e6043e49dbcbe88c0 /server/src | |
parent | 1f4ca4cb82e0144053b8a8d5266535da6af0f21f (diff) | |
download | vaadin-framework-437f4e9c2478750e53ef3c6bff03bdd25e547432.tar.gz vaadin-framework-437f4e9c2478750e53ef3c6bff03bdd25e547432.zip |
Improved portlet configuration resolution. (#7814)
Refactored static path resolution in VaadinPortletService.
Refactored theme name resolution in VaadinPortletService.
Refactored widgetset name resolution in VaadinPortletService.
Change-Id: I44c5ffaa7530383843205aadd8da7642899a04c9
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/server/VaadinPortletRequest.java | 18 | ||||
-rw-r--r-- | server/src/com/vaadin/server/VaadinPortletService.java | 96 |
2 files changed, 77 insertions, 37 deletions
diff --git a/server/src/com/vaadin/server/VaadinPortletRequest.java b/server/src/com/vaadin/server/VaadinPortletRequest.java index 9a1e0e7f07..eae367a992 100644 --- a/server/src/com/vaadin/server/VaadinPortletRequest.java +++ b/server/src/com/vaadin/server/VaadinPortletRequest.java @@ -23,6 +23,7 @@ import java.text.ParseException; import java.util.Enumeration; import javax.portlet.ClientDataRequest; +import javax.portlet.PortletPreferences; import javax.portlet.PortletRequest; import javax.portlet.PortletSession; import javax.portlet.ResourceRequest; @@ -191,6 +192,23 @@ public class VaadinPortletRequest extends PortletRequestWrapper implements return getRequest().getPortalContext().getProperty(name); } + /** + * Reads a portlet preference from the portlet of the request. + * + * @param name + * The name of the portlet preference. Cannot be + * <code>null</code>. + * + * @return The value of the portlet preference, <code>null</code> if the + * preference is not defined. + */ + public String getPortletPreference(String name) { + PortletRequest request = getRequest(); + PortletPreferences preferences = request.getPreferences(); + + return preferences.getValue(name, null); + } + @Override public VaadinPortletService getService() { return vaadinService; diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java index 42cf479c56..dceeec8e91 100644 --- a/server/src/com/vaadin/server/VaadinPortletService.java +++ b/server/src/com/vaadin/server/VaadinPortletService.java @@ -81,11 +81,46 @@ public class VaadinPortletService extends VaadinService { return portlet; } - private static String getPortalProperty(VaadinRequest request, - String propertyName) { + private String getPortalProperty(VaadinRequest request, String propertyName) { return ((VaadinPortletRequest) request).getPortalProperty(propertyName); } + private String getParameter(VaadinRequest request, String name, + String defaultValue) { + VaadinPortletRequest portletRequest = (VaadinPortletRequest) request; + + String preference = portletRequest.getPortletPreference(name); + if (preference != null) { + return preference; + } + + String appOrSystemProperty = getAppOrSystemProperty(name, null); + if (appOrSystemProperty != null) { + return appOrSystemProperty; + } + + String portalProperty = portletRequest.getPortalProperty(name); + if (portalProperty != null) { + + // For backwards compatibility - automatically map old portal + // default widget set to default widget set + if (name.equals(Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET)) { + return mapDefaultWidgetset(portalProperty); + } + + return portalProperty; + } + + return defaultValue; + } + + private String getAppOrSystemProperty(String name, String defaultValue) { + DeploymentConfiguration deploymentConfiguration = getDeploymentConfiguration(); + + return deploymentConfiguration.getApplicationOrSystemProperty(name, + defaultValue); + } + @Override public String getConfiguredWidgetset(VaadinRequest request) { @@ -94,22 +129,17 @@ public class VaadinPortletService extends VaadinService { VaadinPortlet.PARAMETER_WIDGETSET, null); if (widgetset == null) { - // If no widgetset defined for the application, check the - // portal property - widgetset = getPortalProperty(request, - VaadinPortlet.PORTAL_PARAMETER_VAADIN_WIDGETSET); - if ("com.vaadin.portal.gwt.PortalDefaultWidgetSet" - .equals(widgetset)) { - // For backwards compatibility - automatically map old portal - // default widget set to default widget set - widgetset = VaadinPortlet.DEFAULT_WIDGETSET; - - } + widgetset = getParameter(request, + Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET, + Constants.DEFAULT_WIDGETSET); } - if (widgetset == null) { - // If no widgetset defined for the portal, use the default - widgetset = VaadinPortlet.DEFAULT_WIDGETSET; + return widgetset; + } + + private String mapDefaultWidgetset(String widgetset) { + if ("com.vaadin.portal.gwt.PortalDefaultWidgetSet".equals(widgetset)) { + return Constants.DEFAULT_WIDGETSET; } return widgetset; @@ -117,17 +147,8 @@ public class VaadinPortletService extends VaadinService { @Override public String getConfiguredTheme(VaadinRequest request) { - - // is the default theme defined by the portal? - String themeName = getPortalProperty(request, - Constants.PORTAL_PARAMETER_VAADIN_THEME); - - if (themeName == null) { - // no, using the default theme defined by Vaadin - themeName = VaadinPortlet.DEFAULT_THEME_NAME; - } - - return themeName; + return getParameter(request, Constants.PORTAL_PARAMETER_VAADIN_THEME, + Constants.DEFAULT_THEME_NAME); } @Override @@ -137,24 +158,25 @@ public class VaadinPortletService extends VaadinService { @Override public String getStaticFileLocation(VaadinRequest request) { - String staticFileLocation = getPortalProperty(request, - Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); - if (staticFileLocation != null) { - return trimTrailingSlashes(staticFileLocation); - } else { - // default for Liferay - return "/html"; - } + // /html is default for Liferay + String staticFileLocation = getParameter(request, + Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, "/html"); + + return trimTrailingSlashes(staticFileLocation); + } + + private PortletContext getPortletContext() { + return getPortlet().getPortletContext(); } @Override public String getMimeType(String resourceName) { - return getPortlet().getPortletContext().getMimeType(resourceName); + return getPortletContext().getMimeType(resourceName); } @Override public File getBaseDirectory() { - PortletContext context = getPortlet().getPortletContext(); + PortletContext context = getPortletContext(); String resultPath = context.getRealPath("/"); if (resultPath != null) { return new File(resultPath); |