1 25 26 package com.j2biz.blogunity.web.actions.my; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.http.HttpSession ; 31 32 import org.apache.commons.logging.Log; 33 import org.apache.commons.logging.LogFactory; 34 35 import com.j2biz.blogunity.IConstants; 36 import com.j2biz.blogunity.dao.UserDAO; 37 import com.j2biz.blogunity.exception.BlogunityException; 38 import com.j2biz.blogunity.i18n.I18N; 39 import com.j2biz.blogunity.i18n.I18NStatusFactory; 40 import com.j2biz.blogunity.pojo.User; 41 import com.j2biz.blogunity.web.actions.AbstractAction; 42 43 50 public abstract class MyAbstractAction extends AbstractAction { 51 54 private static final Log log = LogFactory.getLog(AbstractAction.class); 55 56 protected User user = null; 57 58 64 public void init(HttpServletRequest request, HttpServletResponse response, String actionName) 65 throws BlogunityException { 66 67 super.init(request, response, actionName); 68 69 HttpSession s = request.getSession(false); 71 if (s == null) { throw new BlogunityException(I18NStatusFactory 72 .create(I18N.ERRORS.USER_NOT_LOGGED)); } 73 74 Object o = s.getAttribute(IConstants.Session.USER); 75 if (o != null) { 76 try { 77 user = (User) o; 78 (new UserDAO()).attachToSession(user); 79 } catch (ClassCastException e) { 80 throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.USER_NOT_LOGGED, 81 e)); 82 } catch (BlogunityException e) { 83 throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.USER_NOT_LOGGED, 84 e)); 85 } 86 } 87 } 88 89 92 protected User getUser() { 93 return user; 94 } 95 96 } | Popular Tags |