1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.portletconfiguration.util;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.GetterUtil;
20  import com.liferay.portal.kernel.util.LocaleUtil;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.kernel.util.Validator;
23  
24  import javax.portlet.PortletPreferences;
25  
26  /**
27   * <a href="PortletConfigurationUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class PortletConfigurationUtil {
32  
33      public static String getPortletTitle(
34          PortletPreferences portletSetup, String languageId) {
35  
36          String useCustomTitle = GetterUtil.getString(portletSetup.getValue(
37              "portlet-setup-use-custom-title", StringPool.BLANK));
38  
39          if (useCustomTitle.equals("false")) {
40              return StringPool.BLANK;
41          }
42  
43          String defaultLanguageId = LocaleUtil.toLanguageId(
44              LocaleUtil.getDefault());
45  
46          String defaultPortletTitle = portletSetup.getValue(
47              "portlet-setup-title-" + defaultLanguageId, StringPool.BLANK);
48  
49          String portletTitle = portletSetup.getValue(
50              "portlet-setup-title-" + languageId, defaultPortletTitle);
51  
52          if (Validator.isNull(portletTitle)) {
53  
54              // For backwards compatibility
55  
56              String oldPortletTitle = portletSetup.getValue(
57                  "portlet-setup-title", null);
58  
59              if (Validator.isNull(useCustomTitle) &&
60                  Validator.isNotNull(oldPortletTitle)) {
61  
62                  portletTitle = oldPortletTitle;
63  
64                  try {
65                      portletSetup.setValue(
66                          "portlet-setup-title-" + defaultLanguageId,
67                          portletTitle);
68                      portletSetup.setValue(
69                          "portlet-setup-use-custom-title", "true");
70  
71                      portletSetup.store();
72                  }
73                  catch (Exception e) {
74                      _log.error(e);
75                  }
76              }
77          }
78  
79          return portletTitle;
80      }
81  
82      private static Log _log = LogFactoryUtil.getLog(
83          PortletConfigurationUtil.class);
84  
85  }