KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > content > comparators > ContainerRankingComparator


1 package org.jahia.content.comparators;
2
3 import java.util.Comparator JavaDoc;
4
5 import org.jahia.data.containers.JahiaContainer;
6 import org.jahia.exceptions.JahiaException;
7 import org.jahia.params.ParamBean;
8 import org.jahia.services.containers.ContentContainer;
9
10 /**
11  * <p>Title: This container comparator orders containers by rank</p>
12  * <p>Description: </p>
13  * <p>Copyright: Copyright (c) 2002</p>
14  * <p>Company: Jahia Ltd</p>
15  * @author Serge Huber
16  * @version 1.0
17  */

18
19 public class ContainerRankingComparator implements Comparator JavaDoc {
20
21     private static org.apache.log4j.Logger logger =
22         org.apache.log4j.Logger.getLogger(ContainerRankingComparator.class);
23
24     private ParamBean paramBean;
25
26     public ContainerRankingComparator(ParamBean paramBean) {
27         this.paramBean = paramBean;
28     }
29
30     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
31         ContentContainer leftContainer = (ContentContainer) o1;
32         ContentContainer rightContainer = (ContentContainer) o2;
33         try {
34             JahiaContainer leftJahiaContainer = leftContainer.getJahiaContainer(
35                 paramBean, paramBean.getEntryLoadRequest());
36             JahiaContainer rightJahiaContainer = rightContainer.
37                                                  getJahiaContainer(paramBean,
38                 paramBean.getEntryLoadRequest());
39             if (leftJahiaContainer == null) {
40                 logger.warn("Left JahiaContainer in comparison is null");
41                 return -1;
42             }
43             if (rightJahiaContainer == null) {
44                 logger.warn("Right JahiaContainer in comparison is null");
45                 return 1;
46             }
47             return new Integer JavaDoc(leftJahiaContainer.getRank()).compareTo(new Integer JavaDoc(rightJahiaContainer.getRank()));
48         } catch (JahiaException je) {
49             logger.error("Error while accessing Jahia containers for entry load request " + paramBean.getEntryLoadRequest(), je);
50             return 0;
51         }
52     }
53
54     public boolean equals(Object JavaDoc obj) {
55         if (obj instanceof ContainerRankingComparator) {
56             return true;
57         } else {
58             return false;
59         }
60     }
61
62 }
63
Popular Tags