001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.softwarecatalog.util;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryCreateDateComparator;
019    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryModifiedDateComparator;
020    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryNameComparator;
021    import com.liferay.portlet.softwarecatalog.util.comparator.ProductEntryTypeComparator;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class SCUtil {
027    
028            public static OrderByComparator getProductEntryOrderByComparator(
029                    String orderByCol, String orderByType) {
030    
031                    boolean orderByAsc = false;
032    
033                    if (orderByType.equals("asc")) {
034                            orderByAsc = true;
035                    }
036    
037                    OrderByComparator orderByComparator = null;
038    
039                    if (orderByCol.equals("create-date")) {
040                            orderByComparator =
041                                    new ProductEntryCreateDateComparator(orderByAsc);
042                    }
043                    else if (orderByCol.equals("modified-date")) {
044                            orderByComparator =
045                                    new ProductEntryModifiedDateComparator(orderByAsc);
046                    }
047                    else if (orderByCol.equals("name")) {
048                            orderByComparator = new ProductEntryNameComparator(orderByAsc);
049                    }
050                    else if (orderByCol.equals("type")) {
051                            orderByComparator = new ProductEntryTypeComparator(orderByAsc);
052                    }
053    
054                    return orderByComparator;
055            }
056    
057    }