1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* distributed under the License is distributed on an "AS IS" BASIS,13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14* See the License for the specific language governing permissions and15* limitations under the License.16*/17packageorg.apache.jetspeed.portlets.security.users;
1819import java.security.Principal;
20import java.sql.Types;
21import java.util.ArrayList;
22import java.util.Iterator;
23import java.util.List;
2425import javax.portlet.PortletConfig;
26import javax.portlet.PortletException;
27import javax.portlet.RenderRequest;
2829import org.apache.jetspeed.CommonPortletServices;
30import org.apache.jetspeed.security.Group;
31import org.apache.jetspeed.security.GroupManager;
32import org.apache.portals.gems.browser.BrowserIterator;
33import org.apache.portals.gems.browser.DatabaseBrowserIterator;
34import org.apache.portals.gems.browser.BrowserPortlet;
3536/***37 * GroupChooserPortlet38 * 39 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>40 * @version $Id: GroupChooserPortlet.java 348264 2005-11-22 22:06:45Z taylor $41 */42publicclassGroupChooserPortletextends BrowserPortlet
43 {
44private GroupManager groupManager;
4546publicvoid init(PortletConfig config)
47 throws PortletException
48 {
49super.init(config);
50 groupManager = (GroupManager)
51 getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT);
52if (null == groupManager)
53 {
54thrownew PortletException("Failed to find the User Manager on portlet initialization");
55 }
56 }
5758publicvoid getRows(RenderRequest request, String sql, int windowSize)
59 throws Exception
60 {
61 List resultSetTitleList = new ArrayList();
62 List resultSetTypeList = new ArrayList();
63try64 {
65 Iterator groups = groupManager.getGroups("");
666768 resultSetTypeList.add(String.valueOf(Types.VARCHAR));
69 resultSetTitleList.add("Group");
7071// TODO: need to try to normalize List/Collection/Iterators72 List list = new ArrayList();
73while (groups.hasNext())
74 {
75 Group group = (Group)groups.next();
7677 Principal principal = group.getPrincipal();
78 list.add(principal.getName());
79 }
8081 BrowserIterator iterator = new DatabaseBrowserIterator(
82 list, resultSetTitleList, resultSetTypeList,
83 windowSize);
84 setBrowserIterator(request, iterator);
85 iterator.sort("Group");
86 }
87catch (Exception e)
88 {
89//log.error("Exception in CMSBrowserAction.getRows: ", e);90 e.printStackTrace();
91throw e;
92 }
93 }
9495 }