01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.services.entityproperties;
07:
08: import java.util.Iterator;
09:
10: import org.jasig.portal.EntityIdentifier;
11: import org.jasig.portal.groups.IEntityGroup;
12: import org.jasig.portal.groups.IGroupMember;
13: import org.jasig.portal.services.GroupService;
14: import org.apache.commons.logging.Log;
15: import org.apache.commons.logging.LogFactory;
16:
17: /**
18: * A finder implementation to provide a , delimited list of containing groups
19: * for any entity
20: *
21: * @author Alex Vigdor av317@columbia.edu
22: * @version $Revision: 34797 $
23: */
24:
25: public class ContainingGroupsFinder implements IEntityPropertyFinder {
26:
27: private static final Log log = LogFactory
28: .getLog(ContainingGroupsFinder.class);
29:
30: protected final static String[] names = new String[] { "Containing Groups" };
31:
32: public ContainingGroupsFinder() {
33: }
34:
35: public String[] getPropertyNames(EntityIdentifier entityID) {
36: return names;
37: }
38:
39: public String getProperty(EntityIdentifier entityID, String name) {
40: String r = null;
41: try {
42: StringBuffer buf = new StringBuffer();
43: if (name.equals(names[0])) {
44: IGroupMember gm = GroupService.getGroupMember(entityID);
45: Iterator i = gm.getContainingGroups();
46: int x = 0;
47: while (i.hasNext()) {
48: if (x > 0) {
49: buf.append(", ");
50: }
51: IEntityGroup g = (IEntityGroup) i.next();
52: buf.append(g.getName());
53: x++;
54: }
55: }
56: r = buf.toString();
57: } catch (Exception e) {
58: log.error("Exception getting property " + "entityId="
59: + entityID + " name=" + name, e);
60: }
61: return r;
62: }
63: }
|