1 package org.jahia.content.comparators; 2 3 import java.util.Comparator ; 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 18 19 public class ContainerRankingComparator implements Comparator { 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 o1, Object 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 (leftJahiaContainer.getRank()).compareTo(new Integer (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 obj) { 55 if (obj instanceof ContainerRankingComparator) { 56 return true; 57 } else { 58 return false; 59 } 60 } 61 62 } 63 | Popular Tags |