KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > user > avatar > SaveAvatarAction


1 /*
2  * $$Id: SaveAvatarAction.java,v 1.3 2005/06/07 12:32:32 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 18.08.2004
27  *
28  */

29 package org.jresearch.gossip.actions.user.avatar;
30
31 import java.awt.image.BufferedImage JavaDoc;
32 import java.io.ByteArrayOutputStream JavaDoc;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import javax.servlet.http.HttpSession JavaDoc;
37
38 import org.apache.struts.action.ActionForm;
39 import org.apache.struts.action.ActionForward;
40 import org.apache.struts.action.ActionMapping;
41 import org.jresearch.gossip.IConst;
42 import org.jresearch.gossip.actions.BaseAction;
43 import org.jresearch.gossip.beans.user.User;
44 import org.jresearch.gossip.configuration.Configurator;
45 import org.jresearch.gossip.dao.ForumDAO;
46 import org.jresearch.gossip.exception.JGossipException;
47 import org.jresearch.gossip.exception.SystemException;
48 import org.jresearch.gossip.util.PictureGenerator;
49
50 /**
51  * @author dbelov
52  *
53  */

54 public abstract class SaveAvatarAction extends BaseAction {
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.jresearch.gossip.actions.BaseAction#process(org.apache.struts.action.ActionMapping,
60      * org.apache.struts.action.ActionForm,
61      * javax.servlet.http.HttpServletRequest,
62      * javax.servlet.http.HttpServletResponse)
63      */

64     protected ActionForward process(ActionMapping mapping, ActionForm form,
65             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
66             throws JGossipException {
67         if (!Configurator.getInstance().getBoolean(IConst.CONFIG.ENABLE_AVATAR)) {
68             return (mapping.findForward(IConst.TOKEN.DENIED));
69         }
70
71         HttpSession JavaDoc session = request.getSession();
72         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
73         ForumDAO dao = ForumDAO.getInstance();
74         try {
75             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
76             BufferedImage JavaDoc image = getImage(form);
77             if (image == null) {
78                 throw new SystemException("Unable to parse image");
79             }
80             PictureGenerator.getInstance().prepareImage(image, buffer);
81             byte[] data = buffer.toByteArray();
82             dao.saveAvatar(user, data);
83         } catch (Exception JavaDoc e) {
84             super.setStatusMessage(request, "errors.general", "<br>"
85                     + e.getMessage());
86             return mapping.getInputForward();
87         }
88         return (mapping.findForward(IConst.TOKEN.PAGE));
89     }
90
91     protected abstract BufferedImage JavaDoc getImage(ActionForm form)
92             throws SystemException;
93
94 }
Popular Tags