package org.jasig.portal.channels.iccdemo;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import javax.naming.Context;
import javax.naming.NamingException;
import org.jasig.portal.ChannelRuntimeData;
import org.jasig.portal.ChannelRuntimeProperties;
import org.jasig.portal.ChannelStaticData;
import org.jasig.portal.IChannel;
import org.jasig.portal.PortalEvent;
import org.jasig.portal.PortalException;
import org.jasig.portal.channels.CAbstractXSLT;
import org.jasig.portal.utils.DocumentFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Demonstration of ability to open other channels in focus mode.
* @author andrew.petro@yale.edu
* @version $Revision:$ $Date:$
*/
public class CFocusAnotherChannel
extends CAbstractXSLT
implements IChannel {
/**
* The name of the channel static data parameter the value of which must be
* the fname of the channel to which we should render a URL which launches it
* in detach mode.
*/
public static final String TARGET_FNAME_PARAM = "target_fname";
private Map fnamesToSubscribeIds = new HashMap();
private Map parameters = new HashMap();
private String xslLocation = "focusAnother.xsl";
public void setRuntimeDataInternal() {
ChannelRuntimeData runtimeData = getRuntimeData();
String paramName = runtimeData.getParameter("paramName");
String paramValue = runtimeData.getParameter("paramValue");
if (paramName != null && paramValue != null) {
this.parameters.put(paramName, paramValue);
if (log.isTraceEnabled()) {
log.trace("recorded parameter name [" +
paramName + "] with value [" + paramValue + "]");
}
} else {
if (log.isTraceEnabled()) {
log.trace("Parameters paramName and paramValue not set.");
}
}
}
/* (non-Javadoc)
* @see org.jasig.portal.IChannel#setStaticData(org.jasig.portal.ChannelStaticData)
*/
public void setStaticData(ChannelStaticData sd) throws PortalException {
try {
Context context = (Context) sd.getJNDIContext().lookup("/channel-ids");
String fnamesWdl = sd.getParameter(TARGET_FNAME_PARAM);
for (StringTokenizer tokens = new StringTokenizer(fnamesWdl);
tokens.hasMoreTokens(); ) {
String fname = tokens.nextToken();
try {
this.fnamesToSubscribeIds.put(fname, context.lookup(fname));
} catch (NamingException nex) {
log.error("We are configured to provide a link to channel" +
" with fname [" + fname +
"] but looking up that name in context /channel-ids failed", nex);
}
}
} catch (NamingException e) {
log.error("Problem getting context [/channel-ids]", e);
}
}
/* (non-Javadoc)
* @see org.jasig.portal.IChannel#receiveEvent(org.jasig.portal.PortalEvent)
*/
public void receiveEvent(PortalEvent ev) {
}
/* (non-Javadoc)
* @see org.jasig.portal.IChannel#getRuntimeProperties()
*/
public ChannelRuntimeProperties getRuntimeProperties() {
return new ChannelRuntimeProperties();
}
/* (non-Javadoc)
* @see org.jasig.portal.channels.CAbstractXSLT#getXml()
*/
protected Document getXml() {
Document doc = DocumentFactory.getNewDocument();
Element focusEl = doc.createElement("focus");
Element paramsEl = doc.createElement("params");
for (Iterator paramIter = this.parameters.keySet().iterator();
paramIter.hasNext() ; ) {
String paramName = (String) paramIter.next();
String paramValue = (String) this.parameters.get(paramName);
Element paramEl = doc.createElement("param");
paramEl.setAttribute("name", paramName);
paramEl.setAttribute("value", paramValue);
paramsEl.appendChild(paramEl);
}
focusEl.appendChild(paramsEl);
Element channelsEl = doc.createElement("channels");
for(Iterator chanIter = this.fnamesToSubscribeIds.keySet().iterator();
chanIter.hasNext();) {
String fname = (String) chanIter.next();
String subscribeId = (String) this.fnamesToSubscribeIds.get(fname);
Element channelEl=doc.createElement("channel");
channelEl.setAttribute("fname", fname);
channelEl.setAttribute("subscribeId", subscribeId);
channelsEl.appendChild(channelEl);
}
focusEl.appendChild(channelsEl);
doc.appendChild(focusEl);
return doc;
}
/* (non-Javadoc)
* @see org.jasig.portal.channels.CAbstractXSLT#getXsltUri()
*/
protected String getXsltUri() {
return this.xslLocation;
}
/* (non-Javadoc)
* @see org.jasig.portal.channels.CAbstractXSLT#getStylesheetParams()
*/
protected Map getStylesheetParams() {
Map map = new HashMap();
map.put("baseActionURL", getRuntimeData().getBaseActionURL());
return map;
}
}