1 25 26 package com.j2biz.blogunity.web.servlet; 27 28 import java.io.IOException ; 29 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import javax.servlet.http.HttpSession ; 34 35 import org.apache.commons.logging.Log; 36 import org.apache.commons.logging.LogFactory; 37 38 import com.j2biz.blogunity.IConstants; 39 import com.j2biz.blogunity.exception.BlogunityException; 40 import com.j2biz.blogunity.i18n.I18N; 41 import com.j2biz.blogunity.i18n.I18NStatusFactory; 42 import com.j2biz.blogunity.pojo.User; 43 import com.j2biz.blogunity.web.actions.AbstractAction; 44 45 52 public class MyServlet extends ActionServlet { 53 56 private static final long serialVersionUID = 3256726190864480567L; 57 60 private static final Log log = LogFactory.getLog(MyServlet.class); 61 62 protected void doJob(HttpServletRequest request, HttpServletResponse response) 63 throws ServletException , IOException { 64 65 if (log.isDebugEnabled()) { 66 log.debug("doJob(HttpServletRequest, HttpServletResponse) - start"); 67 } 68 69 if (request.getRequestURI().endsWith(".jpg") || request.getRequestURI().endsWith(".jpeg") 71 || request.getRequestURI().endsWith(".gif") 72 || request.getRequestURI().endsWith(".png")) { 73 74 return; } 75 76 77 User user = null; 78 HttpSession session = request.getSession(false); 79 if (session != null) 80 user = (User) session.getAttribute(IConstants.Session.USER); 81 82 if (user == null) { 83 BlogunityException ex = new BlogunityException(I18NStatusFactory 84 .create(I18N.ERRORS.USER_NOT_LOGGED)); 85 throw new ServletException (ex); 86 } 87 88 95 String requestAction = getActionName(request); 96 97 AbstractAction action = null; 98 String result; 99 100 String actionClass = actionProperties.getProperty(requestAction); 101 if (actionClass == null) { 102 BlogunityException ex = new BlogunityException(I18NStatusFactory.create( 104 I18N.ERRORS.ACTION_NOT_FOUND, requestAction)); 105 throw new ServletException (ex); 106 } 107 108 try { 109 action = (AbstractAction) Class.forName(actionClass).newInstance(); 111 executeAction(action, request, response); 112 113 } catch (BlogunityException e) { 114 throw new ServletException (e); 115 } catch (Exception e) { 116 BlogunityException ex = new BlogunityException(I18NStatusFactory.create( 118 I18N.ERRORS.ACTION_INITIALIZATION_FAILED, e)); 119 throw new ServletException (ex); 120 } 121 122 if (log.isDebugEnabled()) { 123 log.debug("doJob(HttpServletRequest, HttpServletResponse) -end"); 124 } 125 126 } 127 128 133 protected String getDefaultActionName() { 134 return "index"; 135 } 136 137 142 protected String getServletPrefix() { 143 return "my"; 144 } 145 146 151 protected String getActionPropertiesPath() { 152 return "/com/j2biz/blogunity/web/actions/my/my.actions"; 153 } 154 155 } | Popular Tags |