package kr.or.struts.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p>Title: PageUtil </p>
* <p>Description: Table Page Util </p>
* <p>Copyright: Copyright (c) 2007 Maxoft.Inc</p>
* <p>Company: Maxoft.Inc </p>
* @author Kim sooki
* @version 1.0
*/
public class PageUtil {
// 객체없이 사용하는 utitlity클래스
private PageUtil(){
}
private static Log logger = LogFactory.getLog(PageUtil.class);
// 글의 갯수만큼 입력받아 모든페이지의 링크를 생성
// String page : page이름
// int total : 전체 글 갯수
// int showLine : 한페이지에 표시될 글의 갯수
// int current : 현재페이지
public static String getAllPageLink(String page,int total, int showLine,int current){
if(total == 0)
return “”;
StringBuffer buffer = new StringBuffer();
int count = 1;
for(int i = 1; i <= total; i=i+showLine){
buffer.append(“<a href=”);
buffer.append(page);
buffer.append(“PageNo=”);
buffer.append(Integer.toString(count));
buffer.append(“>”);
if(count == current){
buffer.append(“<strong>”);
buffer.append(Integer.toString(count));
buffer.append(“</strong>”);
} else
buffer.append(Integer.toString(count));
buffer.append(“</A> ”);
count++;
}
return buffer.toString();
}
// 전체 글수와 현재페이지수를 입력하여 전체 페이지수를 구함
public static int getMaxPage(int total, int showLine){
if(total <= 0){
return 0;
}
int temp = total / showLine;
int mode = total % showLine;
if(mode != 0){
temp++;
}
return temp;
}
// 페이지에서 시작되는 가장 나중번호를 구한다.
public static int getRowStart(int total, int showLine,int currentPage){
if(total <= showLine){
return total;
}
int temp = showLine * (currentPage-1);
temp = total – temp;
if(temp < 0){
temp = 0;
}
return temp;
}
// 페이지에서 시작되는 가장 적은 번호를 구한다.
public static int getRowEnd(int total, int showLine,int currentPage){
if(total <= showLine){
return 0;
}
int temp = (showLine * (currentPage -1)) + showLine;
temp = total – temp;
if(temp < 0 ){
temp = 0;
}
return temp;
}
}