1 16 package dlog4j.tags; 17 18 import java.sql.SQLException ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.JspException ; 24 25 import net.sf.hibernate.HibernateException; 26 import net.sf.hibernate.Session; 27 import dlog4j.CategoryManager; 28 import dlog4j.Globals; 29 import dlog4j.LogManager; 30 import dlog4j.SiteManager; 31 import dlog4j.formbean.CategoryForm; 32 import dlog4j.formbean.SiteForm; 33 import dlog4j.formbean.UserForm; 34 35 40 public class CategoryTag extends DlogBaseTag { 41 42 String catid = null; 43 47 boolean security = false; 48 49 boolean sortByNewest = false; 50 51 boolean withLogCount = false; 52 53 boolean addLog = false; 54 55 58 public int doStartTag() throws JspException { 59 if(pageContext.getAttribute(id)==null){ 60 Session session = null; 61 List categories = null; 62 try{ 63 session = getSession(); 64 SiteForm site = SiteManager.getCurrentSite(pageContext.getRequest()); 65 UserForm user = UserForm.getLoginUser((HttpServletRequest )pageContext.getRequest()); 66 if(addLog) 67 categories = CategoryManager.listCategoriesForModify(session,site,user); 68 else 69 categories = CategoryManager.listCategories(session,site,user); 70 Iterator cs = categories.iterator(); 71 while(cs.hasNext()){ 72 CategoryForm cat = (CategoryForm)cs.next(); 73 if(withLogCount) 74 cat.setLogCount(LogManager.getLogCount(session,site,user,cat.getId(),-1,-1,-1,-1)); 75 } 76 int categoryId = -1; 77 try{ 78 categoryId = Integer.parseInt(pageContext.getRequest().getParameter(Globals.PARAM_CATEGORYID)); 79 }catch(Exception e){} 80 for(int i=0;catid!=null&&i<categories.size();i++){ 81 CategoryForm cat = (CategoryForm)categories.get(i); 82 if(cat.getId()==categoryId){ 83 pageContext.setAttribute(catid,cat); 84 break; 85 } 86 } 87 }catch(SQLException e){ 88 throw new JspException (e); 89 }catch(HibernateException e){ 90 throw new JspException (e); 91 }finally{ 92 try{ 93 closeSession(session); 94 }catch(Exception e){} 95 } 96 pageContext.setAttribute(id,categories); 97 } 98 return SKIP_BODY; 99 } 100 101 public int doEndTag() throws JspException { 102 release(); 103 return EVAL_PAGE; 104 } 105 public void release() { 106 catid = null; 107 security = false; 108 109 withLogCount = false; 110 } 111 114 public String getCatid() { 115 return catid; 116 } 117 118 121 public void setCatid(String string) { 122 catid = string; 123 } 124 125 128 public boolean isSecurity() { 129 return security; 130 } 131 132 135 public void setSecurity(boolean b) { 136 security = b; 137 } 138 139 public boolean isWithLogCount() { 140 return withLogCount; 141 } 142 public void setWithLogCount(boolean withLogCount) { 143 this.withLogCount = withLogCount; 144 } 145 public boolean isSortByNewest() { 146 return sortByNewest; 147 } 148 public void setSortByNewest(boolean sortByNewest) { 149 this.sortByNewest = sortByNewest; 150 } 151 public boolean isAddLog() { 152 return addLog; 153 } 154 public void setAddLog(boolean addLog) { 155 this.addLog = addLog; 156 } 157 } 158 | Popular Tags |