001
014
015 package com.liferay.portal.mobile.device.rulegroup.action.impl;
016
017 import com.liferay.portal.kernel.bean.BeanReference;
018 import com.liferay.portal.kernel.mobile.device.rulegroup.action.ActionHandler;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.UnicodeProperties;
021 import com.liferay.portal.model.ColorScheme;
022 import com.liferay.portal.model.Theme;
023 import com.liferay.portal.model.impl.ColorSchemeImpl;
024 import com.liferay.portal.service.ThemeLocalService;
025 import com.liferay.portal.theme.ThemeDisplay;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portal.util.WebKeys;
028 import com.liferay.portlet.mobiledevicerules.model.MDRAction;
029
030 import java.util.ArrayList;
031 import java.util.Collection;
032 import java.util.Collections;
033
034 import javax.servlet.http.HttpServletRequest;
035 import javax.servlet.http.HttpServletResponse;
036
037
040 public class ThemeModificationActionHandler implements ActionHandler {
041
042 public static String getHandlerType() {
043 return ThemeModificationActionHandler.class.getName();
044 }
045
046 public void applyAction(
047 MDRAction mdrAction, HttpServletRequest request,
048 HttpServletResponse response) {
049
050 long companyId = PortalUtil.getCompanyId(request);
051
052 UnicodeProperties typeSettingsProperties =
053 mdrAction.getTypeSettingsProperties();
054
055 String themeId = GetterUtil.getString(
056 typeSettingsProperties.getProperty("themeId"));
057
058 Theme theme = _themeLocalService.fetchTheme(companyId, themeId);
059
060 if (theme == null) {
061 return;
062 }
063
064 request.setAttribute(WebKeys.THEME, theme);
065
066 String colorSchemeId = GetterUtil.getString(
067 typeSettingsProperties.getProperty("colorSchemeId"));
068
069 ColorScheme colorScheme = _themeLocalService.fetchColorScheme(
070 companyId, themeId, colorSchemeId);
071
072 if (colorScheme == null) {
073 colorScheme = ColorSchemeImpl.getNullColorScheme();
074 }
075
076 request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
077
078 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
079 WebKeys.THEME_DISPLAY);
080
081 String contextPath = PortalUtil.getPathContext();
082
083 themeDisplay.setLookAndFeel(contextPath, theme, colorScheme);
084 }
085
086 public Collection<String> getPropertyNames() {
087 return _propertyNames;
088 }
089
090 public String getType() {
091 return getHandlerType();
092 }
093
094 public void setThemeLocalService(ThemeLocalService themeLocalService) {
095 _themeLocalService = themeLocalService;
096 }
097
098 private static Collection<String> _propertyNames;
099
100 @BeanReference(type = ThemeLocalService.class)
101 private ThemeLocalService _themeLocalService;
102
103 static {
104 _propertyNames = new ArrayList<String>(2);
105
106 _propertyNames.add("colorSchemeId");
107 _propertyNames.add("themeId");
108
109 _propertyNames = Collections.unmodifiableCollection(_propertyNames);
110 }
111
112 }