01: /*
02: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19:
20: package com.nabhinc.portlet.useradmin;
21:
22: import java.io.IOException;
23: import java.rmi.RemoteException;
24: import java.sql.Timestamp;
25: import java.util.Date;
26: import java.util.Iterator;
27: import java.util.Map;
28:
29: import javax.portlet.PortletException;
30: import javax.portlet.RenderRequest;
31: import javax.portlet.RenderResponse;
32:
33: import com.nabhinc.portal.spi.UserAdminServiceLocator;
34: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
35: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
36: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
37: import com.nabhinc.spi.NoSuchEntityException;
38: import com.nabhinc.spi.User;
39: import com.nabhinc.util.i18n.DateTimeFormatUtil;
40:
41: /**
42: *
43: *
44: * @author Padmanabh Dabke
45: * (c) 2007 Nabh Information Systems, Inc. All Rights Reserved.
46: */
47: public class UserProfileManager extends BaseRequestProcessor implements
48: RenderProcessor {
49:
50: public String process(RenderRequest request,
51: RenderResponse response, RenderConfig renderConfig)
52: throws PortletException, IOException {
53:
54: String username = request.getRemoteUser();
55: if (username == null)
56: return "unlogged-user";
57:
58: try {
59: User user = UserAdminServiceLocator.getUserAdminService()
60: .getUser(username);
61:
62: request.setAttribute("username", user.getUserName());
63: request.setAttribute("fname", user.getFirstName());
64: request.setAttribute("lname", user.getLastName());
65: request.setAttribute("oemail", user.getPrimaryEmail());
66:
67: Iterator iter = user.getProfile().entrySet().iterator();
68: while (iter.hasNext()) {
69: Map.Entry entry = (Map.Entry) iter.next();
70: String paramName = (String) entry.getKey();
71: Object paramValueObj = entry.getValue();
72: String paramValue = null;
73: if (paramValueObj instanceof Timestamp) {
74: paramValue = DateTimeFormatUtil.getDateTimeFormat(
75: request.getLocale()).format(
76: new java.util.Date(
77: ((Timestamp) paramValueObj)
78: .getTime()));
79: } else if (paramValueObj instanceof Date) {
80: paramValue = DateTimeFormatUtil.getDateFormat(
81: request.getLocale()).format(
82: (Date) paramValueObj);
83: } else {
84: paramValue = paramValueObj.toString();
85: }
86: request.setAttribute(paramName, paramValue);
87: }
88:
89: return "success";
90: } catch (NoSuchEntityException ex) {
91: return "no-such-entity";
92: } catch (RemoteException ex) {
93: throw new PortletException(
94: "Failed to retrieve user information.", ex);
95: }
96: }
97: }
|