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;
007:
008: import org.jasig.portal.ChannelCacheKey;
009: import org.jasig.portal.ICacheable;
010: import org.jasig.portal.IChannel;
011: import org.jasig.portal.IPrivilegedChannel;
012: import org.jasig.portal.PortalControlStructures;
013: import org.jasig.portal.PortalEvent;
014: import org.jasig.portal.i18n.LocaleManager;
015: import org.jasig.portal.utils.DocumentFactory;
016: import org.jasig.portal.utils.XSLT;
017: import org.w3c.dom.Document;
018: import org.w3c.dom.Element;
019: import org.xml.sax.ContentHandler;
020:
021: import org.apache.xml.serialize.OutputFormat;
022: import org.apache.xml.serialize.XMLSerializer;
023:
024: /**
025: * CSecureInfo is designed to replace channel instances that are required
026: * to be rendered securely, yet the request does not warrant it.
027: * <p>
028: * CSecureInfo provides information in place of the actual channel content
029: * as it relates to rendering channels that are tagged as secure.
030: * <p>
031: * The channel is modeled after CError and borrows code from it liberally.
032: *
033: * @author Keith Stacks, kstacks@sct.com
034: * @version $Revision: 36729 $
035: */
036: public class CSecureInfo extends BaseChannel implements
037: IPrivilegedChannel, ICacheable {
038:
039: protected String str_channelSubscribeId = null;
040: protected IChannel the_channel = null;
041:
042: private static final String ssTitle = "info";
043: private static final String sslLocation = "CSecureInfo/CSecureInfo.ssl";
044:
045: private PortalControlStructures portcs;
046:
047: public CSecureInfo() {
048: }
049:
050: public CSecureInfo(String channelSubscribeId,
051: IChannel channelInstance) {
052: this ();
053: this .str_channelSubscribeId = channelSubscribeId;
054: this .the_channel = channelInstance;
055: }
056:
057: public void setPortalControlStructures(PortalControlStructures pcs) {
058: this .portcs = pcs;
059: }
060:
061: public void receiveEvent(PortalEvent ev) {
062: if (the_channel != null) {
063: // propagate the portal events to the normal channel
064: the_channel.receiveEvent(ev);
065: }
066: super .receiveEvent(ev);
067: }
068:
069: public void renderXML(ContentHandler out) {
070: // XML of the following type is generated:
071: // <secure>
072: // <channel>
073: // <id>$channelID</id>
074: // <name>$channelName</name>
075: // </channel>
076: // </secure>
077: //
078: Document doc = DocumentFactory.getNewDocument();
079: Element secureEl = doc.createElement("secure");
080: if (str_channelSubscribeId != null) {
081: Element channelEl = doc.createElement("channel");
082: Element idEl = doc.createElement("id");
083: idEl
084: .appendChild(doc
085: .createTextNode(str_channelSubscribeId));
086: channelEl.appendChild(idEl);
087:
088: // determine channel name
089: if (portcs != null) {
090: String chName = null;
091: try {
092: chName = portcs.getUserPreferencesManager()
093: .getUserLayoutManager().getNode(
094: str_channelSubscribeId).getName();
095: } catch (Exception e) {
096: chName = "undetermined name";
097: }
098: if (chName != null) {
099: Element nameEl = doc.createElement("name");
100: nameEl.appendChild(doc.createTextNode(chName));
101: channelEl.appendChild(nameEl);
102: }
103: secureEl.appendChild(channelEl);
104: }
105: }
106:
107: doc.appendChild(secureEl);
108:
109: // debug block
110: if (log.isDebugEnabled()) {
111: try {
112: java.io.StringWriter outString = new java.io.StringWriter();
113: /* This should be reviewed at some point to see if we can use the
114: * DOM3 LS capability and hence a standard way of doing this rather
115: * than using an internal implementation class.
116: */
117: OutputFormat format = new OutputFormat();
118: format.setOmitXMLDeclaration(true);
119: format.setIndenting(true);
120: XMLSerializer xsl = new XMLSerializer(outString, format);
121: xsl.serialize(doc);
122: log.debug(outString.toString());
123: } catch (Exception e) {
124: log.debug(e, e);
125: }
126: }
127: // end of debug block
128:
129: try {
130: XSLT xslt = XSLT.getTransformer(this , runtimeData
131: .getLocales());
132: xslt.setXML(doc);
133: xslt.setXSL(sslLocation, ssTitle, runtimeData
134: .getBrowserInfo());
135: xslt.setTarget(out);
136: xslt.setStylesheetParameter("baseActionURL", runtimeData
137: .getBaseActionURL());
138: xslt.transform();
139: } catch (Exception e) {
140: log
141: .error(
142: "CSecureInfo::renderXML() : Error transforming document",
143: e);
144: }
145: }
146:
147: public ChannelCacheKey generateKey() {
148: ChannelCacheKey k = new ChannelCacheKey();
149: StringBuffer sbKey = new StringBuffer(1024);
150:
151: // assume that security information can be cached system-wide
152: k.setKeyScope(ChannelCacheKey.SYSTEM_KEY_SCOPE);
153:
154: sbKey
155: .append("org.jasig.portal.channels.CSecureInfo: channelID=");
156: sbKey.append(str_channelSubscribeId);
157: sbKey.append("locales:").append(
158: LocaleManager.stringValueOf(runtimeData.getLocales()));
159:
160: k.setKey(sbKey.toString());
161: return k;
162: }
163:
164: public boolean isCacheValid(Object validity) {
165: return true;
166: }
167: }
|