001: /* Copyright 2001, 2005 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;
007:
008: import javax.xml.parsers.DocumentBuilderFactory;
009: import javax.xml.parsers.ParserConfigurationException;
010:
011: import org.jasig.portal.ChannelCacheKey;
012: import org.jasig.portal.GeneralRenderingException;
013: import org.jasig.portal.ICacheable;
014: import org.jasig.portal.PortalException;
015: import org.jasig.portal.i18n.LocaleManager;
016: import org.jasig.portal.utils.ResourceLoader;
017: import org.jasig.portal.utils.XSLT;
018: import org.w3c.dom.Document;
019: import org.w3c.dom.Element;
020: import org.xml.sax.ContentHandler;
021:
022: /**
023: * This channel renders content identified by a URL within an inline browser
024: * frame. For Browsers without support for IFRAMEs, the channel
025: * just presents a link to open the URL in a separate window. See
026: * <a href="http://www.htmlhelp.com/reference/html40/special/iframe.html">
027: * http://www.htmlhelp.com/reference/html40/special/iframe.html</a> for more
028: * information on inline frames.
029: *
030: * @author Susan Bramhall
031: * @version $Revision: 36690 $
032: */
033: public class CInlineFrame extends BaseChannel implements ICacheable {
034:
035: private static final String sslLocation = "CInlineFrame/CInlineFrame.ssl";
036:
037: /**
038: * Build an XML document and transform for display using org.jasig.portal.util.XSLT
039: * Creates IFrame or link depending on browser capability.
040: * The XML will look something like this:
041: *
042: * <pre>
043: * <iframe>
044: * <url>http://blah.blah.blah</url>
045: * <height>600</height>
046: * </iframe>
047: * </pre>
048: */
049: public void renderXML(ContentHandler out) throws PortalException {
050:
051: // Obtain url and height, both static parameters
052: String srcUrl = staticData.getParameter("url"); // the url for the IFrame content
053: String frameHeight = staticData.getParameter("height"); // the height of the IFrame in pixels
054:
055: Document doc = null;
056: try {
057: doc = DocumentBuilderFactory.newInstance()
058: .newDocumentBuilder().newDocument();
059: } catch (ParserConfigurationException pce) {
060: log.error("Error getting Document", pce);
061: throw new GeneralRenderingException(pce);
062: }
063:
064: // Create XML doc
065: Element iframeE = doc.createElement("iframe");
066: Element urlE = doc.createElement("url");
067: urlE.appendChild(doc.createTextNode(srcUrl));
068: iframeE.appendChild(urlE);
069: Element heightE = doc.createElement("height");
070: heightE.appendChild(doc.createTextNode(frameHeight));
071: iframeE.appendChild(heightE);
072: doc.appendChild(iframeE);
073:
074: XSLT xslt = XSLT.getTransformer(this , runtimeData.getLocales());
075: xslt.setXML(doc);
076: xslt.setXSL(sslLocation, runtimeData.getBrowserInfo());
077: xslt.setTarget(out);
078: xslt.transform();
079: }
080:
081: // IMultithreadedCachable methods...
082:
083: public ChannelCacheKey generateKey() {
084: ChannelCacheKey key = new ChannelCacheKey();
085: key.setKey(getKey());
086: key.setKeyScope(ChannelCacheKey.SYSTEM_KEY_SCOPE);
087: key.setKeyValidity(null);
088: return key;
089: }
090:
091: public boolean isCacheValid(Object validity) {
092: return true;
093: }
094:
095: private String getKey() {
096: StringBuffer sbKey = new StringBuffer(1024);
097: sbKey.append("org.jasig.portal.channels.CInlineFrame").append(
098: ": ");
099: sbKey.append("xslUri:");
100: try {
101: String sslUrl = ResourceLoader.getResourceAsURLString(this
102: .getClass(), sslLocation);
103: sbKey.append(
104: XSLT.getStylesheetURI(sslUrl, runtimeData
105: .getBrowserInfo())).append(", ");
106: } catch (PortalException pe) {
107: sbKey.append("Not available, ");
108: }
109: sbKey.append("staticData:").append(staticData.toString());
110: sbKey.append("locales:").append(
111: LocaleManager.stringValueOf(runtimeData.getLocales()));
112: return sbKey.toString();
113: }
114: }
|