001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portlet.useradmin;
021:
022: import java.io.IOException;
023: import java.rmi.RemoteException;
024: import java.sql.Timestamp;
025: import java.util.Date;
026: import java.util.Iterator;
027: import java.util.Map;
028:
029: import javax.portlet.PortletException;
030: import javax.portlet.RenderRequest;
031: import javax.portlet.RenderResponse;
032:
033: import com.nabhinc.portal.api.PortalInformationStore;
034: import com.nabhinc.portal.api.PortalInformationStoreLocator;
035: import com.nabhinc.portal.model.UserPreferences;
036: import com.nabhinc.portal.spi.UserAdminServiceLocator;
037: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
038: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
039: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
040: import com.nabhinc.spi.NoSuchEntityException;
041: import com.nabhinc.spi.User;
042: import com.nabhinc.util.i18n.DateTimeFormatUtil;
043:
044: /**
045: *
046: *
047: * @author Padmanabh Dabke
048: * (c) 2007 Nabh Information Systems, Inc. All Rights Reserved.
049: */
050: public class ViewUserProfile extends BaseRequestProcessor implements
051: RenderProcessor {
052:
053: public String process(RenderRequest request,
054: RenderResponse response, RenderConfig renderConfig)
055: throws PortletException, IOException {
056:
057: String appPath = request.getParameter("app_path");
058: if (appPath == null)
059: return "unknown-site";
060:
061: try {
062: PortalInformationStore store = PortalInformationStoreLocator
063: .getPortalInformationStore();
064: String username = store.getPortalApplicationOwner(appPath);
065: if (username == null)
066: return "unknown-user";
067:
068: User user = UserAdminServiceLocator.getUserAdminService()
069: .getUser(username);
070: // if (user == null) return "unknown-user";
071: UserPreferences userPref = store
072: .getUserPreferences(username);
073:
074: if (userPref == null)
075: userPref = new UserPreferences();
076: request.setAttribute("user_profile.user", user);
077: request.setAttribute("user_profile.user_preferences",
078: userPref);
079:
080: if (userPref.isShowName()) {
081: request.setAttribute("showname", "true");
082: }
083:
084: if (userPref.isShowEmail()) {
085: request.setAttribute("oemail", user.getPrimaryEmail());
086: }
087:
088: request.setAttribute("username", user.getUserName());
089: request.setAttribute("fname", user.getFirstName());
090: request.setAttribute("lname", user.getLastName());
091: request.setAttribute("lastlogin", user.getLastLogin());
092: request.setAttribute("joined", user.getUserSince());
093:
094: Iterator iter = user.getProfile().entrySet().iterator();
095: while (iter.hasNext()) {
096: Map.Entry entry = (Map.Entry) iter.next();
097: String paramName = (String) entry.getKey();
098: Object paramValueObj = entry.getValue();
099: String paramValue = null;
100: if (paramValueObj instanceof Timestamp) {
101: paramValue = DateTimeFormatUtil.getDateTimeFormat(
102: request.getLocale()).format(
103: new java.util.Date(
104: ((Timestamp) paramValueObj)
105: .getTime()));
106: } else if (paramValueObj instanceof Date) {
107: paramValue = DateTimeFormatUtil.getDateFormat(
108: request.getLocale()).format(
109: (Date) paramValueObj);
110: } else {
111: paramValue = paramValueObj.toString();
112: }
113: request.setAttribute(paramName, paramValue);
114: }
115:
116: return "success";
117: } catch (NoSuchEntityException ex) {
118: return "no-such-entity";
119: } catch (RemoteException ex) {
120: throw new PortletException(
121: "Failed to retrieve user information.", ex);
122: }
123: }
124: }
|