KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: MyServlet.java,v 1.7 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 import javax.servlet.http.HttpSession JavaDoc;
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 /**
46  * @author michelson
47  * @version $$
48  * @since 0.1
49  *
50  *
51  */

52 public class MyServlet extends ActionServlet {
53     /**
54      * Comment for <code>serialVersionUID</code>
55      */

56     private static final long serialVersionUID = 3256726190864480567L;
57     /**
58      * Logger for this class
59      */

60     private static final Log log = LogFactory.getLog(MyServlet.class);
61
62     protected void doJob(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
63             throws ServletException JavaDoc, IOException JavaDoc {
64
65         if (log.isDebugEnabled()) {
66             log.debug("doJob(HttpServletRequest, HttpServletResponse) - start");
67         }
68
69         //>> PATCH for JETTY-Server
70
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 JavaDoc 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 JavaDoc(ex);
86         }
87
88         // try {
89
// UserDAO.attachToSession(user);
90
// } catch (BlogException e1) {
91
// throw new ServletException(
92
// "Unable to attach user to hibernate session!", e1);
93
// }
94

95         String JavaDoc requestAction = getActionName(request);
96
97         AbstractAction action = null;
98         String JavaDoc result;
99
100         String JavaDoc actionClass = actionProperties.getProperty(requestAction);
101         if (actionClass == null) {
102             // re-pack exception into user-friendly one
103
BlogunityException ex = new BlogunityException(I18NStatusFactory.create(
104                     I18N.ERRORS.ACTION_NOT_FOUND, requestAction));
105             throw new ServletException JavaDoc(ex);
106         }
107
108         try {
109             // try to create action instance
110
action = (AbstractAction) Class.forName(actionClass).newInstance();
111             executeAction(action, request, response);
112
113         } catch (BlogunityException e) {
114             throw new ServletException JavaDoc(e);
115         } catch (Exception JavaDoc e) {
116             // re-pack exception into user-friendly one
117
BlogunityException ex = new BlogunityException(I18NStatusFactory.create(
118                     I18N.ERRORS.ACTION_INITIALIZATION_FAILED, e));
119             throw new ServletException JavaDoc(ex);
120         }
121
122         if (log.isDebugEnabled()) {
123             log.debug("doJob(HttpServletRequest, HttpServletResponse) -end");
124         }
125
126     }
127
128     /*
129      * (non-Javadoc)
130      *
131      * @see com.j2biz.blogunity.web.servlet.ActionServlet#getDefaultActionName()
132      */

133     protected String JavaDoc getDefaultActionName() {
134         return "index";
135     }
136
137     /*
138      * (non-Javadoc)
139      *
140      * @see com.j2biz.blogunity.web.servlet.ActionServlet#getServletPrefix()
141      */

142     protected String JavaDoc getServletPrefix() {
143         return "my";
144     }
145
146     /*
147      * (non-Javadoc)
148      *
149      * @see com.j2biz.blogunity.web.servlet.ActionServlet#getActionPropertiesPath()
150      */

151     protected String JavaDoc getActionPropertiesPath() {
152         return "/com/j2biz/blogunity/web/actions/my/my.actions";
153     }
154
155 }
Popular Tags