CParameters

A channel for debugging parameters.

CParameters
package org.jasig.portal.channels.iccdemo;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

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;

/**
 * A demo channel which displays all the parameters it has received.
 * @author andrew.petro@yale.edu
 * @version $Revision:$ $Date:$
 */
public class CParameters 
    extends CAbstractXSLT
    implements IChannel {

    private String xsltUri = "cparams.xsl";
    
    /* (non-Javadoc)
     * @see org.jasig.portal.IChannel#setStaticData(org.jasig.portal.ChannelStaticData)
     */
    public void setStaticData(ChannelStaticData sd) throws PortalException {
        // do nothing
    }

    /* (non-Javadoc)
     * @see org.jasig.portal.IChannel#receiveEvent(org.jasig.portal.PortalEvent)
     */
    public void receiveEvent(PortalEvent ev) {
        // do nothing
    }

    /* (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() {
        // Get a new DOM instance
        Document doc = DocumentFactory.getNewDocument();

        ChannelRuntimeData rd = getRuntimeData();

        Element paramsEl = doc.createElement("params");
        Enumeration params =rd.getParameterNames();
        while (params.hasMoreElements()) {
            String paramName = (String) params.nextElement();
            String paramValue = rd.getParameter(paramName);
            
            Element paramEl=doc.createElement("param");
            paramEl.setAttribute("name", paramName);
            paramEl.setAttribute("value", paramValue);
            paramsEl.appendChild(paramEl);
        }
        
        doc.appendChild(paramsEl);
        return doc;
    }

    /* (non-Javadoc)
     * @see org.jasig.portal.channels.CAbstractXSLT#getXsltUri()
     */
    protected String getXsltUri() {
        return this.xsltUri;
    }

    /* (non-Javadoc)
     * @see org.jasig.portal.channels.CAbstractXSLT#getStylesheetParams()
     */
    protected Map getStylesheetParams() {
        return new HashMap();
    }

}

Here's the XSLT for rendering parameters.

cparams.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:template match="params">
	<div class='portlet-msg-info'>
		This channel displays the names and values of all the parameters sent to it.
	</div>
    <xsl:apply-templates select='param'/>
   </xsl:template>
   
   
   <xsl:template match='param'>
		<div class='portlet-section-body'>
				<xsl:value-of select='@name'/>=<xsl:value-of select='@value'/>
		</div>
   </xsl:template>
</xsl:stylesheet>

Here's an example of the sort of XML this XSLT is intended to render:

paramsExample.xml
<?xml version="1.0"?>
<params>
	<param name="name1" value="value1"/>
	<param name="name2" value="name2"/>
</params>