1 25 29 package org.jresearch.gossip.tags; 30 31 import java.io.IOException ; 32 33 import javax.servlet.http.HttpServletResponse ; 34 import javax.servlet.http.HttpSession ; 35 import javax.servlet.jsp.JspException ; 36 import javax.servlet.jsp.JspWriter ; 37 import javax.servlet.jsp.tagext.TagSupport ; 38 39 import org.apache.log.Logger; 40 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 41 import org.jresearch.gossip.IConst; 42 import org.jresearch.gossip.beans.forum.Topic; 43 import org.jresearch.gossip.beans.user.User; 44 import org.jresearch.gossip.exception.SystemException; 45 import org.jresearch.gossip.log.avalon.JGossipLog; 46 47 52 public class PageRefTag extends TagSupport { 53 54 57 private Logger log; 58 59 private String threadBean; 61 62 private String forumId; 64 65 68 public PageRefTag() { 69 super(); 70 try { 71 log = JGossipLog.getInstance().getAppLogger(); 72 } catch (SystemException e) { 73 } 74 } 75 76 private void eval() throws JspException { 77 forumId = ExpressionEvaluatorManager.evaluate("forumId", forumId, 78 Integer .class, this, pageContext).toString(); 79 } 80 81 89 public int doStartTag() throws JspException { 90 eval(); 91 92 try { 93 HttpSession session = pageContext.getSession(); 94 HttpServletResponse response = (HttpServletResponse ) pageContext 95 .getResponse(); 96 User user = (User) session.getAttribute(IConst.SESSION.USER_KEY); 97 Topic t = (Topic) pageContext.getAttribute(threadBean); 98 int total = (int) t.getMessagesCount(); 99 100 if (total > user.getSettings().getMes_per_page()) { 101 StringBuffer links = new StringBuffer ("("); 102 103 int rep = (int) Math.floor(total 104 / user.getSettings().getMes_per_page()) + 1; 105 int i = 1; 106 107 while ((i <= rep) 108 && (((i - 1) * user.getSettings().getMes_per_page()) < total)) { 109 StringBuffer href = new StringBuffer (); 110 links.append("<a HREF=\""); 111 href.append("ShowThread.do?fid="); 112 href.append(forumId); 113 href.append("&tid="); 114 href.append(t.getThreadid()); 115 href.append("&block="); 116 href.append((i - 1) * user.getSettings().getMes_per_page()); 117 links.append(response.encodeURL(href.toString())); 118 links.append("\" class=\"thread_name\" >"); 119 links.append(i); 120 links.append("</a>"); 121 122 if ((++i) <= rep) { 123 links.append(", "); 124 } 125 } 126 127 links.append(")"); 128 129 JspWriter out = pageContext.getOut(); 130 out.print(links.toString()); 131 } 132 } catch (IOException e) { 133 if (log.isErrorEnabled()) { 134 log.error("PageRefTag::", e); 135 } 136 throw new JspException ("error in PageRefTag tag:", e); 137 } 138 139 return (SKIP_BODY); 140 } 141 142 147 public String getForumId() { 148 return forumId; 149 } 150 151 156 public String getThreadBean() { 157 return threadBean; 158 } 159 160 165 public void setForumId(String string) { 166 forumId = string; 167 } 168 169 174 public void setThreadBean(String string) { 175 threadBean = string; 176 } 177 } 178 | Popular Tags |