KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > web > servlet > ExecServlet


1 /*
2  * $Id: ExecServlet.java,v 1.3 2005/01/17 11:21:21 keyboardsamurai Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.web.servlet;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.servlet.ServletException JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
43  * @author michelson
44  * @version $$
45  * @since 0.1
46  *
47  *
48  */

49 public class ExecServlet extends ActionServlet {
50     /**
51      * Comment for <code>serialVersionUID</code>
52      */

53     private static final long serialVersionUID = 3257847684017961013L;
54     /**
55      * Logger for this class
56      */

57     private static final Log log = LogFactory.getLog(ExecServlet.class);
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see com.j2biz.blogunity.web.servlet.ActionServlet#getActionPropertiesPath()
63      */

64     protected String JavaDoc getActionPropertiesPath() {
65         return "/com/j2biz/blogunity/web/actions/exec/exec.actions";
66     }
67
68     /*
69      * (non-Javadoc)
70      *
71      * @see com.j2biz.blogunity.web.servlet.ActionServlet#getDefaultActionName()
72      */

73     protected String JavaDoc getDefaultActionName() {
74         return "index";
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see com.j2biz.blogunity.web.servlet.ActionServlet#getServletPrefix()
81      */

82     protected String JavaDoc getServletPrefix() {
83         return "exec";
84     }
85
86     protected void doJob(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
87             throws ServletException JavaDoc, IOException JavaDoc {
88         if (log.isDebugEnabled()) {
89             log.debug("doJob(HttpServletRequest, HttpServletResponse) - start");
90         }
91
92         String JavaDoc 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 JavaDoc result;
104
105         String JavaDoc actionClass = actionProperties.getProperty(execAction);
106         if (actionClass == null) {
107             // re-pack exception into user-friendly one
108
BlogunityException ex = new BlogunityException(I18NStatusFactory.create(
109                     I18N.ERRORS.ACTION_NOT_FOUND, actionClass));
110             throw new ServletException JavaDoc(ex);
111         }
112
113         try {
114             // try to create action instance
115
action = (AbstractAction) Class.forName(actionClass).newInstance();
116             executeAction(action, request, response);
117
118         } catch (BlogunityException e) {
119             throw new ServletException JavaDoc(e);
120         } catch (Exception JavaDoc e) {
121             // re-pack exception into user-friendly one
122
BlogunityException ex = new BlogunityException(I18NStatusFactory.create(
123                     I18N.ERRORS.ACTION_INITIALIZATION_FAILED, e));
124             throw new ServletException JavaDoc(ex);
125         }
126         
127         
128         if (log.isDebugEnabled()) {
129             log.debug("doJob(HttpServletRequest, HttpServletResponse) - end");
130         }
131     }
132 }
Popular Tags