package com.scce.sk.entity;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class SplitPager extends BodyTagSupport
{
private int pageSize;
private List pagelist;
private HttpServletRequest request;
private int i;
private List currentPageList;
private String emptyMessage;
private int pageFootStyle = 1;
private int pageNo = 1;
public int doStartTag()
throws JspException
{
try
{
this.request = ((HttpServletRequest)this.pageContext.getRequest());
JspWriter out = this.pageContext.getOut();
HttpServletRequest request = (HttpServletRequest)this.pageContext.getRequest();
String how = request.getParameter("howPage");
setPageNo();
if (how != null)
{
setCurrentPageNo(Integer.parseInt(how));
}
this.i = 1;
this.currentPageList = getCurrentPageList();
this.pageContext.setAttribute("row", this.currentPageList.get(0));
}
catch (Exception e) {
e.printStackTrace();
}
return this.EVAL_BODY_INCLUDE;
}
public int doAfterBody()
throws JspException
{
try
{
if (this.pagelist == null)
{
return 0;
}
if (this.i < this.currentPageList.size())
{
//break label67;
this.pageContext.setAttribute("row", this.currentPageList.get(this.i));
this.i += 1;
return this.EVAL_BODY_AGAIN;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return 0;
}
public int doEndTag() throws JspException
{
try {
this.i = 1;
JspWriter out = this.pageContext.getOut();
if (this.pagelist == null)
{
out.print("<center>" + this.emptyMessage + "</center>");
return this.EVAL_PAGE;
}
// String bodyContent = this.bodyContent.getString();
// out.print(bodyContent);
out.println("<table align=\"right\"><tr><td><br/><form id=\"frm_page\" name=\"frm_page\" method=\"post\">");
Enumeration enumeration = this.request.getParameterNames();
while (enumeration.hasMoreElements())
{
String name = (String)enumeration.nextElement();
if ((!("howPage".equals(name))) && (!("pageNo".equals(name))))
{
String value = new String(this.request.getParameter(name).getBytes("iso-8859-1"));
out.println("<input type=\"hidden\" id=\"" + name + "\" name=\"" + name + "\" value=\"" + value + "\">");
}
}
out.println("<input type=\"hidden\" id=\"howPage\" name=\"howPage\" /><input type=\"hidden\" id=\"pageNo\" name=\"pageNo\" value=\"" + this.pageNo + "\"" + " />");
out.println("<a href=javascript:document.getElementById(\"howPage\").value=1;document.frm_page.submit();>李為</a>");
if (this.pageNo > 1)
{
out.println("<a href=javascript:document.getElementById(\"howPage\").value=2;document.frm_page.submit();>吮為</a>");
}
else if (this.pageFootStyle == 2)
{
out.println("<a onclick=\"return false\" href=javascript:document.getElementById(\"howPage\").value=2;document.frm_page.submit();>吮為</a>");
}
if (this.pageNo < getPageCount())
{
out.println("<a href=javascript:document.getElementById(\"howPage\").value=3;document.frm_page.submit();>芟為</a>");
}
else if (this.pageFootStyle == 2)
{
out.println("<a onclick=\"return false\" href=javascript:document.getElementById(\"howPage\").value=3;document.frm_page.submit();>芟為</a>");
}
out.println("<a href=javascript:document.getElementById(\"howPage\").value=4;document.frm_page.submit();>人為</a>");
out.println("�<font color=blue>" + this.pageNo + "</font>為/�<font color=blue>" + getPageCount() + "</font>為 </form></td></tr></table>");
}
catch (Exception e)
{
e.printStackTrace();
}
return this.EVAL_PAGE;
}
public void setPagelist(List pagelist)
{
this.pagelist = pagelist;
}
private void setPageNo()
{
if (this.request.getParameter("pageNo") == null)
{
this.pageNo = 1;
}
else
{
this.pageNo = Integer.parseInt(this.request.getParameter("pageNo").toString());
}
}
private void setCurrentPageNo(int how)
{
switch (how)
{
case 1:
this.pageNo = 1;
break;
case 2:
if (this.pageNo <= 1)
return;
this.pageNo -= 1;
break;
case 3:
if (this.pageNo >= getPageCount())
return;
this.pageNo += 1;
break;
case 4:
this.pageNo = getPageCount();
}
}
private List getCurrentPageList()
{
int startIndex = (this.pageNo - 1) * this.pageSize;
int endIndex = startIndex + this.pageSize;
if (endIndex > this.pagelist.size())
{
endIndex = this.pagelist.size();
}
List saveList = new ArrayList();
for (int i = startIndex; i < endIndex; ++i)
{
saveList.add(this.pagelist.get(i));
}
return saveList;
}
private int getPageCount()
{
int size = this.pagelist.size();
return ((size % this.pageSize == 0) ? size / this.pageSize : size / this.pageSize + 1);
}
public void setEmptyMessage(String emptyMessage) {
this.emptyMessage = emptyMessage;
}
public void setPageFootStyle(int pageFootStyle) {
this.pageFootStyle = pageFootStyle;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}