1 16 package dlog4j.tags; 17 18 import java.text.DateFormat ; 19 import java.text.SimpleDateFormat ; 20 import java.util.List ; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.JspException ; 24 25 import net.sf.hibernate.Session; 26 27 import org.apache.commons.lang.StringUtils; 28 29 import dlog4j.Globals; 30 import dlog4j.ParamManager; 31 import dlog4j.ReplyManager; 32 import dlog4j.SiteManager; 33 import dlog4j.formbean.SiteForm; 34 import dlog4j.formbean.UserForm; 35 36 40 public class RepliesTag extends DlogBaseTag { 41 42 public final static int PAGE_PER_SCREEN = 10; 43 44 public final static DateFormat FMT_DATE = new SimpleDateFormat ("yyyyMMdd"); 45 46 int catid = -1; String search = null; int year = -1; 49 int month = -1; 50 int date = -1; String sort = null; int userid = -1; 53 int size = -1; 54 55 58 public int doStartTag() throws JspException { 59 Session ssn = null; 61 try{ 62 ssn = getSession(); 63 SiteForm site = SiteManager.getCurrentSite(pageContext.getRequest()); 64 if(catid==-1) 65 try{ 66 catid = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_CATEGORYID)); 67 }catch(Exception e){} 68 if(year==-1) 69 try{ 70 year = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_YEAR)); 71 }catch(Exception e){} 72 if(month==-1) 73 try{ 74 month = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_MONTH)); 75 }catch(Exception e){} 76 if(date==-1) 77 try{ 78 date = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_DATE)); 79 }catch(Exception e){} 80 if(userid==-1) 81 try{ 82 userid = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_USER)); 83 }catch(Exception e){} 84 String search = pageContext.getRequest().getParameter("query"); 85 86 UserForm loginUser = UserForm.getLoginUser((HttpServletRequest )pageContext.getRequest()); 87 List searchReplies = null; 88 int Replycount = 0; 89 if(StringUtils.isEmpty(search)) 90 Replycount = ReplyManager.getRepliesCount(ssn,site,loginUser,catid,userid,year,month,date); 91 else { 92 searchReplies = ReplyManager.searchAllReplies(ssn,site,loginUser,catid,search,sort); 93 Replycount = searchReplies.size(); 94 } 96 pageContext.setAttribute(RepliesTei.REPLY_COUNT,new Integer (Replycount)) ; 98 int perPage = size; 100 if(perPage<1) 101 perPage = ParamManager.getIntParam(ssn,site,"REPLIES_PER_PAGE",10); 102 pageContext.setAttribute(RepliesTei.PER_PAGE,new Integer (perPage)) ; 103 int pageCount = (Replycount / perPage) + (((Replycount%perPage)>0)?1:0); 105 pageContext.setAttribute(RepliesTei.PAGE_COUNT,new Integer (pageCount)) ; 106 int screenCount = (pageCount / PAGE_PER_SCREEN) + (((pageCount%PAGE_PER_SCREEN)>0)?1:0); 108 pageContext.setAttribute(RepliesTei.SCREEN_COUNT,new Integer (screenCount)); 109 int curPage = 1; 111 try{ 112 curPage = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_PAGE)); 113 }catch(Exception e){} 114 pageContext.setAttribute(RepliesTei.CUR_PAGE, new Integer (curPage)); 115 if(sort==null) 117 sort = pageContext.getRequest().getParameter("sort"); 118 int from = (curPage-1)*perPage; 119 if(from<0) 120 from = 0; 121 if(StringUtils.isEmpty(search)) { 122 List replies = ReplyManager.listReplies(ssn,site,loginUser,catid,userid,from,perPage,sort,year,month,date); 123 pageContext.setAttribute(id,replies); 124 String timestr = null; 126 if(year!=-1&&month!=-1&&date!=-1) 127 timestr = year+"年"+month+"月"+date+"日"; 128 else 129 if(year!=-1&&month!=-1) 130 timestr = year+"年"+month+"月"; 131 else 132 if(year!=-1) 133 timestr = year+"年"; 134 if(timestr!=null) 135 pageContext.setAttribute(RepliesTei.TIME_STR,timestr); 136 } 137 else { 138 int to = from+perPage; 139 if(to>searchReplies.size()) 140 to = searchReplies.size(); 141 142 if(from>searchReplies.size()) 143 from = searchReplies.size(); 144 pageContext.setAttribute(id, searchReplies.subList(from,to)); 146 } 147 }catch(Exception e){ 148 throw new JspException (e); 149 }finally{ 150 try{ 151 closeSession(ssn); 152 }catch(Exception e){} 153 } 154 userid = -1; 157 size = -1; 158 return EVAL_BODY_INCLUDE; 159 } 160 161 164 public void release() { 165 catid = -1; 166 search = null; 167 date = -1; 168 year = -1; 169 month = -1; 170 sort = null; 171 userid = -1; 172 size = -1; 173 } 174 175 178 public int doEndTag() throws JspException { 179 release(); 180 return EVAL_PAGE; 181 } 182 185 public int getCatid() { 186 return catid; 187 } 188 189 192 public String getSearch() { 193 return search; 194 } 195 196 199 public void setCatid(int i) { 200 catid = i; 201 } 202 203 206 public void setCatid(String string) { 207 try{ 208 catid = Integer.parseInt(string); 209 }catch(Exception e){} 210 } 211 212 215 public void setSearch(String string) { 216 search = string; 217 } 218 219 222 public int getDate() { 223 return date; 224 } 225 226 229 public void setDate(int string) { 230 date = string; 231 } 232 233 236 public String getSort() { 237 return sort; 238 } 239 240 243 public void setSort(String string) { 244 sort = string; 245 } 246 247 250 public int getMonth() { 251 return month; 252 } 253 254 257 public int getYear() { 258 return year; 259 } 260 261 264 public void setMonth(int i) { 265 month = i; 266 } 267 268 271 public void setYear(int i) { 272 year = i; 273 } 274 275 public int getUserid() { 276 return userid; 277 } 278 public void setUserid(int userid) { 279 this.userid = userid; 280 } 281 public int getSize() { 282 return size; 283 } 284 public void setSize(int size) { 285 this.size = size; 286 } 287 } 288 | Popular Tags |