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.util.LocaleUtil;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.model.PortletConstants;
024 import com.liferay.portal.security.permission.ActionKeys;
025 import com.liferay.portal.security.permission.PermissionChecker;
026 import com.liferay.portal.service.permission.PortletPermissionUtil;
027 import com.liferay.portal.struts.JSONAction;
028 import com.liferay.portal.theme.ThemeDisplay;
029 import com.liferay.portal.util.PortalUtil;
030 import com.liferay.portal.util.WebKeys;
031 import com.liferay.portlet.PortletPreferencesFactoryUtil;
032 import com.liferay.portlet.PortletSetupUtil;
033
034 import java.util.Locale;
035
036 import javax.portlet.PortletPreferences;
037
038 import javax.servlet.http.HttpServletRequest;
039 import javax.servlet.http.HttpServletResponse;
040
041 import org.apache.struts.action.ActionForm;
042 import org.apache.struts.action.ActionMapping;
043
044
047 public class GetLookAndFeelAction extends JSONAction {
048
049 @Override
050 public String getJSON(
051 ActionMapping actionMapping, ActionForm actionForm,
052 HttpServletRequest request, HttpServletResponse response)
053 throws Exception {
054
055 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
056 WebKeys.THEME_DISPLAY);
057
058 Layout layout = themeDisplay.getLayout();
059
060 PermissionChecker permissionChecker =
061 themeDisplay.getPermissionChecker();
062
063 String portletId = ParamUtil.getString(request, "portletId");
064
065 if (!PortletPermissionUtil.contains(
066 permissionChecker, layout, portletId,
067 ActionKeys.CONFIGURATION)) {
068
069 return null;
070 }
071
072 PortletPreferences portletSetup =
073 PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(
074 layout, portletId);
075
076 JSONObject portletSetupJSONObject = PortletSetupUtil.cssToJSONObject(
077 portletSetup);
078
079 JSONObject defaultPortletTitlesJSONObject =
080 JSONFactoryUtil.createJSONObject();
081
082 Locale[] availableLocales = LanguageUtil.getAvailableLocales(
083 themeDisplay.getSiteGroupId());
084
085 for (Locale locale : availableLocales) {
086 String rootPortletId = PortletConstants.getRootPortletId(portletId);
087 String languageId = LocaleUtil.toLanguageId(locale);
088
089 defaultPortletTitlesJSONObject.put(
090 languageId,
091 PortalUtil.getPortletTitle(rootPortletId, languageId));
092 }
093
094 portletSetupJSONObject.put(
095 "defaultPortletTitles", defaultPortletTitlesJSONObject);
096
097 return portletSetupJSONObject.toString();
098 }
099
100 }