You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2005/11/25 03:25:20 UTC
svn commit: r348854 [9/16] - in
/portals/jetspeed-2/trunk/applications/j2-admin: ./
src/java/org/apache/jetspeed/portlets/entityeditor/
src/java/org/apache/jetspeed/portlets/localeselector/
src/java/org/apache/jetspeed/portlets/localeselector/resources...
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,1098 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.security.users;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.prefs.Preferences;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.container.JetspeedPortletContext;
+import org.apache.jetspeed.om.common.SecurityConstraints;
+import org.apache.jetspeed.om.common.UserAttribute;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.portlets.security.SecurityResources;
+import org.apache.jetspeed.portlets.security.SecurityUtil;
+import org.apache.jetspeed.portlets.security.users.JetspeedUserBean;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.PrincipalRule;
+import org.apache.jetspeed.security.Group;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.jetspeed.security.InvalidNewPasswordException;
+import org.apache.jetspeed.security.InvalidPasswordException;
+import org.apache.jetspeed.security.PasswordAlreadyUsedException;
+import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.security.om.InternalCredential;
+import org.apache.portals.bridges.beans.TabBean;
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.portals.bridges.util.PreferencesHelper;
+import org.apache.portals.messaging.PortletMessaging;
+
+/**
+ * This portlet is a tabbed editor user interface for editing user attributes
+ * and security definitions.
+ *
+ * @author <a href="mailto:jford@apache.com">Jeremy Ford</a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: UserDetailsPortlet.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class UserDetailsPortlet extends GenericServletPortlet
+{
+ private final String VIEW_USER = "user";
+ private final String VIEW_ROLES = "roles";
+ private final String VIEW_GROUPS = "groups";
+ private final String VIEW_RULES = "rules";
+ private final String VIEW_CREDENTIAL = "credential";
+ private final String VIEW_ALL_RULES = "prules";
+ private final String VIEW_PA_USER_ATTRIBUTES = "paUserAttributes";
+
+ private final String USER_ACTION_PREFIX = "security_user.";
+ private final String ACTION_EDIT_USER = "edit_user";
+ private final String ACTION_UPDATE_ATTRIBUTE = "update_user_attribute";
+ private final String ACTION_REMOVE_ATTRIBUTE = "remove_user_attribute";
+ private final String ACTION_ADD_ATTRIBUTE = "add_user_attribute";
+ private final String ACTION_REMOVE_ROLE = "remove_user_role";
+ private final String ACTION_ADD_ROLE = "add_user_role";
+ private final String ACTION_REMOVE_GROUP = "remove_user_group";
+ private final String ACTION_ADD_GROUP = "add_user_group";
+ private final String ACTION_REMOVE_RULE = "remove_user_rule";
+ private final String ACTION_ADD_RULE = "add_rule";
+ private final String ACTION_UPDATE_CREDENTIAL = "update_user_credential";
+
+ private final String TAB_USER = "user";
+ private final String TAB_ATTRIBUTES = "user_attributes";
+ private final String TAB_ROLE = "user_role";
+ private final String TAB_GROUP = "user_group";
+ private final String TAB_PROFILE = "user_profile";
+ private final String TAB_CREDENTIAL = "user_credential";
+
+ /** the id of the roles control */
+ private static final String ROLES_CONTROL = "jetspeedRoles";
+
+ /** the id of the rules control */
+ private static final String RULES_CONTROL = "jetspeedRules";
+
+
+ /** the id of the groups control */
+ private static final String GROUPS_CONTROL = "jetspeedGroups";
+
+ private PageManager pageManager;
+ private UserManager userManager;
+ private RoleManager roleManager;
+ private GroupManager groupManager;
+ private Profiler profiler;
+ private PortletRegistry registry;
+ private String paIdentifier;
+ private Collection paUserAttributes;
+ private boolean initPrefsAndAttr;
+
+ private LinkedHashMap userTabMap;
+ private LinkedHashMap anonymousUserTabMap;
+
+ public void init(PortletConfig config)
+ throws PortletException
+ {
+ super.init(config);
+ userManager = (UserManager)getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+ if (null == userManager)
+ {
+ throw new PortletException("Failed to find the User Manager on portlet initialization");
+ }
+ roleManager = (RoleManager)getPortletContext().getAttribute(CommonPortletServices.CPS_ROLE_MANAGER_COMPONENT);
+ if (null == roleManager)
+ {
+ throw new PortletException("Failed to find the Role Manager on portlet initialization");
+ }
+ groupManager = (GroupManager)getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT);
+ if (null == groupManager)
+ {
+ throw new PortletException("Failed to find the Group Manager on portlet initialization");
+ }
+ profiler = (Profiler)getPortletContext().getAttribute(CommonPortletServices.CPS_PROFILER_COMPONENT);
+ if (null == profiler)
+ {
+ throw new PortletException("Failed to find the Profiler on portlet initialization");
+ }
+ registry = (PortletRegistry)getPortletContext().getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT);
+ if (null == registry)
+ {
+ throw new PortletException("Failed to find the Portlet Registry on portlet initialization");
+ }
+
+ pageManager = (PageManager)getPortletContext().getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT);
+ if (null == pageManager)
+ {
+ throw new PortletException("Failed to find the Page Manager on portlet initialization");
+ }
+
+ paIdentifier = ((MutablePortletApplication)((JetspeedPortletContext)config.getPortletContext())
+ .getApplication()).getApplicationIdentifier();
+ }
+
+ public void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
+ {
+ response.setContentType("text/html");
+
+ if ( !initPrefsAndAttr )
+ {
+ initPrefsAndAttr(request);
+ }
+
+ String userName = (String)PortletMessaging.receive(request,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+
+ User user = null;
+ if (userName != null)
+ {
+ user = lookupUser(userName);
+ }
+
+ if (user != null)
+ {
+ LinkedHashMap tabMap = null;
+ if ( userManager.getAnonymousUser().equals(userName) )
+ {
+ tabMap = anonymousUserTabMap;
+ }
+ else
+ {
+ tabMap = userTabMap;
+ }
+
+ // Tabs
+ request.setAttribute("tabs", tabMap.values());
+ TabBean selectedTab =
+ (TabBean) request.getPortletSession().getAttribute(SecurityResources.REQUEST_SELECT_TAB);
+
+ if(selectedTab != null && !tabMap.containsKey(selectedTab.getId()))
+ {
+ selectedTab = null;
+ }
+
+ if(selectedTab == null)
+ {
+ selectedTab = (TabBean) tabMap.values().iterator().next();
+ }
+ JetspeedUserBean bean = new JetspeedUserBean(user);
+ request.setAttribute(VIEW_USER, bean);
+
+ if (selectedTab.getId().equals(TAB_USER))
+ {
+ request.setAttribute(VIEW_PA_USER_ATTRIBUTES, paUserAttributes);
+ if ( "true".equals(request.getPreferences().getValue("showPasswordOnUserTab", "false")))
+ {
+ request.setAttribute(VIEW_CREDENTIAL, getCredential(userName));
+ }
+ }
+ else if (selectedTab.getId().equals(TAB_ROLE))
+ {
+ Collection userRoles = getRoles(userName);
+ request.setAttribute(VIEW_ROLES, userRoles );
+
+ // check for refresh on roles list
+ String refreshRoles = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_USERS, "roles");
+ List roles = null;
+ if (refreshRoles == null)
+ {
+ roles = (List) request.getPortletSession().getAttribute(ROLES_CONTROL);
+ }
+
+ // build the roles control and provide it to the view
+ try
+ {
+ if (roles == null)
+ {
+ roles = new LinkedList();
+ Iterator fullRoles = roleManager.getRoles("");
+ while (fullRoles.hasNext())
+ {
+ Role role = (Role)fullRoles.next();
+ roles.add(role.getPrincipal().getName());
+ }
+ request.getPortletSession().setAttribute(ROLES_CONTROL, roles);
+ }
+ }
+ catch (SecurityException se)
+ {
+ throw new PortletException(se);
+ }
+ ArrayList selectableRoles = new ArrayList(roles);
+ Iterator rolesIter = userRoles.iterator();
+ while ( rolesIter.hasNext() )
+ {
+ Role role = (Role)rolesIter.next();
+ int index = selectableRoles.indexOf(role.getPrincipal().getName());
+ if (index != -1)
+ {
+ selectableRoles.remove(index);
+ }
+ }
+ request.setAttribute(ROLES_CONTROL, selectableRoles);
+
+ }
+ else if (selectedTab.getId().equals(TAB_GROUP))
+ {
+ Collection userGroups = getGroups(userName);
+ request.setAttribute(VIEW_GROUPS, userGroups);
+
+ // check for refresh on groups list
+ String refreshGroups = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_USERS, "groups");
+ List groups = null;
+ if (refreshGroups == null)
+ {
+ groups = (List) request.getPortletSession().getAttribute(GROUPS_CONTROL);
+ }
+
+ // build the groups control and provide it to the view
+ try
+ {
+ if (groups == null)
+ {
+ groups = new LinkedList();
+ Iterator fullGroups = groupManager.getGroups("");
+ while (fullGroups.hasNext())
+ {
+ Group group = (Group)fullGroups.next();
+ groups.add(group.getPrincipal().getName());
+ }
+ request.getPortletSession().setAttribute(GROUPS_CONTROL, groups);
+ }
+ }
+ catch (SecurityException se)
+ {
+ throw new PortletException(se);
+ }
+ ArrayList selectableGroups = new ArrayList(groups);
+ Iterator groupsIter = userGroups.iterator();
+ while ( groupsIter.hasNext() )
+ {
+ Group group = (Group)groupsIter.next();
+ int index = selectableGroups.indexOf(group.getPrincipal().getName());
+ if (index != -1)
+ {
+ selectableGroups.remove(index);
+ }
+ }
+ request.setAttribute(GROUPS_CONTROL, selectableGroups);
+
+ }
+ else if (selectedTab.getId().equals(TAB_PROFILE))
+ {
+ request.setAttribute(VIEW_RULES, getRules(user));
+ request.setAttribute(VIEW_ALL_RULES, getProfilerRules());
+ }
+ else if (selectedTab.getId().equals(TAB_CREDENTIAL))
+ {
+ request.setAttribute(VIEW_CREDENTIAL, getCredential(userName));
+ }
+
+ request.setAttribute(SecurityResources.REQUEST_SELECT_TAB, selectedTab);
+ }
+ else
+ {
+ renderRoleInformation(request);
+ renderProfileInformation(request);
+ }
+ // check for ErrorMessages
+ ArrayList errorMessages = (ArrayList)PortletMessaging.consume(request, SecurityResources.ERROR_MESSAGES);
+ if (errorMessages != null )
+ {
+ request.setAttribute(SecurityResources.ERROR_MESSAGES, errorMessages);
+ }
+
+ super.doView(request, response);
+ }
+
+ protected void initPrefsAndAttr(PortletRequest request)
+ {
+ initPrefsAndAttr = true;
+ if ( userTabMap == null )
+ {
+ userTabMap = new LinkedHashMap();
+ anonymousUserTabMap = new LinkedHashMap();
+ }
+ else
+ {
+ userTabMap.clear();
+ anonymousUserTabMap.clear();
+ }
+
+ TabBean tb;
+ PortletPreferences prefs = request.getPreferences();
+
+ if ( "true".equals(prefs.getValue("showUserTab", "true")) )
+ {
+ tb = new TabBean(TAB_USER);
+ userTabMap.put(tb.getId(), tb);
+ }
+ if ( "true".equals(prefs.getValue("showAttributesTab", "true")) )
+ {
+ tb = new TabBean(TAB_ATTRIBUTES);
+ userTabMap.put(tb.getId(), tb);
+ }
+ if ( "true".equals(prefs.getValue("showPasswordTab", "true")) )
+ {
+ tb = new TabBean(TAB_CREDENTIAL);
+ userTabMap.put(tb.getId(), tb);
+ }
+ if ( "true".equals(prefs.getValue("showRoleTab", "true")) )
+ {
+ tb = new TabBean(TAB_ROLE);
+ userTabMap.put(tb.getId(), tb);
+ anonymousUserTabMap.put(tb.getId(), tb);
+ }
+ if ( "true".equals(prefs.getValue("showGroupTab", "true")) )
+ {
+ tb = new TabBean(TAB_GROUP);
+ userTabMap.put(tb.getId(), tb);
+ anonymousUserTabMap.put(tb.getId(), tb);
+ }
+ if ( "true".equals(prefs.getValue("showProfileTab", "true")) )
+ {
+ tb = new TabBean(TAB_PROFILE);
+ userTabMap.put(tb.getId(), tb);
+ anonymousUserTabMap.put(tb.getId(), tb);
+ }
+ // refresh PA UserAttributes (kinda hack but can't communicate between PAM and Security PA yet to signal a refresh is needed)
+ paUserAttributes = registry.getPortletApplicationByIdentifier(paIdentifier).getUserAttributes();
+ }
+
+ protected void renderRoleInformation(RenderRequest request)
+ throws PortletException
+ {
+ // check for refresh on roles list
+ String refreshRoles = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_REFRESH_ROLES);
+ List roles = null;
+ if (refreshRoles == null)
+ {
+ roles = (List) request.getPortletSession().getAttribute(ROLES_CONTROL);
+ }
+
+ // build the roles control and provide it to the view
+ try
+ {
+ if (roles == null)
+ {
+ roles = new LinkedList();
+ Iterator fullRoles = roleManager.getRoles("");
+ while (fullRoles.hasNext())
+ {
+ Role role = (Role)fullRoles.next();
+ roles.add(role.getPrincipal().getName());
+ }
+ request.getPortletSession().setAttribute(ROLES_CONTROL, roles);
+ }
+ }
+ catch (SecurityException se)
+ {
+ throw new PortletException(se);
+ }
+ request.setAttribute(ROLES_CONTROL, roles);
+ }
+
+ protected void renderProfileInformation(RenderRequest request)
+ {
+ // check for refresh on profiles list
+ String refreshProfiles = (String)PortletMessaging.consume(request,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_REFRESH_PROFILES);
+ Collection rules = null;
+ if (refreshProfiles == null)
+ {
+ rules = (Collection) request.getPortletSession().getAttribute(RULES_CONTROL);
+ }
+
+ // build the profiles control and provide it to the view
+ if (rules == null)
+ {
+ rules = profiler.getRules();
+ request.getPortletSession().setAttribute(RULES_CONTROL, rules);
+ }
+ request.setAttribute(RULES_CONTROL, rules);
+ }
+
+ public void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
+ {
+ response.setContentType("text/html");
+ renderRoleInformation(request);
+ renderProfileInformation(request);
+ super.doEdit(request, response);
+ }
+
+ public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
+ throws PortletException, IOException
+ {
+ if (actionRequest.getPortletMode() == PortletMode.EDIT)
+ {
+ PortletPreferences prefs = actionRequest.getPreferences();
+ PreferencesHelper.requestParamsToPreferences(actionRequest);
+ prefs.store();
+ actionResponse.setPortletMode(PortletMode.VIEW);
+ initPrefsAndAttr(actionRequest);
+ return;
+ }
+
+ String selectedTab = actionRequest.getParameter(SecurityResources.REQUEST_SELECT_TAB);
+ if (selectedTab != null)
+ {
+ TabBean tab = (TabBean) userTabMap.get(selectedTab);
+ if (tab != null)
+ {
+ actionRequest.getPortletSession().setAttribute(
+ SecurityResources.REQUEST_SELECT_TAB, tab);
+ }
+ }
+ String action = actionRequest.getParameter(SecurityResources.PORTLET_ACTION);
+ if (action != null && action.equals("remove.user"))
+ {
+ removeUser(actionRequest, actionResponse);
+ }
+ else if (action != null && action.equals("add.new.user"))
+ {
+ PortletMessaging.cancel(actionRequest, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ }
+ else if (action != null && action.equals("add.user"))
+ {
+ addUser(actionRequest);
+ }
+ else if (action != null && isUserPortletAction(action))
+ {
+ action = getAction(USER_ACTION_PREFIX, action);
+ if (action.endsWith(ACTION_EDIT_USER))
+ {
+ editUser(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_UPDATE_ATTRIBUTE))
+ {
+ updateUserAttribute(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_REMOVE_ATTRIBUTE))
+ {
+ removeUserAttributes(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_ADD_ATTRIBUTE))
+ {
+ addUserAttribute(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_REMOVE_ROLE))
+ {
+ removeUserRoles(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_ADD_ROLE))
+ {
+ addUserRole(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_REMOVE_GROUP))
+ {
+ removeUserGroups(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(ACTION_ADD_GROUP))
+ {
+ addUserGroup(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(this.ACTION_ADD_RULE))
+ {
+ addUserProfile(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(this.ACTION_REMOVE_RULE))
+ {
+ removeUserProfile(actionRequest, actionResponse);
+ }
+ else if (action.endsWith(this.ACTION_UPDATE_CREDENTIAL))
+ {
+ updateUserCredential(actionRequest, actionResponse);
+ }
+ }
+ }
+
+ public void removeUser(ActionRequest actionRequest, ActionResponse actionResponse)
+ throws PortletException
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ try
+ {
+ userManager.removeUser(userName);
+ PortletMessaging.publish(actionRequest, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_REFRESH, "true");
+
+ // TODO: remove ALL user from PSML
+ Page page = pageManager.getPage(Folder.USER_FOLDER + userName + "/default-page.psml");
+ pageManager.removePage(page);
+
+ Folder folder = pageManager.getFolder(Folder.USER_FOLDER + userName);
+ pageManager.removeFolder(folder);
+
+ // remove selected user from USERS_TOPIC
+ PortletMessaging.cancel(actionRequest,SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ // TODO: send message to site manager portlet
+
+ }
+ catch (Exception e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ }
+ }
+ }
+
+ public Principal createPrincipal(Subject subject, Class classe)
+ {
+ Principal principal = null;
+ Iterator principals = subject.getPrincipals().iterator();
+ while (principals.hasNext())
+ {
+ Principal p = (Principal) principals.next();
+ if (classe.isInstance(p))
+ {
+ principal = p;
+ break;
+ }
+ }
+ return principal;
+ }
+
+ private void updateUserCredential(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.UsersResources",actionRequest.getLocale());
+
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ try
+ {
+ String password = actionRequest.getParameter("user_cred_value");
+ boolean passwordSet = false;
+ if ( password != null && password.trim().length() > 0 )
+ {
+ userManager.setPassword(userName, null, password);
+ passwordSet = true;
+ }
+ PasswordCredential credential = getCredential(userName);
+ if ( credential != null )
+ {
+ String updateRequiredStr = actionRequest.getParameter("user_cred_updreq");
+ if (updateRequiredStr != null)
+ {
+ boolean updateRequired = Boolean.valueOf(updateRequiredStr).booleanValue();
+ if (updateRequired != credential.isUpdateRequired())
+ {
+ userManager.setPasswordUpdateRequired(userName,updateRequired);
+ }
+ }
+ String enabledStr = actionRequest.getParameter("user_cred_enabled");
+ if (enabledStr != null)
+ {
+ boolean enabled = Boolean.valueOf(enabledStr).booleanValue();
+ if (enabled != credential.isEnabled())
+ {
+ userManager.setPasswordEnabled(userName,enabled);
+ }
+ }
+ String expiredFlagStr = actionRequest.getParameter("user_expired_flag");
+ if (expiredFlagStr != null)
+ {
+ if ( !passwordSet && expiredFlagStr.equals("expired"))
+ {
+ java.sql.Date today = new java.sql.Date(new Date().getTime());
+ userManager.setPasswordExpiration(userName,today);
+ }
+ else if (expiredFlagStr.equals("extend"))
+ {
+ userManager.setPasswordExpiration(userName,null);
+ }
+ else if (expiredFlagStr.equals("unlimited"))
+ {
+ userManager.setPasswordExpiration(userName,InternalCredential.MAX_DATE);
+ }
+ }
+ }
+ }
+ catch ( InvalidPasswordException ipe )
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,bundle.getString("chgpwd.error.invalidPassword"));
+ }
+ catch ( InvalidNewPasswordException inpe )
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,bundle.getString("chgpwd.error.invalidNewPassword"));
+ }
+ catch ( PasswordAlreadyUsedException paue )
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,bundle.getString("chgpwd.error.passwordAlreadyUsed"));
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ }
+ }
+ }
+
+ private void editUser(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ Iterator attrIter = paUserAttributes.iterator();
+ UserAttribute attr;
+ String value;
+ while( attrIter.hasNext() )
+ {
+ attr = (UserAttribute)attrIter.next();
+ value = actionRequest.getParameter("attr_"+attr.getName());
+ if (value != null)
+ {
+ user.getUserAttributes().put(attr.getName(), value);
+ }
+ }
+ }
+ if ( "true".equals(actionRequest.getPreferences().getValue("showPasswordOnUserTab", "false")))
+ {
+ updateUserCredential(actionRequest, actionResponse);
+ }
+ }
+
+ private void updateUserAttribute(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] userAttrNames = actionRequest.getParameterValues("user_attr_id");
+ if(userAttrNames != null)
+ {
+ for (int i=0; i<userAttrNames.length; i++)
+ {
+ String userAttrName = userAttrNames[i];
+ String value = actionRequest.getParameter(userAttrName + ":value");
+ user.getUserAttributes().put(userAttrName, value);
+ }
+ }
+ }
+ }
+
+ private void addUserAttribute(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String userAttrName = actionRequest.getParameter("user_attr_name");
+ String userAttrValue = actionRequest.getParameter("user_attr_value");
+ if (userAttrName != null && userAttrName.trim().length() > 0)
+ {
+ Preferences attributes = user.getUserAttributes();
+ attributes.put(userAttrName, userAttrValue);
+ }
+ }
+ }
+
+ private void removeUserAttributes(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] userAttrNames = actionRequest.getParameterValues("user_attr_id");
+
+ if(userAttrNames != null)
+ {
+ Preferences attributes = user.getUserAttributes();
+ for(int ix = 0; ix < userAttrNames.length; ix++)
+ {
+ try
+ {
+ attributes.remove(userAttrNames[ix]);
+ }
+ catch (Exception e) {}
+ }
+ }
+ }
+ }
+
+ private void removeUserRoles(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] roleNames = actionRequest.getParameterValues("user_role_id");
+
+ if(roleNames != null)
+ {
+ for (int ix = 0; ix < roleNames.length; ix++)
+ {
+ try
+ {
+ if (roleManager.roleExists(roleNames[ix]))
+ {
+ roleManager.removeRoleFromUser(userName, roleNames[ix]);
+ }
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ // TODO: logging
+ System.err.println("failed to remove user from role: " + userName + ", " + roleNames[ix] + e);
+ }
+ }
+ }
+ }
+ }
+
+ private void addUserRole(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String roleName = actionRequest.getParameter("role_name");
+ if (roleName != null && roleName.trim().length() > 0)
+ {
+ try
+ {
+ roleManager.addRoleToUser(userName, roleName);
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ // TODO: logging
+ System.err.println("failed to add user to role: " + userName + ", " + roleName + e);
+ }
+ }
+ }
+ }
+
+ private void removeUserGroups(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] groupNames = actionRequest.getParameterValues("user_group_id");
+
+ if(groupNames != null)
+ {
+ for (int ix = 0; ix < groupNames.length; ix++)
+ {
+ try
+ {
+ if (groupManager.groupExists(groupNames[ix]))
+ {
+ groupManager.removeUserFromGroup(userName, groupNames[ix]);
+ }
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ // TODO: logging
+ System.err.println("failed to remove user from group: " + userName + ", " + groupNames[ix] + e);
+ }
+ }
+ }
+ }
+ }
+
+ private void addUserGroup(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String groupName = actionRequest.getParameter("group_name");
+ if (groupName != null && groupName.trim().length() > 0)
+ {
+ try
+ {
+ groupManager.addUserToGroup(userName, groupName);
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ // TODO: logging
+ System.err.println("failed to add user to group: " + userName + ", " + groupName + e);
+ }
+ }
+ }
+ }
+
+ private String getAction(String prefix, String action)
+ {
+ return action.substring(prefix.length());
+ }
+
+ private boolean isUserPortletAction(String action)
+ {
+ return action.startsWith(USER_ACTION_PREFIX);
+ }
+
+ private Collection getRoles(String userName)
+ {
+ try
+ {
+ return roleManager.getRolesForUser(userName);
+ }
+ catch (SecurityException e)
+ {
+ // TODO: logging
+ System.err.println("roles not found: " + userName + ", " + e);
+ }
+ return new LinkedList();
+ }
+
+ private Collection getGroups(String userName)
+ {
+ try
+ {
+ return groupManager.getGroupsForUser(userName);
+ }
+ catch (SecurityException e)
+ {
+ // TODO: logging
+ System.err.println("groups not found: " + userName + ", " + e);
+ }
+ return new LinkedList();
+ }
+
+ private PasswordCredential getCredential(User user)
+ {
+ PasswordCredential credential = null;
+
+ Set credentials = user.getSubject().getPrivateCredentials();
+ Iterator iter = credentials.iterator();
+ while (iter.hasNext())
+ {
+ Object o = iter.next();
+ if (o instanceof PasswordCredential)
+ {
+ credential = (PasswordCredential)o;
+ break;
+ }
+ }
+ return credential;
+ }
+ private PasswordCredential getCredential(String userName)
+ {
+ return getCredential(lookupUser(userName));
+ }
+
+ private User lookupUser(String userName)
+ {
+ User user = null;
+ try
+ {
+ user = userManager.getUser(userName);
+ }
+ catch (Exception e)
+ {
+ // TODO: logging
+ System.err.println("user not found: " + userName + ", " + e);
+ }
+ return user;
+ }
+
+ private Collection getProfilerRules()
+ {
+ return profiler.getRules();
+ }
+
+ private Collection getRules(User user)
+ {
+ Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);
+ return profiler.getRulesForPrincipal(userPrincipal);
+ }
+
+ private void addUserProfile(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String locatorName = actionRequest.getParameter("locator_name");
+ if (locatorName != null && locatorName.trim().length() > 0)
+ {
+ try
+ {
+ Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);
+ String ruleName = actionRequest.getParameter("select_rule");
+ profiler.setRuleForPrincipal(userPrincipal,
+ profiler.getRule(ruleName),
+ locatorName);
+ }
+ catch (Exception e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ // TODO: logging
+ System.err.println("failed to set rule for principal: " + userName + ", " + locatorName + e);
+ }
+ }
+
+ }
+ }
+
+ private void removeUserProfile(ActionRequest actionRequest, ActionResponse actionResponse)
+ {
+ String userName = (String)PortletMessaging.receive(actionRequest,
+ SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] locatorNames = actionRequest.getParameterValues("user_profile_id");
+
+ if(locatorNames != null)
+ {
+ Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);
+ Collection rules = profiler.getRulesForPrincipal(userPrincipal);
+ for (int ix = 0; ix < locatorNames.length; ix++)
+ {
+ try
+ {
+ Iterator it = rules.iterator();
+ while (it.hasNext())
+ {
+ PrincipalRule rule = (PrincipalRule)it.next();
+ if (rule.getLocatorName().equals(locatorNames[ix]))
+ {
+ profiler.deletePrincipalRule(rule);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest,e.getMessage());
+ // TODO: logging
+ System.err.println("failed to remove rule for principal: " + userName + ", " + locatorNames[ix] + e);
+ }
+ }
+ }
+ }
+ }
+
+ protected void addUser(ActionRequest actionRequest)
+ {
+ String userName = actionRequest.getParameter("jetspeed.user");
+ String password = actionRequest.getParameter("jetspeed.password");
+ if (!SecurityUtil.isEmpty(userName) && !SecurityUtil.isEmpty(password))
+ {
+ try
+ {
+ userManager.addUser(userName, password);
+ PortletMessaging.publish(actionRequest, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_REFRESH, "true");
+ PortletMessaging.publish(actionRequest, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED, userName);
+
+ User user = userManager.getUser(userName);
+
+ PasswordCredential credential = getCredential(user);
+ if ( credential != null )
+ {
+ String updateRequiredStr = actionRequest.getParameter("user_cred_updreq");
+ if (updateRequiredStr != null)
+ {
+ boolean updateRequired = Boolean.valueOf(updateRequiredStr).booleanValue();
+ if (updateRequired != credential.isUpdateRequired())
+ {
+ userManager.setPasswordUpdateRequired(userName,updateRequired);
+ }
+ }
+ }
+
+ String role = actionRequest.getParameter(ROLES_CONTROL);
+ if (!SecurityUtil.isEmpty(role) && user != null)
+ {
+ roleManager.addRoleToUser(userName, role);
+ }
+
+ // create user's home page and folder
+ Folder folder = pageManager.newFolder(Folder.USER_FOLDER + userName);
+ setSecurityConstraints(folder, userName);
+ pageManager.updateFolder(folder);
+
+ String templateFolder = actionRequest.getPreferences().getValue("newUserTemplateDirectory", "/_user/template/");
+
+ // TODO: copy the entire dir tree, not just the default-page.psml
+ Page template = pageManager.getPage(templateFolder + "default-page.psml");
+ Page copy = pageManager.copyPage(template, Folder.USER_FOLDER + userName + "/default-page.psml");
+ pageManager.updatePage(copy);
+
+ // TODO: send message that site tree portlet invalidated
+
+ String rule = actionRequest.getParameter(RULES_CONTROL);
+ if (!SecurityUtil.isEmpty(rule) && user != null)
+ {
+ Principal principal = SecurityUtil.getPrincipal(user.getSubject(), UserPrincipal.class);
+ profiler.setRuleForPrincipal(principal, profiler.getRule(rule), "page");
+ }
+
+ }
+ catch (Exception se)
+ {
+ ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.UsersResources",actionRequest.getLocale());
+ SecurityUtil.publishErrorMessage(actionRequest, bundle.getString("user.exists"));
+ }
+ }
+ }
+
+ private void setSecurityConstraints(Folder folder, String userName)
+ {
+ SecurityConstraints constraints = pageManager.newSecurityConstraints();
+ constraints.setOwner(userName);
+ folder.setSecurityConstraints(constraints);
+ }
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.security.users;
+
+import java.security.Principal;
+import java.util.Iterator;
+
+import javax.faces.context.FacesContext;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.portals.bridges.jsf.FacesPortlet;
+
+/**
+ * Provides maintenance capabilities for User Administration.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: UserManagerPortlet.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class UserManagerPortlet extends FacesPortlet {
+ private UserManager userManager;
+
+ public void init(PortletConfig config) throws PortletException {
+ super.init(config);
+ userManager = (UserManager) getPortletContext().getAttribute(
+ CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+ if (null == userManager) {
+ throw new PortletException(
+ "Failed to find the User Manager on portlet initialization");
+ }
+ System.out.println("user manager = " + userManager);
+ try {
+ Iterator users = userManager.getUsers("");
+ while (users.hasNext()) {
+ User user = (User) users.next();
+ System.out.println("++++ User = " + user);
+ Principal principal = getPrincipal(user.getSubject(),
+ UserPrincipal.class);
+ System.out.println("principal = " + principal.getName());
+ }
+ } catch (SecurityException se) {
+ throw new PortletException(se);
+ }
+ }
+
+ protected void preProcessFaces(FacesContext context) {
+ System.out.println("*** pre processing faces for user manager: "
+ + context);
+ }
+
+ public Principal getPrincipal(Subject subject, Class classe) {
+ Principal principal = null;
+ Iterator principals = subject.getPrincipals().iterator();
+ while (principals.hasNext()) {
+ Principal p = (Principal) principals.next();
+ if (classe.isInstance(p)) {
+ principal = p;
+ break;
+ }
+ }
+ return principal;
+ }
+
+}
\ No newline at end of file
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletIterator.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletIterator.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletIterator.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletIterator.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.selector;
+
+import java.util.List;
+
+import org.apache.jetspeed.portlets.selector.PortletSelector.PortletInfo;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+
+
+/**
+ * PortletIterator
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: PortletIterator.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+
+public class PortletIterator extends DatabaseBrowserIterator
+{
+ private static final long serialVersionUID = 1;
+
+ public PortletIterator(List result, List columnTitles,
+ List columnTypes, int pageSize)
+ {
+ super(result, columnTitles, columnTypes, pageSize);
+ }
+
+ public int compare(Object obj1, Object obj2)
+ {
+ PortletInfo info1 = (PortletInfo)obj1;
+ PortletInfo info2 = (PortletInfo)obj2;
+ String name1 = info1.getDisplayName();
+ String name2 = info2.getDisplayName();
+ int order = 0;
+
+ if (name1 == null)
+ {
+ if (name2 == null)
+ order = 0;
+ else
+ order = -1;
+ }
+ else if (name2 == null)
+ {
+ order = 1;
+ }
+ else
+ {
+ order = name1.compareTo(name2);
+ }
+
+ if (!getAscendingOrder())
+ {
+ order = 0 - order;
+ }
+ return order;
+
+ }
+
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletSelector.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletSelector.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletSelector.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/PortletSelector.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,300 @@
+/* Copyright 2004 Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.jetspeed.portlets.selector;
+
+import java.io.IOException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.om.common.SecuredResource;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
+import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.search.ParsedObject;
+import org.apache.jetspeed.search.SearchEngine;
+import org.apache.jetspeed.security.PermissionManager;
+import org.apache.jetspeed.security.PortletPermission;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+import org.apache.portals.gems.util.StatusMessage;
+import org.apache.portals.messaging.PortletMessaging;
+
+/**
+ * Selects one or more portlets
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: PortletSelector.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class PortletSelector extends BrowserPortlet
+{
+ protected PortletRegistry registry;
+ protected SearchEngine searchEngine;
+ protected PermissionManager permissionManager;
+
+ public void init(PortletConfig config)
+ throws PortletException
+ {
+ super.init(config);
+ context = getPortletContext();
+ registry = (PortletRegistry)context.getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT);
+ if (null == registry)
+ {
+ throw new PortletException("Failed to find the Portlet Registry on portlet initialization");
+ }
+ searchEngine = (SearchEngine)context.getAttribute(CommonPortletServices.CPS_SEARCH_COMPONENT);
+ if (null == searchEngine)
+ {
+ throw new PortletException("Failed to find the Search Engine on portlet initialization");
+ }
+ permissionManager = (PermissionManager)context.getAttribute(CommonPortletServices.CPS_PERMISSION_MANAGER);
+ if (null == permissionManager)
+ {
+ throw new PortletException("Failed to find the Permission Manager on portlet initialization");
+ }
+
+ }
+
+ public void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
+ {
+ StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, PortletApplicationResources.TOPIC_PORTLET_SELECTOR, PortletApplicationResources.MESSAGE_STATUS);
+ if (msg != null)
+ {
+ this.getContext(request).put("statusMsg", msg);
+ }
+
+ String filtered = (String)PortletMessaging.receive(request, PortletApplicationResources.TOPIC_PORTLET_SELECTOR, PortletApplicationResources.MESSAGE_FILTERED);
+ if (filtered != null)
+ {
+ this.getContext(request).put(FILTERED, "on");
+ }
+
+ super.doView(request, response);
+ }
+
+ public void processAction(ActionRequest request, ActionResponse response)
+ throws PortletException, IOException
+ {
+ String filtered = (String)request.getParameter(FILTERED);
+ if (filtered != null)
+ {
+ PortletMessaging.publish(request, PortletApplicationResources.TOPIC_PORTLET_SELECTOR, PortletApplicationResources.MESSAGE_FILTERED, "on");
+ }
+ else
+ {
+ PortletMessaging.cancel(request, PortletApplicationResources.TOPIC_PORTLET_SELECTOR, PortletApplicationResources.MESSAGE_FILTERED);
+ }
+
+ super.processAction(request, response);
+
+ }
+
+ public void getRows(RenderRequest request, String sql, int windowSize)
+ throws Exception
+ {
+ getRows(request, sql, windowSize, null);
+ }
+
+ public void getRows(RenderRequest request, String sql, int windowSize, String filter)
+ throws Exception
+ {
+ List resultSetTitleList = new ArrayList();
+ List resultSetTypeList = new ArrayList();
+ try
+ {
+ Iterator portlets = null;
+
+ if (filter == null)
+ portlets = registry.getAllPortletDefinitions().iterator();
+ else
+ portlets = searchEngine.search(filter).getResults().iterator();
+
+ resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+ resultSetTitleList.add("Portlet");
+ resultSetTitleList.add("Description");
+ Locale locale = request.getLocale();
+ List list = new ArrayList();
+
+ // get subject
+ RequestContext requestContext = (RequestContext) request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+ Subject subject = null;
+ if (requestContext != null)
+ subject = requestContext.getSubject();
+
+ while (portlets.hasNext())
+ {
+ PortletDefinitionComposite portlet = null;
+ if (filter == null)
+ portlet = (PortletDefinitionComposite)portlets.next();
+ else
+ portlet = this.getPortletFromParsedObject((ParsedObject)portlets.next());
+
+ if (portlet == null)
+ continue;
+
+ MutablePortletApplication muta = (MutablePortletApplication)portlet.getPortletApplicationDefinition();
+ String appName = muta.getName();
+ if (appName != null && appName.equals("jetspeed-layouts"))
+ continue;
+
+ // SECURITY filtering
+ String uniqueName = appName + "::" + portlet.getName();
+ if (subject != null)
+ {
+ if (permissionManager.checkPermission(subject,
+ new PortletPermission(portlet.getUniqueName(),
+ SecuredResource.VIEW_ACTION, subject )))
+ {
+ list.add(new PortletInfo(uniqueName, portlet.getDisplayNameText(locale), portlet.getDescriptionText(locale)));
+ }
+ }
+ }
+ BrowserIterator iterator = new PortletIterator(
+ list, resultSetTitleList, resultSetTypeList,
+ windowSize);
+ setBrowserIterator(request, iterator);
+ iterator.sort("Portlet");
+ }
+ catch (Exception e)
+ {
+ //log.error("Exception in CMSBrowserAction.getRows: ", e);
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ public class PortletInfo
+ {
+ private String name;
+ private String displayName;
+ private String description;
+
+ public PortletInfo(String name, String displayName, String description)
+ {
+ this.name = name;
+ this.displayName = displayName;
+ this.description = description;
+ }
+ /**
+ * @return Returns the description.
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+ /**
+ * @return Returns the displayName.
+ */
+ public String getDisplayName()
+ {
+ return displayName;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+ }
+
+ public int find(BrowserIterator iterator, String searchString, String searchColumn)
+ {
+ int index = 0;
+ int column = 1;
+
+ if (searchColumn != null)
+ column = Integer.parseInt(searchColumn);
+
+ Iterator it = iterator.getResultSet().iterator();
+ while (it.hasNext())
+ {
+ PortletInfo info = (PortletInfo)it.next();
+ String name = info.getDisplayName();
+ if (name != null && name.startsWith(searchString))
+ {
+ return index;
+ }
+ index++;
+ }
+
+ return -1;
+ }
+
+ protected PortletDefinitionComposite getPortletFromParsedObject(ParsedObject po)
+ {
+ boolean found = false;
+ String name = "";
+ Map fields = po.getFields();
+ if(fields != null)
+ {
+ Object id = fields.get("ID");
+
+ if(id != null)
+ {
+ if(id instanceof Collection)
+ {
+ Collection coll = (Collection)id;
+ name = (String) coll.iterator().next();
+ }
+ else
+ {
+ name = (String)id;
+ }
+ }
+
+ if(po.getType().equals("portlet"))
+ {
+ Object pa = fields.get("portlet_application");
+ String paName = "";
+ if(pa != null)
+ {
+ if(id instanceof Collection)
+ {
+ Collection coll = (Collection)pa;
+ paName = (String) coll.iterator().next();
+ }
+ else
+ {
+ paName = (String)pa;
+ }
+ }
+ name = paName + "::" + name;
+ found = true;
+ }
+ }
+ if (found == false)
+ return null;
+
+ return registry.getPortletDefinitionByUniqueName(name);
+ }
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.site;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+
+
+/**
+ * Abstract Tree Portlet
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+
+public class AbstractPSMLTreePortlet extends GenericServletPortlet
+{
+ protected PageManager pageManager;
+ protected PSMLTreeLoader loader;
+ /** the PSML Root, i.e "/" or "/_users/joe" **/
+ protected String psmlRoot;
+
+ /** image map for content type **/
+ protected Map imageMap = new HashMap();
+
+ protected String linkImage;
+ protected String folderImage;
+ protected String documentImage;
+ protected String rootImage;
+ protected String rootLabel;
+
+
+ public void init(PortletConfig config) throws PortletException
+ {
+ super.init(config);
+
+ pageManager = (PageManager) getPortletContext().getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT);
+ if (null == pageManager) { throw new PortletException(
+ "Failed to find the Page Manager on portlet initialization"); }
+
+ loader = new PSMLTreeLoader(pageManager, this);
+ psmlRoot = config.getInitParameter("psmlRoot");
+ if (psmlRoot == null)
+ {
+ psmlRoot = "/";
+ }
+
+ // Images
+ String extensions = config.getInitParameter("extensions");
+ String images = config.getInitParameter("images");
+ linkImage = config.getInitParameter("linkImage");
+ folderImage = config.getInitParameter("folderImage");
+ documentImage = config.getInitParameter("documentImage");
+ rootImage = config.getInitParameter("rootImage");
+ rootLabel = config.getInitParameter("rootLabel");
+
+ if (extensions == null)
+ {
+ extensions = "text/html,text/plain,application/pdf";
+ }
+ if (images == null)
+ {
+ images = "html-document.gif, text-document.gif, pdficon.jpg";
+ }
+ if (linkImage == null)
+ {
+ linkImage = "link.gif";
+ }
+ if (folderImage == null)
+ {
+ folderImage = "folder.gif";
+ }
+ if (documentImage == null)
+ {
+ documentImage = "document.gif";
+ }
+ if (rootImage == null)
+ {
+ rootImage = "root.gif";
+ }
+ if (rootLabel == null)
+ {
+ rootLabel = "Bookshelf";
+ }
+
+ String[]ext = stringToArray(extensions, ", ");
+ String[]img = stringToArray(images, ", ");
+ int max = (ext.length > img.length) ? img.length : ext.length;
+ for (int ix = 0; ix < max; ix++)
+ {
+ imageMap.put(ext[ix], img[ix]);
+ }
+ }
+
+ public static final String[] stringToArray(String str, String separators)
+ {
+ StringTokenizer tokenizer;
+ String[] array = null;
+ int count = 0;
+
+ if (str == null)
+ return array;
+
+ if (separators == null)
+ separators = ", ";
+
+ tokenizer = new StringTokenizer(str, separators);
+ if ((count = tokenizer.countTokens()) <= 0) {
+ return array;
+ }
+
+ array = new String[count];
+
+ int ix = 0;
+ while (tokenizer.hasMoreTokens())
+ {
+ array[ix] = tokenizer.nextToken();
+ ix++;
+ }
+
+ return array;
+ }
+
+ /**
+ * @return Returns the linkImage.
+ */
+ public String getLinkImage()
+ {
+ return linkImage;
+ }
+ /**
+ * @return Returns the folderImage.
+ */
+ public String getFolderImage(Folder folder)
+ {
+ if (folder.isReserved())
+ {
+ if (folder.getReservedType() == Folder.RESERVED_FOLDER_USERS)
+ return "users.gif";
+ else if (folder.getReservedType() == Folder.RESERVED_FOLDER_ROLES)
+ return "roles.gif";
+ else if (folder.getReservedType() == Folder.RESERVED_FOLDER_GROUPS)
+ return "groups.gif";
+ else if (folder.getReservedType() == Folder.RESERVED_FOLDER_SUBSITES)
+ return "subsites.gif";
+ else
+ return "other.gif";
+ }
+ return folderImage;
+ }
+
+ public String getImageForContentType(String contentType)
+ {
+ String ct = (String)imageMap.get(contentType);
+ if (ct == null)
+ return documentImage;
+ return ct;
+ }
+ /**
+ * @return Returns the documentImage.
+ */
+ public String getDocumentImage()
+ {
+ return documentImage;
+ }
+ /**
+ * @return Returns the rootImage.
+ */
+ public String getRootImage()
+ {
+ return rootImage;
+ }
+ /**
+ * @return Returns the rootLabel.
+ */
+ public String getRootLabel()
+ {
+ return rootLabel;
+ }
+
+ public String getFolderTitle(Folder folder, Locale locale)
+ {
+ String title = folder.getTitle(locale);
+ if (title == null)
+ title = folder.getName();
+ return title;
+ }
+
+ public String getPageTitle(Page page, Locale locale)
+ {
+ String title = page.getTitle(locale);
+ if (title == null)
+ {
+ title = page.getName();
+ }
+ return title;
+ }
+
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/FolderProxyBean.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/FolderProxyBean.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/FolderProxyBean.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/FolderProxyBean.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.site;
+
+import java.io.Serializable;
+
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.portals.bridges.frameworks.ExternalComponentSupport;
+import org.apache.portals.bridges.frameworks.Lookup;
+
+
+/**
+ * FolderProxyBean
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: FolderProxyBean.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class FolderProxyBean
+ implements
+ ExternalComponentSupport,
+ Lookup,
+ Serializable
+{
+ private transient PageManager pageManager = null;
+ private transient Folder folder;
+ private String lookupKey;
+ private boolean isNew = true;
+
+ private String title;
+ private String name;
+ private String shortTitle;
+ private String defaultPage;
+ private String theme;
+ private String resourceType;
+ private String key;
+ private String path;
+
+ /**
+ * @return Returns the path.
+ */
+ public String getPath()
+ {
+ return path;
+ }
+ /**
+ * @param path The path to set.
+ */
+ public void setPath(String path)
+ {
+ this.path = path;
+ }
+ /**
+ * @return Returns the defaultPage.
+ */
+ public String getDefaultPage()
+ {
+ return defaultPage;
+ }
+ /**
+ * @param defaultPage The defaultPage to set.
+ */
+ public void setDefaultPage(String defaultPage)
+ {
+ this.defaultPage = defaultPage;
+ }
+ /**
+ * @return Returns the resourceType.
+ */
+ public String getResourceType()
+ {
+ return resourceType;
+ }
+ /**
+ * @param resourceType The resourceType to set.
+ */
+ public void setResourceType(String resourceType)
+ {
+ this.resourceType = resourceType;
+ }
+ /**
+ * @return Returns the shortTitle.
+ */
+ public String getShortTitle()
+ {
+ return shortTitle;
+ }
+ /**
+ * @param shortTitle The shortTitle to set.
+ */
+ public void setShortTitle(String shortTitle)
+ {
+ this.shortTitle = shortTitle;
+ }
+
+ public FolderProxyBean()
+ {
+ }
+
+ public void setExternalSupport(Object externalSupport)
+ {
+ if (externalSupport instanceof PageManager)
+ {
+ pageManager = (PageManager)externalSupport;
+ }
+ }
+
+ public void update(Folder folder)
+ {
+ folder.setTitle(this.getTitle());
+ folder.setDefaultPage(this.getDefaultPage());
+ folder.setShortTitle(this.getShortTitle());
+ }
+
+ public boolean lookup(String key)
+ {
+ boolean result = true;
+ try
+ {
+ if (pageManager != null)
+ {
+ this.folder = pageManager.getFolder(key);
+ setTitle(folder.getTitle());
+ setShortTitle(folder.getShortTitle());
+ setDefaultPage(folder.getDefaultPage());
+ setName(folder.getName());
+ setKey(key);
+ setPath(folder.getPath());
+ isNew = false;
+ }
+ }
+ catch (Exception ne)
+ {
+ // create a new folder
+ result = false;
+ }
+ return result;
+ }
+
+ /**
+ * @return Returns the title.
+ */
+ public String getTitle()
+ {
+ return title;
+ }
+ /**
+ * @param title The title to set.
+ */
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
+ /**
+ * @return Returns the lookupKey.
+ */
+ public String getLookupKey()
+ {
+ return lookupKey;
+ }
+ /**
+ * @param lookupKey The lookupKey to set.
+ */
+ public void setLookupKey(String lookupKey)
+ {
+ this.lookupKey = lookupKey;
+ }
+ /**
+ * @return Returns the isNew.
+ */
+ public boolean isNew()
+ {
+ return isNew;
+ }
+ /**
+ * @param isNew The isNew to set.
+ */
+ public void setNew(boolean isNew)
+ {
+ this.isNew = isNew;
+ }
+ /**
+ * @return Returns the key.
+ */
+ public String getKey()
+ {
+ return key;
+ }
+ /**
+ * @param key The key to set.
+ */
+ public void setKey(String key)
+ {
+ this.key = key;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.site;
+
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Locale;
+
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Link;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.page.document.Node;
+import org.apache.jetspeed.page.document.NodeSet;
+import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
+import org.apache.webapp.admin.TreeControlNode;
+
+/**
+ * PSML Tree Loader
+ * Encapsulates the handling of PSML content into a tree view
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class PSMLTreeLoader
+{
+ public static final String ROOT_DOMAIN = "ROOT_DOMAIN";
+ public static final String FOLDER_DOMAIN = "FOLDER_DOMAIN";
+ public static final String PAGE_DOMAIN = "PAGE_DOMAIN";
+ public static final String LINK_DOMAIN = "LINK_DOMAIN";
+
+ public final static String PORTLET_URL = "portlet_url";
+
+ private AbstractPSMLTreePortlet portlet;
+ private PageManager pm;
+
+ public PSMLTreeLoader(PageManager pm, AbstractPSMLTreePortlet portlet)
+ {
+ this.pm = pm;
+ this.portlet = portlet;
+ }
+
+ public TreeControlNode createRootNode(Folder folder, Locale locale)
+ {
+ TreeControlNode root =
+ new TreeControlNode(folder.getPath(), // unique id
+ portlet.getRootImage(), // image
+ folder.getTitle(locale), // label
+ PortletApplicationResources.PORTLET_URL, // action
+ null, // target
+ true, // expanded
+ FOLDER_DOMAIN); // domain
+
+ return root;
+ }
+
+ public TreeControlNode createFolderNode(Folder folder, Locale locale, String domain) throws JetspeedException
+ {
+ TreeControlNode node =
+ new TreeControlNode(
+ folder.getPath(), // unique id
+ portlet.getFolderImage(folder), // image
+ portlet.getFolderTitle(folder, locale), // label
+ PortletApplicationResources.PORTLET_URL, // action
+ null, // target
+ false, // expanded
+ FOLDER_DOMAIN, // domain
+ "Folder", // CSS
+ true); // lazy load
+
+ node.setExpandWhenClicked(true);
+ node.setTitle(folder.getName());
+ node.setLeaf(folder.getAll().isEmpty());
+
+ return node;
+ }
+
+ public TreeControlNode createPageNode(Page page, Locale locale, String domain)
+ {
+ String title = portlet.getPageTitle(page, locale);
+
+ TreeControlNode issueNode =
+ new TreeControlNode(
+ page.getPath(), // unique id
+ portlet.getImageForContentType("text/html"), // image
+ title, // label
+ PortletApplicationResources.PORTLET_URL, // action
+ null, // target
+ false, // expanded
+ PAGE_DOMAIN, // domain
+ "Document", // css
+ true); // lazy load
+
+ issueNode.setTitle(title);
+ issueNode.setLeaf(true);
+
+ return issueNode;
+ }
+
+ public TreeControlNode createLinkNode(Link link, Locale locale, String domain)
+ {
+ TreeControlNode linkNode =
+ new TreeControlNode(
+ link.getPath(), // unique id
+ portlet.getLinkImage(), // image
+ link.getTitle(locale), // label
+ PortletApplicationResources.PORTLET_URL, // action
+ null, // target
+ false, // expanded
+ LINK_DOMAIN, // domain
+ null, // css
+ true); // lazy load
+
+ linkNode.setTitle(link.getTitle());
+ linkNode.setLeaf(true);
+
+ return linkNode;
+ }
+
+ public void loadChildren(Folder folder, TreeControlNode parent, Locale locale)
+ {
+ NodeSet childFolders = null;
+ NodeSet childPages = null;
+ NodeSet childLinks = null;
+ try
+ {
+// int ilevel = ((new Integer(parent.getDomain()).intValue()) + 1);
+// String level = Integer.toString(ilevel);
+ String level = "";
+
+ childFolders = folder.getFolders();
+ childPages = folder.getPages();
+ childLinks = folder.getLinks();
+
+ if (childFolders != null)
+ {
+ Iterator folderIter = childFolders.iterator();
+ while (folderIter.hasNext())
+ {
+ Folder childFolder = (Folder) folderIter.next();
+ TreeControlNode childNode = createFolderNode(childFolder, locale, level);
+ parent.addChild(childNode);
+ }
+ }
+ if (childPages != null)
+ {
+ Iterator pagesIter = childPages.iterator();
+ while (pagesIter.hasNext())
+ {
+ Page childPage = (Page) pagesIter.next();
+ TreeControlNode childNode = createPageNode(childPage, locale, level);
+ parent.addChild(childNode);
+ }
+ }
+ if (childLinks != null)
+ {
+ Iterator linksIter = childLinks.iterator();
+ while (linksIter.hasNext())
+ {
+ Link childLink = (Link) linksIter.next();
+ TreeControlNode childNode = createLinkNode(childLink, locale, level);
+ parent.addChild(childNode);
+ }
+ }
+ parent.setLoaded(true);
+ }
+ catch (JetspeedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public static Comparator psmlComparator = new PSMLObjectComparator();
+
+ public static Comparator getComparator()
+ {
+ return psmlComparator;
+ }
+
+ private static class PSMLObjectComparator implements Comparator
+ {
+ public int compare(Object o1, Object o2)
+ {
+ Node lhs = (Node)o1;
+ Node rhs = (Node)o2;
+
+ return rhs.getName().compareTo(lhs.getName());
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org