001
014
015 package com.liferay.portlet.portletconfiguration.action;
016
017 import com.liferay.portal.kernel.json.JSONFactoryUtil;
018 import com.liferay.portal.kernel.json.JSONObject;
019 import com.liferay.portal.kernel.language.LanguageUtil;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.util.GetterUtil;
023 import com.liferay.portal.kernel.util.LocaleUtil;
024 import com.liferay.portal.kernel.util.ParamUtil;
025 import com.liferay.portal.kernel.util.Validator;
026 import com.liferay.portal.model.Layout;
027 import com.liferay.portal.security.permission.ActionKeys;
028 import com.liferay.portal.security.permission.PermissionChecker;
029 import com.liferay.portal.service.permission.PortletPermissionUtil;
030 import com.liferay.portal.struts.JSONAction;
031 import com.liferay.portal.theme.ThemeDisplay;
032 import com.liferay.portal.util.WebKeys;
033 import com.liferay.portlet.InvokerPortletImpl;
034 import com.liferay.portlet.PortletPreferencesFactoryUtil;
035
036 import java.util.Locale;
037
038 import javax.portlet.PortletPreferences;
039
040 import javax.servlet.http.HttpServletRequest;
041 import javax.servlet.http.HttpServletResponse;
042 import javax.servlet.http.HttpSession;
043
044 import org.apache.struts.action.ActionForm;
045 import org.apache.struts.action.ActionMapping;
046
047
051 public class UpdateLookAndFeelAction extends JSONAction {
052
053 @Override
054 public String getJSON(
055 ActionMapping mapping, ActionForm form, HttpServletRequest request,
056 HttpServletResponse response)
057 throws Exception {
058
059 HttpSession session = request.getSession();
060
061 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
062 WebKeys.THEME_DISPLAY);
063
064 Layout layout = themeDisplay.getLayout();
065
066 PermissionChecker permissionChecker =
067 themeDisplay.getPermissionChecker();
068
069 String portletId = ParamUtil.getString(request, "portletId");
070
071 if (!PortletPermissionUtil.contains(
072 permissionChecker, themeDisplay.getPlid(), portletId,
073 ActionKeys.CONFIGURATION)) {
074
075 return null;
076 }
077
078 PortletPreferences portletSetup =
079 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
080 layout, portletId);
081
082 String css = ParamUtil.getString(request, "css");
083
084 if (_log.isDebugEnabled()) {
085 _log.debug("Updating css " + css);
086 }
087
088 JSONObject jsonObj = JSONFactoryUtil.createJSONObject(css);
089
090 JSONObject portletData = jsonObj.getJSONObject("portletData");
091
092 jsonObj.remove("portletData");
093
094 css = jsonObj.toString();
095
096 boolean useCustomTitle = portletData.getBoolean("useCustomTitle");
097 boolean showBorders = portletData.getBoolean("showBorders");
098 String linkToLayoutUuid = GetterUtil.getString(
099 portletData.getString("portletLinksTarget"));
100
101 JSONObject titles = portletData.getJSONObject("titles");
102
103 Locale[] locales = LanguageUtil.getAvailableLocales();
104
105 for (int i = 0; i < locales.length; i++) {
106 String languageId = LocaleUtil.toLanguageId(locales[i]);
107
108 String title = null;
109
110 if (titles.has(languageId)) {
111 title = GetterUtil.getString(titles.getString(languageId));
112 }
113
114 if (Validator.isNotNull(title)) {
115 portletSetup.setValue("portletSetupTitle_" + languageId, title);
116 }
117 else {
118 portletSetup.reset("portletSetupTitle_" + languageId);
119 }
120 }
121
122 portletSetup.setValue(
123 "portletSetupUseCustomTitle", String.valueOf(useCustomTitle));
124 portletSetup.setValue(
125 "portletSetupShowBorders", String.valueOf(showBorders));
126
127 if (Validator.isNotNull(linkToLayoutUuid)) {
128 portletSetup.setValue(
129 "portletSetupLinkToLayoutUuid", linkToLayoutUuid);
130 }
131 else {
132 portletSetup.reset("portletSetupLinkToLayoutUuid");
133 }
134
135 portletSetup.setValue("portletSetupCss", css);
136
137 JSONObject wapData = jsonObj.getJSONObject("wapData");
138
139 String wapTitle = wapData.getString("title");
140 String wapInitialWindowState = wapData.getString("initialWindowState");
141
142 portletSetup.setValue("lfrWapTitle", wapTitle);
143 portletSetup.setValue(
144 "lfrWapInitialWindowState", wapInitialWindowState);
145
146 portletSetup.store();
147
148 InvokerPortletImpl.clearResponse(
149 session, layout.getPrimaryKey(), portletId,
150 LanguageUtil.getLanguageId(request));
151
152 return null;
153 }
154
155 private static Log _log = LogFactoryUtil.getLog(
156 UpdateLookAndFeelAction.class);
157
158 }