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.portal.model.impl;
16  
17  import com.liferay.portal.kernel.util.HtmlUtil;
18  import com.liferay.portal.kernel.util.LocaleUtil;
19  import com.liferay.portal.kernel.util.LocalizationUtil;
20  import com.liferay.portal.kernel.util.Validator;
21  import com.liferay.portal.model.Role;
22  import com.liferay.portal.model.RoleConstants;
23  
24  import java.util.Locale;
25  
26  /**
27   * <a href="RoleImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Jorge Ferrer
31   */
32  public class RoleImpl extends RoleModelImpl implements Role {
33  
34      public RoleImpl() {
35      }
36  
37      public String getTitle(Locale locale) {
38          String localeLanguageId = LocaleUtil.toLanguageId(locale);
39  
40          return getTitle(localeLanguageId);
41      }
42  
43      public String getTitle(Locale locale, boolean useDefault) {
44          String localeLanguageId = LocaleUtil.toLanguageId(locale);
45  
46          return getTitle(localeLanguageId, useDefault);
47      }
48  
49      public String getTitle(String localeLanguageId) {
50          String title = LocalizationUtil.getLocalization(
51              getTitle(), localeLanguageId);
52  
53          if (Validator.isNull(title)) {
54              title = getName();
55          }
56          else if (isEscapedModel()) {
57              title = HtmlUtil.escape(title);
58          }
59  
60          return title;
61      }
62  
63      public String getTitle(String localeLanguageId, boolean useDefault) {
64          return LocalizationUtil.getLocalization(
65              getTitle(), localeLanguageId, useDefault);
66      }
67  
68      public String getTypeLabel() {
69          return RoleConstants.getTypeLabel(getType());
70      }
71  
72      public void setTitle(String title, Locale locale) {
73          String localeLanguageId = LocaleUtil.toLanguageId(locale);
74  
75          if (Validator.isNotNull(title)) {
76              setTitle(
77                  LocalizationUtil.updateLocalization(
78                      getTitle(), "title", title, localeLanguageId));
79          }
80          else {
81              setTitle(
82                  LocalizationUtil.removeLocalization(
83                      getTitle(), "title", localeLanguageId));
84          }
85      }
86  
87  }