1
19
20 package com.liferay.portlet.portletconfiguration.action;
21
22 import com.liferay.portal.kernel.json.JSONFactoryUtil;
23 import com.liferay.portal.kernel.json.JSONObject;
24 import com.liferay.portal.kernel.language.LanguageUtil;
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.kernel.util.LocaleUtil;
29 import com.liferay.portal.kernel.util.ParamUtil;
30 import com.liferay.portal.kernel.util.Validator;
31 import com.liferay.portal.model.Layout;
32 import com.liferay.portal.security.permission.ActionKeys;
33 import com.liferay.portal.security.permission.PermissionChecker;
34 import com.liferay.portal.service.permission.PortletPermissionUtil;
35 import com.liferay.portal.struts.JSONAction;
36 import com.liferay.portal.theme.ThemeDisplay;
37 import com.liferay.portal.util.WebKeys;
38 import com.liferay.portlet.InvokerPortletImpl;
39 import com.liferay.portlet.PortletPreferencesFactoryUtil;
40
41 import java.util.Locale;
42
43 import javax.portlet.PortletPreferences;
44
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
47 import javax.servlet.http.HttpSession;
48
49 import org.apache.struts.action.ActionForm;
50 import org.apache.struts.action.ActionMapping;
51
52
59 public class UpdateLookAndFeelAction extends JSONAction {
60
61 public String getJSON(
62 ActionMapping mapping, ActionForm form, HttpServletRequest request,
63 HttpServletResponse response)
64 throws Exception {
65
66 HttpSession session = request.getSession();
67
68 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
69 WebKeys.THEME_DISPLAY);
70
71 Layout layout = themeDisplay.getLayout();
72
73 PermissionChecker permissionChecker =
74 themeDisplay.getPermissionChecker();
75
76 String portletId = ParamUtil.getString(request, "portletId");
77
78 if (!PortletPermissionUtil.contains(
79 permissionChecker, themeDisplay.getPlid(), portletId,
80 ActionKeys.CONFIGURATION)) {
81
82 return null;
83 }
84
85 PortletPreferences portletSetup =
86 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
87 layout, portletId);
88
89 String css = ParamUtil.getString(request, "css");
90
91 if (_log.isDebugEnabled()) {
92 _log.debug("Updating css " + css);
93 }
94
95 JSONObject jsonObj = JSONFactoryUtil.createJSONObject(css);
96
97 JSONObject portletData = jsonObj.getJSONObject("portletData");
98
99 jsonObj.remove("portletData");
100
101 css = jsonObj.toString();
102
103 boolean useCustomTitle = portletData.getBoolean("useCustomTitle");
104 boolean showBorders = portletData.getBoolean("showBorders");
105 long linkToLayoutId = GetterUtil.getLong(
106 portletData.getString("portletLinksTarget"));
107
108 JSONObject titles = portletData.getJSONObject("titles");
109
110 Locale[] locales = LanguageUtil.getAvailableLocales();
111
112 for (int i = 0; i < locales.length; i++) {
113 String languageId = LocaleUtil.toLanguageId(locales[i]);
114
115 String title = null;
116
117 if (titles.has(languageId)) {
118 title = GetterUtil.getString(titles.getString(languageId));
119 }
120
121 if (Validator.isNotNull(title)) {
122 portletSetup.setValue(
123 "portlet-setup-title-" + languageId, title);
124 }
125 else {
126 portletSetup.reset("portlet-setup-title-" + languageId);
127 }
128 }
129
130 portletSetup.setValue(
131 "portlet-setup-use-custom-title", String.valueOf(useCustomTitle));
132 portletSetup.setValue(
133 "portlet-setup-show-borders", String.valueOf(showBorders));
134
135 if (linkToLayoutId > 0) {
136 portletSetup.setValue(
137 "portlet-setup-link-to-layout-id",
138 String.valueOf(linkToLayoutId));
139 }
140 else {
141 portletSetup.reset("portlet-setup-link-to-layout-id");
142 }
143
144 portletSetup.setValue("portlet-setup-css", css);
145
146 JSONObject wapData = jsonObj.getJSONObject("wapData");
147
148 String wapTitle = wapData.getString("title");
149 String wapInitialWindowState = wapData.getString("initialWindowState");
150
151 portletSetup.setValue("lfr-wap-title", wapTitle);
152 portletSetup.setValue(
153 "lfr-wap-initial-window-state", wapInitialWindowState);
154
155 portletSetup.store();
156
157 InvokerPortletImpl.clearResponse(
158 session, layout.getPrimaryKey(), portletId,
159 LanguageUtil.getLanguageId(request));
160
161 return null;
162 }
163
164 private static Log _log =
165 LogFactoryUtil.getLog(UpdateLookAndFeelAction.class);
166
167 }