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.LogManager; 31 import dlog4j.ParamManager; 32 import dlog4j.SiteManager; 33 import dlog4j.formbean.SiteForm; 34 import dlog4j.formbean.UserForm; 35 36 40 public class LogsTag 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 count = -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 if(search==null) 85 search = pageContext.getRequest().getParameter("query"); 86 87 List searchLogs = null; 88 UserForm loginUser = UserForm.getLoginUser((HttpServletRequest )pageContext.getRequest()); 89 int logcount = 0; 90 if(StringUtils.isEmpty(search)) 91 logcount = LogManager.getLogCount(ssn,site,loginUser,catid,userid,year,month,date); 92 else { 93 searchLogs = LogManager.searchAllLogs(ssn,site,loginUser,catid,search,sort); 94 logcount = searchLogs.size(); 95 } 96 pageContext.setAttribute(LogsTei.LOG_COUNT, new Integer (logcount)); 97 int perPage = (count==-1)?ParamManager.getLogPerPage(ssn,site):count; 98 pageContext.setAttribute(LogsTei.PER_PAGE, new Integer (perPage)); 99 int pageCount = (logcount / perPage) + (((logcount%perPage)>0)?1:0); 100 pageContext.setAttribute(LogsTei.PAGE_COUNT, new Integer (pageCount)); 101 int screenCount = (pageCount / PAGE_PER_SCREEN) + (((pageCount%PAGE_PER_SCREEN)>0)?1:0); 102 pageContext.setAttribute(LogsTei.SCREEN_COUNT, new Integer (screenCount)); 103 int curPage = 1; 104 try{ 105 curPage = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_PAGE)); 106 }catch(Exception e){} 107 pageContext.setAttribute(LogsTei.CUR_PAGE, new Integer (curPage)); 108 if(sort==null) 109 sort = pageContext.getRequest().getParameter("sort"); 110 int from = (curPage-1)*perPage; 111 if(from<0) 112 from = 0; 113 114 if(StringUtils.isEmpty(search)) { 115 List logs = LogManager.listLogs(ssn,site,loginUser,catid,userid,from,perPage,sort,year,month,date); 116 pageContext.setAttribute(id, logs); 117 118 String timestr = null; 120 if(year!=-1&&month!=-1&&date!=-1) 121 timestr = year+"年"+month+"月"+date+"日"; 122 else 123 if(year!=-1&&month!=-1) 124 timestr = year+"年"+month+"月"; 125 else 126 if(year!=-1) 127 timestr = year+"年"; 128 if(timestr!=null) 129 pageContext.setAttribute(LogsTei.TIME_STR,timestr); 130 } 131 else { 132 int to = from+perPage; 133 if(to>searchLogs.size()) 134 to = searchLogs.size(); 135 if(from>searchLogs.size()) 136 from = searchLogs.size(); 137 List logs = searchLogs.subList(from,to); 138 pageContext.setAttribute(id, logs); 139 } 140 }catch(Exception e){ 141 e.printStackTrace(); 142 throw new JspException (e); 143 }finally{ 144 try{ 145 closeSession(ssn); 146 }catch(Exception e){} 147 } 148 userid = -1; 151 return EVAL_BODY_INCLUDE; 152 } 153 154 157 public void release() { 158 catid = -1; 159 search = null; 160 date = -1; 161 year = -1; 162 month = -1; 163 sort = null; 164 userid = -1; 165 count = -1; 166 } 167 168 171 public int doEndTag() throws JspException { 172 release(); 173 return EVAL_PAGE; 174 } 175 178 public int getCatid() { 179 return catid; 180 } 181 182 185 public String getSearch() { 186 return search; 187 } 188 189 192 public void setCatid(int i) { 193 catid = i; 194 } 195 196 199 public void setCatid(String string) { 200 try{ 201 catid = Integer.parseInt(string); 202 }catch(Exception e){} 203 } 204 205 208 public void setSearch(String string) { 209 search = string; 210 } 211 212 215 public int getDate() { 216 return date; 217 } 218 219 222 public void setDate(int string) { 223 date = string; 224 } 225 226 229 public String getSort() { 230 return sort; 231 } 232 233 236 public void setSort(String string) { 237 sort = string; 238 } 239 240 243 public int getMonth() { 244 return month; 245 } 246 247 250 public int getYear() { 251 return year; 252 } 253 254 257 public void setMonth(int i) { 258 month = i; 259 } 260 261 264 public void setYear(int i) { 265 year = i; 266 } 267 268 public int getUserid() { 269 return userid; 270 } 271 public void setUserid(int userid) { 272 this.userid = userid; 273 } 274 public int getCount() { 275 return count; 276 } 277 public void setCount(int count) { 278 this.count = count; 279 } 280 } 281 | Popular Tags |