📄 profilemanagerportlet.java
字号:
/* * @author <a href="mailto:michael.russell@aei.mpg.de">Michael Russell</a> * @version $Id: ProfileManagerPortlet.java 5062 2006-08-17 21:31:25Z novotny $ */package org.gridsphere.portlets.core.user;import org.gridsphere.portlet.impl.SportletProperties;import org.gridsphere.provider.event.jsr.ActionFormEvent;import org.gridsphere.provider.event.jsr.FormEvent;import org.gridsphere.provider.event.jsr.RenderFormEvent;import org.gridsphere.provider.portlet.jsr.ActionPortlet;import org.gridsphere.provider.portletui.beans.*;import org.gridsphere.services.core.locale.LocaleService;import org.gridsphere.services.core.portal.PortalConfigService;import org.gridsphere.services.core.security.password.InvalidPasswordException;import org.gridsphere.services.core.security.password.PasswordEditor;import org.gridsphere.services.core.security.password.PasswordManagerService;import org.gridsphere.services.core.security.role.PortletRole;import org.gridsphere.services.core.security.role.RoleManagerService;import org.gridsphere.services.core.user.User;import org.gridsphere.services.core.user.UserManagerService;import org.gridsphere.services.core.utils.DateUtil;import javax.portlet.*;import java.io.File;import java.text.DateFormat;import java.util.*;public class ProfileManagerPortlet extends ActionPortlet { public static String USER_PROFILE_PUBLIC = "user.publicprofile"; // JSP pages used by this portlet public static final String VIEW_USER_JSP = "profile/viewuser.jsp"; public static final String CONFIGURE_JSP = "profile/configure.jsp"; public static final String HELP_JSP = "profile/help.jsp"; public static final String EDIT_PASSWD_JSP = "profile/editpassword.jsp"; // Portlet services private UserManagerService userManagerService = null; private PasswordManagerService passwordManagerService = null; private RoleManagerService roleManagerService = null; private LocaleService localeService = null; private PortalConfigService portalConfigService = null; public void init(PortletConfig config) throws PortletException { super.init(config); this.userManagerService = (UserManagerService) createPortletService(UserManagerService.class); this.roleManagerService = (RoleManagerService) createPortletService(RoleManagerService.class); this.passwordManagerService = (PasswordManagerService) createPortletService(PasswordManagerService.class); this.localeService = (LocaleService) createPortletService(LocaleService.class); this.portalConfigService = (PortalConfigService) createPortletService(PortalConfigService.class); DEFAULT_VIEW_PAGE = "doViewUser"; DEFAULT_HELP_PAGE = HELP_JSP; DEFAULT_CONFIGURE_PAGE = "doConfigureSettings"; } public void doViewUser(RenderFormEvent event) { PortletRequest req = event.getRenderRequest(); setUserTable(event, req); if (portalConfigService.getProperty(PortalConfigService.SAVE_PASSWORDS).equals(Boolean.TRUE.toString())) { req.setAttribute("savePass", "true"); } User user = (User) req.getAttribute(SportletProperties.PORTLET_USER); String email = user.getEmailAddress(); TextFieldBean emailTF = event.getTextFieldBean("emailTF"); emailTF.setValue(email); CheckBoxBean privacyCB = event.getCheckBoxBean("privacyCB"); if ((user.getAttribute(USER_PROFILE_PUBLIC) != null) && (user.getAttribute(USER_PROFILE_PUBLIC).equals("true"))) { privacyCB.setSelected(true); } else { privacyCB.setSelected(false); } ListBoxBean themeLB = event.getListBoxBean("themeLB"); String[] themes = new String[]{}; String theme = (String) user.getAttribute(User.THEME); String renderkit = (String) req.getPortletSession().getAttribute(SportletProperties.LAYOUT_RENDERKIT, PortletSession.APPLICATION_SCOPE); themeLB.clear(); String themesPath = getPortletContext().getRealPath("themes"); /// retrieve the current renderkit themesPath += File.separator + renderkit; File f = new File(themesPath); if (f.isDirectory()) { themes = f.list(); } for (int i = 0; i < themes.length; i++) { ListBoxItemBean lb = new ListBoxItemBean(); lb.setValue(themes[i].trim()); if (themes[i].trim().equalsIgnoreCase(theme)) lb.setSelected(true); themeLB.addBean(lb); } setNextState(req, VIEW_USER_JSP); } public void doEditPassword(ActionFormEvent event) { ActionRequest req = event.getActionRequest(); setNextState(req, EDIT_PASSWD_JSP); } public void saveTheme(ActionFormEvent event) { PortletRequest req = event.getActionRequest(); ListBoxBean themeLB = event.getListBoxBean("themeLB"); String theme = themeLB.getSelectedValue(); String loginName = req.getRemoteUser(); User user = userManagerService.getUserByUserName(loginName); if (user != null) { user.setAttribute(User.THEME, theme); userManagerService.saveUser(user); req.getPortletSession().setAttribute(SportletProperties.LAYOUT_THEME, theme, PortletSession.APPLICATION_SCOPE); } } public void setUserTable(FormEvent event, PortletRequest req) { User user = (User) req.getAttribute(SportletProperties.PORTLET_USER); //String uid = (String) req.getPortletSession().getAttribute(SportletProperties.PORTLET_USER, PortletSession.APPLICATION_SCOPE); //User user = userManagerService.getUser(uid); //String logintime = DateFormat.getDateTimeInstance().format(new Date(user.getLastLoginTime())); req.setAttribute("logintime", DateUtil.getLocalizedDate(user, req.getLocale(), user.getLastLoginTime(), DateFormat.FULL, DateFormat.FULL)); req.setAttribute("username", user.getUserName()); if (req.isUserInRole(PortletRole.ADMIN.getName())) { TextFieldBean userName = event.getTextFieldBean("userNameTF"); userName.setValue(user.getUserName()); } else { TextBean userName = event.getTextBean("userName"); userName.setValue(user.getUserName()); } //userName.setDisabled(disable); TextFieldBean firstName = event.getTextFieldBean("firstName"); firstName.setValue(user.getFirstName()); TextFieldBean lastName = event.getTextFieldBean("lastName"); lastName.setValue(user.getLastName()); TextFieldBean organization = event.getTextFieldBean("organization"); organization.setValue(user.getOrganization()); TextBean userRolesTB = event.getTextBean("userRoles"); List userRoles = roleManagerService.getRolesForUser(user); Iterator it = userRoles.iterator(); String userRole = ""; while (it.hasNext()) { userRole += ((PortletRole) it.next()).getName() + ", "; } if (userRole.length() > 2) { userRolesTB.setValue(userRole.substring(0, userRole.length() - 2)); } else { userRolesTB.setValue(this.getLocalizedText(req, "ROLES_HASNOROLES")); } Locale locale = req.getLocale(); req.setAttribute("locale", locale); ListBoxBean localeSelector = event.getListBoxBean("userlocale"); localeSelector.clear(); localeSelector.setSize(1); Locale[] locales = localeService.getSupportedLocales(); for (int i = 0; i < locales.length; i++) { Locale displayLocale = locales[i]; ListBoxItemBean localeBean = makeLocaleBean(displayLocale.getDisplayLanguage(displayLocale), displayLocale.getLanguage(), locale); localeSelector.addBean(localeBean); } ListBoxBean timezoneList = event.getListBoxBean("timezones"); Map zones = DateUtil.getLocalizedTimeZoneNames(); Set keys = zones.keySet(); Iterator it2 = keys.iterator(); String userTimeZone = (String) user.getAttribute(User.TIMEZONE); if (userTimeZone == null) { userTimeZone = TimeZone.getDefault().getID(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -