View Javadoc
1   /*
2    * Copyright (C) 2003-2012 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.ecm.webui.comparator;
18  
19  import java.util.Comparator;
20  
21  import javax.jcr.Node;
22  
23  import org.exoplatform.ecm.webui.utils.Utils;
24  
25  /**
26   * Created by The eXo Platform SAS
27   * Author : eXoPlatform
28   *          vinh_nguyen@exoplatform.com
29   * 8 May 2012  
30   */
31  public class NodeTitleComparator implements Comparator<Node> {
32  
33    public static final String ASCENDING_ORDER = "Ascending" ;
34    private String order_ ;
35  
36    public NodeTitleComparator(String pOrder) {
37      order_ = pOrder ;
38    }
39  
40    public int compare(Node node1, Node node2) {
41      try{
42        String titleNode1 = Utils.getTitle(node1);
43        String titleNode2 = Utils.getTitle(node2);
44        if(order_.equals(ASCENDING_ORDER)) {
45          return titleNode1.compareToIgnoreCase(titleNode2) ;
46        }
47        return titleNode2.compareToIgnoreCase(titleNode1) ;
48      }catch (Exception e) {
49        return 0;
50      }
51    }
52  }