| PortletTitleComparator.java |
1 /**
2 * Copyright (c) 2000-2009 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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20 package com.liferay.portal.util.comparator;
21
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.model.Portlet;
24 import com.liferay.portal.util.PortalUtil;
25
26 import java.io.Serializable;
27
28 import java.util.Comparator;
29 import java.util.Locale;
30
31 import javax.servlet.ServletContext;
32
33 /**
34 * <a href="PortletTitleComparator.java.html"><b><i>View Source</i></b></a>
35 *
36 * @author Brian Wing Shun Chan
37 *
38 */
39 public class PortletTitleComparator
40 implements Comparator<Portlet>, Serializable {
41
42 public PortletTitleComparator(long companyId, Locale locale) {
43 _companyId = companyId;
44 _locale = 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(
66 portlet1, _companyId, _locale);
67 portletTitle2 = PortalUtil.getPortletTitle(
68 portlet2, _companyId, _locale);
69 }
70
71 return portletTitle1.compareTo(portletTitle2);
72 }
73
74 private long _companyId;
75 private ServletContext _servletContext;
76 private Locale _locale;
77
78 }