1
14
15 package com.liferay.portlet.portletconfiguration.util;
16
17 import com.liferay.portal.kernel.json.JSONObject;
18 import com.liferay.portal.kernel.log.Log;
19 import com.liferay.portal.kernel.log.LogFactoryUtil;
20 import com.liferay.portal.kernel.util.GetterUtil;
21 import com.liferay.portal.kernel.util.LocaleUtil;
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portlet.PortletSetupUtil;
25
26 import javax.portlet.PortletPreferences;
27
28
33 public class PortletConfigurationUtil {
34
35 public static String getPortletCustomCSSClassName(
36 PortletPreferences portletSetup)
37 throws Exception {
38
39 String customCSSClassName = StringPool.BLANK;
40
41 String css = portletSetup.getValue(
42 "portlet-setup-css", StringPool.BLANK);
43
44 if (Validator.isNotNull(css)) {
45 JSONObject cssJSON = PortletSetupUtil.cssToJSON(portletSetup, css);
46
47 JSONObject advancedDataJSON = cssJSON.getJSONObject("advancedData");
48
49 if (advancedDataJSON != null) {
50 customCSSClassName = advancedDataJSON.getString(
51 "customCSSClassName");
52 }
53 }
54
55 return customCSSClassName;
56 }
57
58 public static String getPortletTitle(
59 PortletPreferences portletSetup, String languageId) {
60
61 String useCustomTitle = GetterUtil.getString(portletSetup.getValue(
62 "portlet-setup-use-custom-title", StringPool.BLANK));
63
64 if (useCustomTitle.equals("false")) {
65 return StringPool.BLANK;
66 }
67
68 String defaultLanguageId = LocaleUtil.toLanguageId(
69 LocaleUtil.getDefault());
70
71 String defaultPortletTitle = portletSetup.getValue(
72 "portlet-setup-title-" + defaultLanguageId, StringPool.BLANK);
73
74 String portletTitle = portletSetup.getValue(
75 "portlet-setup-title-" + languageId, defaultPortletTitle);
76
77 if (Validator.isNull(portletTitle)) {
78
79
81 String oldPortletTitle = portletSetup.getValue(
82 "portlet-setup-title", null);
83
84 if (Validator.isNull(useCustomTitle) &&
85 Validator.isNotNull(oldPortletTitle)) {
86
87 portletTitle = oldPortletTitle;
88
89 try {
90 portletSetup.setValue(
91 "portlet-setup-title-" + defaultLanguageId,
92 portletTitle);
93 portletSetup.setValue(
94 "portlet-setup-use-custom-title", "true");
95
96 portletSetup.store();
97 }
98 catch (Exception e) {
99 _log.error(e);
100 }
101 }
102 }
103
104 return portletTitle;
105 }
106
107 private static Log _log = LogFactoryUtil.getLog(
108 PortletConfigurationUtil.class);
109
110 }