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(
040 "portlet-setup-css", StringPool.BLANK);
041
042 if (Validator.isNotNull(css)) {
043 JSONObject cssJSON = PortletSetupUtil.cssToJSON(portletSetup, css);
044
045 JSONObject advancedDataJSON = cssJSON.getJSONObject("advancedData");
046
047 if (advancedDataJSON != null) {
048 customCSSClassName = advancedDataJSON.getString(
049 "customCSSClassName");
050 }
051 }
052
053 return customCSSClassName;
054 }
055
056 public static String getPortletTitle(
057 PortletPreferences portletSetup, String languageId) {
058
059 String useCustomTitle = GetterUtil.getString(portletSetup.getValue(
060 "portlet-setup-use-custom-title", StringPool.BLANK));
061
062 if (useCustomTitle.equals("false")) {
063 return StringPool.BLANK;
064 }
065
066 String defaultLanguageId = LocaleUtil.toLanguageId(
067 LocaleUtil.getDefault());
068
069 String defaultPortletTitle = portletSetup.getValue(
070 "portlet-setup-title-" + defaultLanguageId, StringPool.BLANK);
071
072 String portletTitle = portletSetup.getValue(
073 "portlet-setup-title-" + languageId, defaultPortletTitle);
074
075 if (Validator.isNull(portletTitle)) {
076
077
078
079 String oldPortletTitle = portletSetup.getValue(
080 "portlet-setup-title", null);
081
082 if (Validator.isNull(useCustomTitle) &&
083 Validator.isNotNull(oldPortletTitle)) {
084
085 portletTitle = oldPortletTitle;
086
087 try {
088 portletSetup.setValue(
089 "portlet-setup-title-" + defaultLanguageId,
090 portletTitle);
091 portletSetup.setValue(
092 "portlet-setup-use-custom-title", "true");
093
094 portletSetup.store();
095 }
096 catch (Exception e) {
097 _log.error(e);
098 }
099 }
100 }
101
102 return portletTitle;
103 }
104
105 private static Log _log = LogFactoryUtil.getLog(
106 PortletConfigurationUtil.class);
107
108 }