1 14 41 42 package org.jahia.data.viewhelper.sitemap; 43 44 import java.util.Comparator ; 45 46 57 final class SiteMapComparator implements Comparator { 58 59 public SiteMapComparator(String languageCode, int orderBy, int sortOrder) { 60 this.languageCode = languageCode; 61 this.sortOrder = sortOrder; 62 this.orderBy = orderBy; 63 } 64 65 72 public int compare(Object object1, Object object2) { 73 PageSiteMap pageSiteMap1 = (PageSiteMap)object1; 74 PageSiteMap pageSiteMap2 = (PageSiteMap)object2; 75 if (orderBy == FlatSiteMapViewHelper.ORDER_BY_PAGE_TITLE) { 76 String pageTitle1 = pageSiteMap1.getPageTitle(languageCode).toLowerCase(); 77 String pageTitle2 = pageSiteMap2.getPageTitle(languageCode).toLowerCase(); 78 return sortOrder == FlatSiteMapViewHelper.ASCENDING_ORDER ? 79 pageTitle1.compareTo(pageTitle2) : 80 pageTitle2.compareTo(pageTitle1); 81 } else if (orderBy == FlatSiteMapViewHelper.ORDER_BY_PAGE_ID) { 82 return sortOrder == FlatSiteMapViewHelper.ASCENDING_ORDER ? 83 pageSiteMap1.getPageID() - pageSiteMap2.getPageID() : 84 pageSiteMap2.getPageID() - pageSiteMap1.getPageID(); 85 } else if (orderBy == FlatSiteMapViewHelper.ORDER_BY_PAGE_LEVEL) { 86 String pageTitle1 = pageSiteMap1.getPageTitle(languageCode).toLowerCase(); 87 String pageTitle2 = pageSiteMap2.getPageTitle(languageCode).toLowerCase(); 88 boolean diff = pageSiteMap2.getPageLevel() - pageSiteMap1.getPageLevel() == 0; return sortOrder == FlatSiteMapViewHelper.ASCENDING_ORDER ? 90 diff ? 91 pageTitle1.compareTo(pageTitle2) : 92 pageSiteMap1.getPageLevel() - pageSiteMap2.getPageLevel() 93 : 94 diff ? 95 pageTitle2.compareTo(pageTitle1) : 96 pageSiteMap2.getPageLevel() - pageSiteMap1.getPageLevel(); 97 } 98 return 0; 100 } 101 102 private String languageCode; 104 private int orderBy; 105 private int sortOrder; 106 107 private static org.apache.log4j.Logger logger = 108 org.apache.log4j.Logger.getLogger(PageSiteMap.class); 109 } 110 | Popular Tags |