KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > web > actions > user > UserprofileAction


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

25
26 package com.j2biz.blogunity.web.actions.user;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import com.j2biz.blogunity.dao.UserDAO;
36 import com.j2biz.blogunity.exception.BlogunityException;
37 import com.j2biz.blogunity.i18n.I18N;
38 import com.j2biz.blogunity.i18n.I18NStatusFactory;
39 import com.j2biz.blogunity.pojo.User;
40 import com.j2biz.blogunity.web.ActionResultFactory;
41 import com.j2biz.blogunity.web.IActionResult;
42 import com.j2biz.blogunity.web.actions.AbstractAction;
43
44 public class UserprofileAction extends AbstractAction {
45     /**
46      * Logger for this class
47      */

48     private static final Log log = LogFactory.getLog(UserprofileAction.class);
49
50     private static final IActionResult USER_PROFILE_FORWARD = ActionResultFactory
51             .buildForward("/jsp/profile.jsp");
52
53     private Long JavaDoc id;
54
55     private String JavaDoc nickname;
56
57     public UserprofileAction(String JavaDoc nickname) {
58         this.nickname = nickname;
59     }
60
61     public UserprofileAction(Long JavaDoc id) {
62         this.id = id;
63     }
64
65     /*
66      * (non-Javadoc)
67      *
68      * @see com.j2biz.blogunity.web.actions.AbstractAction#execute(javax.servlet.http.HttpServletRequest,
69      * javax.servlet.http.HttpServletResponse)
70      */

71     public IActionResult execute(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
72             throws BlogunityException {
73         UserDAO userDAO = new UserDAO();
74         User user = getUser(userDAO);
75
76         request.setAttribute("requestedUser", user);
77         request.setAttribute("friendOfList", userDAO.getFriendOfList(user));
78
79         navigationStack.clear();
80         navigationStack.push(ActionResultFactory.buildRedirect(I18N.MESSAGES.NAVI_USERPROFILE,
81                 currentActionPath));
82
83         return USER_PROFILE_FORWARD;
84
85     }
86
87     /**
88      * @return
89      * @throws BlogunityException
90      */

91     private User getUser(UserDAO userDAO) throws BlogunityException {
92         User u = null;
93         if (id != null) {
94             u = userDAO.getUserByID(id);
95         } else if (StringUtils.isNotEmpty(nickname)) {
96             u = userDAO.getUserByName(nickname);
97         }
98
99         if (u != null) return u;
100
101         throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.NOT_FOUND, "User"));
102
103     }
104
105 }
Popular Tags