/** * Copyright © 2001 The JA-SIG Collaborative. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the JA-SIG Collaborative * (http://www.jasig.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */ package org.jasig.portal.channels; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.jasig.portal.ChannelCacheKey; import org.jasig.portal.ChannelRuntimeData; import org.jasig.portal.ChannelRuntimeProperties; import org.jasig.portal.ChannelStaticData; import org.jasig.portal.GeneralRenderingException; import org.jasig.portal.IMultithreadedCacheable; import org.jasig.portal.IMultithreadedChannel; import org.jasig.portal.PortalEvent; import org.jasig.portal.PortalException; import org.jasig.portal.ResourceMissingException; import org.jasig.portal.i18n.LocaleManager; import org.jasig.portal.security.LocalConnectionContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jasig.portal.utils.DTDResolver; import org.jasig.portal.utils.ResourceLoader; import org.jasig.portal.utils.XSLT; import org.w3c.dom.Document; import org.xml.sax.ContentHandler; import org.jasig.portal.utils.DocumentFactory; import org.w3c.dom.Element; import org.apache.xml.serialize.XMLSerializer; import java.io.PrintWriter; import java.io.FileOutputStream; /** *

A channel which transforms XML for rendering in the portal.

* *

Static channel parameters to be supplied: * * 1) "xmlUri" - a URI representing the source XML document * 2) "sslUri" - a URI representing the corresponding .ssl (stylesheet list) file * 3) "upc_localConnContext" - The class name of the ILocalConnectionContext * implementation. Use when local data needs to be sent with the request for the URL. *

*

This channel is intended to be used as one that can be selectively edited according to * permissions in order to display a customized message from select faculty/staff members.

* @author rtwigg@uccs.edu, adapted from CGenericXSLT.java * @version $Revision: 2.4.1 $ */ public class CDeptMsg implements IMultithreadedChannel, IMultithreadedCacheable { private static final Log log = LogFactory.getLog(CDeptMsg.class); Map stateTable; static final String systemCacheId="org.jasig.portal.channels.CDeptMsg"; // to prepend to the system-wide cache key boolean refresh; // state class private class CState { private String xmlUri; private String sslUri; private Map params; private long cacheTimeout; private ChannelRuntimeData runtimeData; private LocalConnectionContext localConnContext; private String action; public CState() { xmlUri = sslUri = action = null; params = new HashMap(); runtimeData = null; localConnContext = null; } public String toString() { StringBuffer str = new StringBuffer(); str.append("xmlUri = "+xmlUri+"\n"); str.append("sslUri = "+sslUri+"\n"); if (params != null) { str.append("params = "+params.toString()+"\n"); } return str.toString(); } } public CDeptMsg() { stateTable = Collections.synchronizedMap(new HashMap()); } public void setStaticData (ChannelStaticData sd, String uid) throws ResourceMissingException { CState state = new CState(); state.xmlUri = sd.getParameter("xmlUri"); state.sslUri = sd.getParameter("sslUri"); state.action="view"; refresh=false; String cacheTimeout = sd.getParameter("cacheTimeout"); String connContext = sd.getParameter ("upc_localConnContext"); if (connContext != null) { try { state.localConnContext = (LocalConnectionContext) Class.forName(connContext).newInstance(); state.localConnContext.init(sd); } catch (Exception e) { log.error( "CDeptMsg: Cannot initialize ILocalConnectionContext: " + e); } } stateTable.put(uid,state); } public void setRuntimeData (ChannelRuntimeData rd, String uid) throws PortalException { CState state = (CState)stateTable.get(uid); if (state == null) { log.error("CDeptMsg:setRuntimeData() : attempting to access a non-established channel! setStaticData() has never been called on the =uid=\""+uid+"\""); } else { state.runtimeData=rd; String submit = rd.getParameter("form_submit"); if (submit != null && submit.trim().equals("Save and Return")) { state.action = "view"; refresh=true; String xmlPath = null; try { if (state.localConnContext != null) xmlPath = ResourceLoader.getResourceAsFileString(this.getClass(), state.localConnContext.getDescriptor(state.xmlUri, rd)); else xmlPath = ResourceLoader.getResourceAsFileString(this.getClass(), state.xmlUri); } catch (Exception e) { throw new ResourceMissingException (state.xmlUri, "", e.getMessage()); } try { Document emptyDoc = DocumentFactory.getNewDocument(); Element messageE = emptyDoc.createElement("message"); Element fromNameE = emptyDoc.createElement("fromName"); String new_fromName = rd.getParameter("form_fromName"); if (new_fromName != null) { fromNameE.appendChild(emptyDoc.createTextNode(new_fromName)); } messageE.appendChild(fromNameE); Element headlineE = emptyDoc.createElement("headline"); String new_headline = rd.getParameter("form_headline"); if (new_headline != null) { headlineE.appendChild(emptyDoc.createTextNode(new_headline)); } messageE.appendChild(headlineE); Element bodyE = emptyDoc.createElement("body"); String new_body = rd.getParameter("form_body"); // create multiple paragraphs int i=0,start=0; for(;i