1 package org.javabb.action.infra; 2 3 import java.util.HashMap ; 4 import java.util.List ; 5 import java.util.Map ; 6 7 import javax.servlet.http.HttpSession ; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.javabb.infra.ApplicationContext; 12 import org.javabb.infra.JbbConfig; 13 import org.javabb.infra.Online; 14 import org.javabb.infra.PagedList; 15 import org.javabb.infra.UserContext; 16 import org.javabb.vo.Forum; 17 import org.javabb.vo.Topic; 18 import org.javabb.vo.User; 19 import org.springframework.web.util.HtmlUtils; 20 21 import com.opensymphony.webwork.ServletActionContext; 22 import com.opensymphony.webwork.util.Timer; 23 import com.opensymphony.xwork.ActionContext; 24 import com.opensymphony.xwork.ActionSupport; 25 26 41 42 47 public class ActionSuper extends ActionSupport { 48 49 protected final Log log = LogFactory.getLog(getClass()); 50 51 52 private Timer timer = new Timer(); 53 54 55 private Online online; 56 57 58 private JbbConfig jbbConfig; 59 60 61 private String url; 62 63 64 protected int _page = 1; 65 66 67 private String temp; 68 69 private String captchafield; 70 71 private PagedList _pagedResult; 72 73 76 public ApplicationContext getApplication() { 77 return ApplicationContext.getContext(); 78 } 79 80 83 public void setOnline(Online online) { 84 this.online = online; 85 } 86 87 90 public void setJbbConfig(JbbConfig jbbConfig) { 91 this.jbbConfig = jbbConfig; 92 } 93 94 98 public JbbConfig getJbbConfig() { 99 return jbbConfig; 100 } 101 102 105 public Timer getTimer() { 106 return timer; 107 } 108 109 113 public Online getOnline() { 114 return online; 115 } 116 117 120 public String getUrl() { 121 return url; 122 } 123 124 127 public void setUrl(String url) { 128 this.url = url; 129 } 130 131 134 public int getPage() { 135 return _page; 136 } 137 138 141 public void setPage(int page) { 142 this._page = page; 143 } 144 145 148 public List getPages() { 149 return (List ) getSessionAttribute("pages"); 150 } 151 152 155 public Integer getLastPage() { 156 return (Integer ) getSessionAttribute("last_page"); 157 } 158 159 162 public String getTemp() { 163 return temp; 164 } 165 166 169 public void setTemp(String temp) { 170 this.temp = temp; 171 } 172 173 177 public String htmlEscape(String text) { 178 return HtmlUtils.htmlEscape(text); 179 } 180 181 186 protected void setParameter(String name, Object value) { 187 Map params = new HashMap (ActionContext.getContext().getParameters()); 188 params.put(name, value); 189 ActionContext.getContext().setParameters(params); 190 } 191 192 197 protected void setViewObject(String name, Object value) { 198 Map map = new HashMap (); 199 map.put(name, value); 200 ActionContext.getContext().getValueStack().push(map); 201 } 202 203 211 public Object getSessionAttribute(String attributeName) { 212 return ActionContext.getContext().getSession().get(attributeName); 213 } 214 215 224 public void setSessionAttribute(String nameSession, Object objectSession) { 225 ActionContext ctx = ActionContext.getContext(); 226 Map session = ctx.getSession(); 227 session.put(nameSession, objectSession); 228 } 229 230 237 public void removeSessionAttribute(String attributeName) { 238 ActionContext.getContext().getSession().remove(attributeName); 239 } 240 241 public PagedList getPagedResult() { 242 return _pagedResult; 243 } 244 245 public void setPagedResult(PagedList pagedResult) { 246 _pagedResult = pagedResult; 247 } 248 249 public boolean isTopicRead(Topic topic) { 250 try { 251 return UserContext.getContext().isTopicRead(topic); 252 } catch (RuntimeException e) { 253 log.debug(e.getMessage(), e); 254 return true; 255 } 256 } 257 258 public boolean isForumRead(Forum forum) { 259 try { 260 return false; 261 } catch (RuntimeException e) { 263 log.debug(e.getMessage(), e); 264 return false; 265 } 266 } 267 268 269 273 public boolean checkCaptcha(){ 274 HttpSession ss = ServletActionContext.getRequest().getSession(); 275 if(ss != null){ 276 String c = (String )ss.getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) ; 277 if (c != null && getCaptchafield() != null) { 278 if (c.equals(getCaptchafield())) { 279 return true; 280 }else { 281 return false; 282 } 283 } 284 } 285 return false; 286 } 287 288 289 294 public User getUserLogged() throws Exception { 295 return (User)this.getSessionAttribute("jbbuser"); 296 } 297 298 public String getCaptchafield() { 299 return captchafield; 300 } 301 302 public void setCaptchafield(String captchafield) { 303 this.captchafield = captchafield; 304 } 305 306 } | Popular Tags |