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 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 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.web.actions.AbstractAction; 41 42 49 public class ExecServlet extends ActionServlet { 50 53 private static final long serialVersionUID = 3257847684017961013L; 54 57 private static final Log log = LogFactory.getLog(ExecServlet.class); 58 59 64 protected String getActionPropertiesPath() { 65 return "/com/j2biz/blogunity/web/actions/exec/exec.actions"; 66 } 67 68 73 protected String getDefaultActionName() { 74 return "index"; 75 } 76 77 82 protected String getServletPrefix() { 83 return "exec"; 84 } 85 86 protected void doJob(HttpServletRequest request, HttpServletResponse response) 87 throws ServletException , IOException { 88 if (log.isDebugEnabled()) { 89 log.debug("doJob(HttpServletRequest, HttpServletResponse) - start"); 90 } 91 92 String execAction = getActionName(request); 93 if (execAction == null || execAction.length() == 0) { 94 response.sendError(HttpServletResponse.SC_NOT_FOUND, "No action-instance specified!"); 95 96 if (log.isDebugEnabled()) { 97 log.debug("doJob(HttpServletRequest, HttpServletResponse) - end"); 98 } 99 return; 100 } 101 102 AbstractAction action = null; 103 String result; 104 105 String actionClass = actionProperties.getProperty(execAction); 106 if (actionClass == null) { 107 BlogunityException ex = new BlogunityException(I18NStatusFactory.create( 109 I18N.ERRORS.ACTION_NOT_FOUND, actionClass)); 110 throw new ServletException (ex); 111 } 112 113 try { 114 action = (AbstractAction) Class.forName(actionClass).newInstance(); 116 executeAction(action, request, response); 117 118 } catch (BlogunityException e) { 119 throw new ServletException (e); 120 } catch (Exception e) { 121 BlogunityException ex = new BlogunityException(I18NStatusFactory.create( 123 I18N.ERRORS.ACTION_INITIALIZATION_FAILED, e)); 124 throw new ServletException (ex); 125 } 126 127 128 if (log.isDebugEnabled()) { 129 log.debug("doJob(HttpServletRequest, HttpServletResponse) - end"); 130 } 131 } 132 } | Popular Tags |