1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }