001
014
015 package com.liferay.portlet.portletconfiguration.util;
016
017 import com.liferay.portal.kernel.json.JSONObject;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.LocaleUtil;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.portlet.PortletSetupUtil;
025
026 import javax.portlet.PortletPreferences;
027
028
031 public class PortletConfigurationUtil {
032
033 public static String getPortletCustomCSSClassName(
034 PortletPreferences portletSetup)
035 throws Exception {
036
037 String customCSSClassName = StringPool.BLANK;
038
039 String css = portletSetup.getValue("portletSetupCss", StringPool.BLANK);
040
041 if (Validator.isNotNull(css)) {
042 JSONObject cssJSONObject = PortletSetupUtil.cssToJSONObject(
043 portletSetup, css);
044
045 JSONObject advancedDataJSONObject = cssJSONObject.getJSONObject(
046 "advancedData");
047
048 if (advancedDataJSONObject != null) {
049 customCSSClassName = advancedDataJSONObject.getString(
050 "customCSSClassName");
051 }
052 }
053
054 return customCSSClassName;
055 }
056
057 public static String getPortletTitle(
058 PortletPreferences portletSetup, String languageId) {
059
060 String useCustomTitle = GetterUtil.getString(
061 portletSetup.getValue(
062 "portletSetupUseCustomTitle", StringPool.BLANK));
063
064 if (!useCustomTitle.equals("true")) {
065 return null;
066 }
067
068 String defaultLanguageId = LocaleUtil.toLanguageId(
069 LocaleUtil.getSiteDefault());
070
071 String defaultPortletTitle = portletSetup.getValue(
072 "portletSetupTitle_" + defaultLanguageId, StringPool.BLANK);
073
074 String portletTitle = portletSetup.getValue(
075 "portletSetupTitle_" + languageId, defaultPortletTitle);
076
077 if (Validator.isNotNull(portletTitle)) {
078 return portletTitle;
079 }
080
081
082
083 String oldPortletTitle = portletSetup.getValue(
084 "portletSetupTitle", null);
085
086 if (Validator.isNull(useCustomTitle) &&
087 Validator.isNotNull(oldPortletTitle)) {
088
089 portletTitle = oldPortletTitle;
090
091 try {
092 portletSetup.setValue(
093 "portletSetupTitle_" + defaultLanguageId, portletTitle);
094 portletSetup.setValue(
095 "portletSetupUseCustomTitle", Boolean.TRUE.toString());
096
097 portletSetup.store();
098 }
099 catch (Exception e) {
100 _log.error(e, e);
101 }
102 }
103
104 return portletTitle;
105 }
106
107 private static Log _log = LogFactoryUtil.getLog(
108 PortletConfigurationUtil.class);
109
110 }