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 @Override
047 public void applyAction(
048 MDRAction mdrAction, HttpServletRequest request,
049 HttpServletResponse response) {
050
051 long companyId = PortalUtil.getCompanyId(request);
052
053 UnicodeProperties typeSettingsProperties =
054 mdrAction.getTypeSettingsProperties();
055
056 String themeId = GetterUtil.getString(
057 typeSettingsProperties.getProperty("themeId"));
058
059 Theme theme = _themeLocalService.fetchTheme(companyId, themeId);
060
061 if (theme == null) {
062 return;
063 }
064
065 request.setAttribute(WebKeys.THEME, theme);
066
067 String colorSchemeId = GetterUtil.getString(
068 typeSettingsProperties.getProperty("colorSchemeId"));
069
070 ColorScheme colorScheme = _themeLocalService.fetchColorScheme(
071 companyId, themeId, colorSchemeId);
072
073 if (colorScheme == null) {
074 colorScheme = ColorSchemeImpl.getNullColorScheme();
075 }
076
077 request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
078
079 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
080 WebKeys.THEME_DISPLAY);
081
082 themeDisplay.setLookAndFeel(theme, colorScheme);
083 }
084
085 @Override
086 public Collection<String> getPropertyNames() {
087 return _propertyNames;
088 }
089
090 @Override
091 public String getType() {
092 return getHandlerType();
093 }
094
095 public void setThemeLocalService(ThemeLocalService themeLocalService) {
096 _themeLocalService = themeLocalService;
097 }
098
099 private static Collection<String> _propertyNames;
100
101 @BeanReference(type = ThemeLocalService.class)
102 private ThemeLocalService _themeLocalService;
103
104 static {
105 _propertyNames = new ArrayList<String>(2);
106
107 _propertyNames.add("colorSchemeId");
108 _propertyNames.add("themeId");
109
110 _propertyNames = Collections.unmodifiableCollection(_propertyNames);
111 }
112
113 }