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.util.comparator;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.model.Portlet;
19  import com.liferay.portal.util.PortalUtil;
20  
21  import java.io.Serializable;
22  
23  import java.util.Comparator;
24  import java.util.Locale;
25  
26  import javax.servlet.ServletContext;
27  
28  /**
29   * <a href="PortletTitleComparator.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class PortletTitleComparator
34      implements Comparator<Portlet>, Serializable {
35  
36      public PortletTitleComparator(Locale locale) {
37          _locale = locale;
38      }
39  
40      /**
41       * @deprecated
42       */
43      public PortletTitleComparator(long companyId, Locale locale) {
44          this(locale);
45      }
46  
47      public PortletTitleComparator(
48          ServletContext servletContext, Locale locale) {
49  
50          _servletContext = servletContext;
51          _locale = locale;
52      }
53  
54      public int compare(Portlet portlet1, Portlet portlet2) {
55          String portletTitle1 = StringPool.BLANK;
56          String portletTitle2 = StringPool.BLANK;
57  
58          if (_servletContext != null) {
59              portletTitle1 = PortalUtil.getPortletTitle(
60                  portlet1, _servletContext, _locale);
61              portletTitle2 = PortalUtil.getPortletTitle(
62                  portlet2, _servletContext, _locale);
63          }
64          else {
65              portletTitle1 = PortalUtil.getPortletTitle(portlet1, _locale);
66              portletTitle2 = PortalUtil.getPortletTitle(portlet2, _locale);
67          }
68  
69          return portletTitle1.compareTo(portletTitle2);
70      }
71  
72      private Locale _locale;
73      private ServletContext _servletContext;
74  
75  }