1 14 41 42 package org.jahia.data.viewhelper.sitemap; 43 44 import java.util.Arrays ; 45 import java.util.HashMap ; 46 import java.util.List ; 47 48 import org.jahia.params.ParamBean; 49 import org.jahia.services.pages.ContentPage; 50 import org.jahia.services.usermanager.JahiaUser; 51 52 64 public class FlatSiteMapViewHelper extends SiteMapViewHelper { 65 66 public static final int ORDER_AS_IS = -1; 68 public static final int ORDER_BY_PAGE_TITLE = 0; 69 public static final int ORDER_BY_PAGE_ID = 1; 70 public static final int ORDER_BY_PAGE_LEVEL = 2; 71 public static final int ASCENDING_ORDER = 0; 72 public static final int DESCENDING_ORDER = 1; 73 74 86 public FlatSiteMapViewHelper(JahiaUser user, ContentPage startPage, 87 int pageInfosFlag, String languageCode, 88 int defaultMaxLevel) { 89 super(user, startPage, pageInfosFlag, languageCode, defaultMaxLevel); 90 _sortedPageSiteMap = new PageSiteMap[getJahiaPageSiteMap().size()]; 92 getJahiaPageSiteMap().toArray(_sortedPageSiteMap); 93 sortSiteMap(languageCode, ORDER_BY_PAGE_TITLE, ASCENDING_ORDER); 95 } 96 97 110 public FlatSiteMapViewHelper(JahiaUser user, ContentPage startPage, 111 int pageInfosFlag, String languageCode, 112 int defaultMaxLevel, PagesFilter pagesFilter, 113 ParamBean jParams) { 114 super(user, startPage, pageInfosFlag, languageCode, defaultMaxLevel, pagesFilter, jParams); 115 _sortedPageSiteMap = new PageSiteMap[getJahiaPageSiteMap().size()]; 117 getJahiaPageSiteMap().toArray(_sortedPageSiteMap); 118 sortSiteMap(languageCode, ORDER_BY_PAGE_TITLE, ASCENDING_ORDER); 120 121 } 122 123 public FlatSiteMapViewHelper(JahiaUser user, List startPages, 124 int pageInfosFlag, String languageCode, 125 int defaultMaxLevel, PagesFilter pagesFilter, 126 ParamBean jParams) { 127 super(user, startPages, pageInfosFlag, languageCode, defaultMaxLevel, true, pagesFilter, jParams); 128 _sortedPageSiteMap = new PageSiteMap[getJahiaPageSiteMap().size()]; 130 getJahiaPageSiteMap().toArray(_sortedPageSiteMap); 131 sortSiteMap(languageCode, ORDER_BY_PAGE_TITLE, ASCENDING_ORDER); 133 } 134 135 142 public void sortSiteMap(String languageCode, int orderBy, int sortOrder) { 143 if (languageCode == null) { 144 languageCode = "en"; 145 } 146 _sortOrder = sortOrder; 147 SiteMapComparator siteMapComparator = new SiteMapComparator(languageCode, orderBy, sortOrder); 148 Arrays.sort(_sortedPageSiteMap, siteMapComparator); 149 } 150 151 155 public int getSortOrder() { 156 return _sortOrder; 157 } 158 159 164 public ContentPage getContentPage(int index) { 165 PageSiteMap pageSiteMap = _sortedPageSiteMap[index]; 166 return pageSiteMap.isDisplayable() ? lookupContentPage(pageSiteMap.getPageID()) : null; 167 } 168 169 175 public String getPageTitle(int index, String languageCode) { 176 return _sortedPageSiteMap[index].getPageTitle(languageCode); 177 } 178 179 184 public int getPageID(int index) { 185 return _sortedPageSiteMap[index].getPageID(); 186 } 187 188 194 public int getPageIndex(int pageID){ 195 PageSiteMap pageSiteMap = null; 196 for ( int i=0 ; i<_sortedPageSiteMap.length ; i++ ){ 197 pageSiteMap = _sortedPageSiteMap[i]; 198 if ( pageSiteMap.getPageID() == pageID ){ 199 return i; 200 } 201 } 202 return -1; 203 } 204 205 211 public int getPageLevel(int index) { 212 return _sortedPageSiteMap[index].getPageLevel(); 213 } 214 215 220 public int getParentPageID(int index) { 221 return _sortedPageSiteMap[index].getParentPageID(); 222 } 223 224 229 public int size() { 230 return _sortedPageSiteMap.length; 231 } 232 233 private int _currentLevel = 0; 234 private int _defaultMaxLevel; 235 private int _maxLevel; private HashMap _availableLanguageCodeMap = new HashMap (); 237 private JahiaUser _user; 238 private int _pageInfosFlag; 239 private String _languageCode; 240 241 private int _sortOrder; 243 private int _orderBy; 244 private PageSiteMap[] _sortedPageSiteMap; 245 246 private static org.apache.log4j.Logger logger = 247 org.apache.log4j.Logger.getLogger(SiteMapViewHelper.class); 248 249 } 250 | Popular Tags |