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.util.Locale;
24:
25: import javax.portlet.ActionRequest;
26: import javax.portlet.ActionResponse;
27: import javax.portlet.PortletException;
28:
29: import com.nabhinc.portal.api.PortalInformationStore;
30: import com.nabhinc.portal.api.PortalInformationStoreLocator;
31: import com.nabhinc.portal.model.UserPreferences;
32: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
33: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
34: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
35: import com.nabhinc.util.StringUtil;
36:
37: /**
38: *
39: *
40: * @author Padmanabh Dabke
41: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
42: */
43: public class UserPreferenceUpdater extends BaseRequestProcessor
44: implements ActionProcessor {
45:
46: public String process(ActionRequest request,
47: ActionResponse response, ActionConfig actionConfig)
48: throws PortletException, IOException {
49:
50: String userName = request.getRemoteUser();
51: if (userName == null)
52: return "unlogged-user";
53: String loc = request.getParameter("user_locale");
54: String tz = request.getParameter("user_timezone");
55: boolean showEmail = request.getParameter("showemail") != null;
56: boolean showName = request.getParameter("showname") != null;
57:
58: PortalInformationStore storeInfo = PortalInformationStoreLocator
59: .getPortalInformationStore();
60: UserPreferences userPrefs = storeInfo
61: .getUserPreferences(userName);
62: if (userPrefs == null)
63: userPrefs = new UserPreferences();
64: userPrefs.setName(userName);
65: userPrefs.setShowEmail(showEmail);
66: userPrefs.setShowName(showName);
67: if (StringUtil.isNullOrEmpty(tz))
68: userPrefs.setTimezone(null);
69: else
70: userPrefs.setTimezone(tz);
71: setUserLocale(loc, userPrefs);
72: storeInfo.saveUserPreferences(userPrefs);
73:
74: return "success";
75: }
76:
77: private void setUserLocale(String loc, UserPreferences userPrefs) {
78: if (StringUtil.isNullOrEmpty(loc))
79: userPrefs.setPreferredLocale(null);
80: else {
81: String[] theLoc = StringUtil.split(loc, "_");
82: if (theLoc.length == 2) {
83: userPrefs.setPreferredLocale(new Locale(theLoc[0],
84: theLoc[1]));
85: } else {
86: userPrefs.setPreferredLocale(new Locale(theLoc[0]));
87: }
88: }
89: }
90:
91: }
|