1 30 31 34 package com.nightlabs.webapp; 35 36 import java.util.ArrayList ; 37 import java.util.HashMap ; 38 import java.util.List ; 39 import java.util.Map ; 40 41 45 public class PageLink 46 { 47 48 public static List createPageLinks(Map urlParams, MultiPageSearchResult searchResult) 49 { 50 int currentPageIndex = searchResult.getPageIndex(); 51 52 List pageLinks = new ArrayList (); 53 int pageCount = searchResult.getItemsFound() / searchResult.getItemsPerPage(); 54 if (searchResult.getItemsFound() % searchResult.getItemsPerPage() != 0) 55 ++pageCount; 56 57 boolean haveDots = true; 58 for (int i = 0; i < pageCount; ++i) { 59 if (i <= 2 || i >= pageCount - 3 || (i >= currentPageIndex - 2 && i <= currentPageIndex + 2)) { 60 PageLink pl = new PageLink(); 61 pl.setCaption(Integer.toString(i)); 62 pl.setPageIndex(i); 63 64 if (i != currentPageIndex) { 65 pl.setUrlParams(new HashMap (urlParams)); 66 pl.setUrlParam("pageIndex", Integer.toString(i)); 67 pl.setUrlParam("itemsPerPage", new Integer (searchResult.getItemsPerPage())); 68 } pageLinks.add(pl); 70 haveDots = true; 71 } 72 else { 73 if (haveDots) { 74 PageLink pl = new PageLink(); 75 pl.setCaption("..."); 76 pageLinks.add(pl); 77 haveDots = false; 78 } 79 } 80 } 81 82 return pageLinks; 83 } 84 85 private int pageIndex; 86 private String caption; 87 private Map urlParams = null; 88 89 92 public String getCaption() { 93 return caption; 94 } 95 98 public void setCaption(String caption) { 99 this.caption = caption; 100 } 101 104 public int getPageIndex() { 105 return pageIndex; 106 } 107 110 public void setPageIndex(int pageIndex) { 111 this.pageIndex = pageIndex; 112 } 113 116 public Map getUrlParams() { 117 return urlParams; 118 } 119 122 public void setUrlParams(Map url) { 123 this.urlParams = url; 124 } 125 126 public void setUrlParam(String name, Object value) 127 { 128 if (urlParams == null) 129 urlParams = new HashMap (); 130 131 urlParams.put(name, value.toString()); 132 } 133 134 } 135 | Popular Tags |