001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels.permissionsmanager;
007:
008: import java.util.HashMap;
009:
010: import org.jasig.portal.ChannelRegistryManager;
011: import org.jasig.portal.IPermissible;
012: import org.jasig.portal.groups.IEntityNameFinder;
013: import org.jasig.portal.services.EntityNameFinderService;
014: import org.apache.commons.logging.Log;
015: import org.apache.commons.logging.LogFactory;
016: import org.w3c.dom.Document;
017: import org.w3c.dom.Element;
018: import org.w3c.dom.NodeList;
019:
020: /**
021: * An IPermissible implementation that provides management of uPortal 2.0
022: * channel subscribtion permissions
023: *
024: * @author Alex Vigdor
025: * @version $Revision: 34837 $
026: */
027: public class PermissibleSubscribeChannels implements IPermissible {
028: private static final Log log = LogFactory
029: .getLog(PermissibleSubscribeChannels.class);
030: protected HashMap activities = new HashMap();
031: protected HashMap targets = new HashMap();
032:
033: /**
034: * put your documentation comment here
035: */
036: public PermissibleSubscribeChannels() {
037: try {
038: activities.put("SUBSCRIBE", "Subscribe to Channel");
039: Document chanregistry = ChannelRegistryManager
040: .getChannelRegistry();
041: NodeList chans = chanregistry
042: .getElementsByTagName("channel");
043: IEntityNameFinder chanf = EntityNameFinderService
044: .instance()
045: .getNameFinder(
046: Class
047: .forName("org.jasig.portal.ChannelDefinition"));
048: for (int i = 0; i < chans.getLength(); i++) {
049: Element chan = (Element) chans.item(i);
050: String chanID = chan.getAttribute("ID");
051: if (chanID.indexOf("chan") == 0) {
052: chanID = chanID.substring(4);
053: }
054: targets.put("CHAN_ID." + chanID, chanf.getName(chanID));
055: }
056: } catch (Exception e) {
057: log.error(e, e);
058: }
059: }
060:
061: /**
062: * put your documentation comment here
063: * @return an array of <code>String</code> activity tokens
064: */
065: public String[] getActivityTokens() {
066: return (String[]) activities.keySet().toArray(new String[0]);
067: }
068:
069: /**
070: * put your documentation comment here
071: * @param token
072: * @return the <code>String</code> activity name
073: */
074: public String getActivityName(String token) {
075: return (String) activities.get(token);
076: }
077:
078: /**
079: * put your documentation comment here
080: * @return an array of <code>String</code> target tokens
081: */
082: public String[] getTargetTokens() {
083: return (String[]) targets.keySet().toArray(new String[0]);
084: }
085:
086: /**
087: * put your documentation comment here
088: * @param token
089: * @return a <code>String</code> target name
090: */
091: public String getTargetName(String token) {
092: return (String) targets.get(token);
093: }
094:
095: /**
096: * put your documentation comment here
097: * @return the <code>String</code> owner token
098: */
099: public String getOwnerToken() {
100: return "UP_FRAMEWORK";
101: }
102:
103: /**
104: * put your documentation comment here
105: * @return the <code>String</code> owner name
106: */
107: public String getOwnerName() {
108: return "uPortal Channel Subscription";
109: }
110: }
|