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;
007:
008: import java.util.Hashtable;
009:
010: import org.apache.commons.logging.Log;
011: import org.apache.commons.logging.LogFactory;
012: import org.jasig.portal.utils.SAX2BufferImpl;
013: import org.xml.sax.Attributes;
014: import org.xml.sax.ContentHandler;
015: import org.xml.sax.SAXException;
016: import org.xml.sax.XMLReader;
017:
018: /**
019: * Channel Rendering buffer allows portal to accumulate a list
020: * of all channels that will have to be rendered. This is done
021: * by accumulating layout content (full page content minus content
022: * provided by the channels).
023: * The entire document is accumulated in a buffer. Information about
024: * channel elements is passed to a ChannelManager. Once the end of the
025: * document is reached, the entire buffer is released to a provided
026: * Document Handler.
027: *
028: * @author Peter Kharchenko
029: * @version $Revision: 34807 $
030: */
031: public class ChannelRenderingBuffer extends SAX2BufferImpl {
032:
033: private static final Log log = LogFactory
034: .getLog(ChannelRenderingBuffer.class);
035:
036: protected ChannelManager cm;
037:
038: // information about the current channel
039: private boolean insideChannelElement = false;
040: private Hashtable params;
041: private String channelClassName;
042: private String channelSubscribeId;
043: private String channelPublishId;
044: private long timeOut;
045: boolean ccaching;
046:
047: /**
048: * Default constructor.
049: * @param chanman the channel manager
050: */
051: public ChannelRenderingBuffer(ChannelManager chanman) {
052: super ();
053: ccaching = false;
054: this .cm = chanman;
055: this .startBuffering();
056: this .setContentHandler(null);
057: }
058:
059: public ChannelRenderingBuffer(ContentHandler ch,
060: ChannelManager chanman) {
061: super (ch);
062: ccaching = false;
063: this .cm = chanman;
064: this .startBuffering();
065: this .setContentHandler(null);
066: }
067:
068: public ChannelRenderingBuffer(XMLReader parent,
069: ChannelManager chanman) {
070: super (parent);
071: ccaching = false;
072: this .cm = chanman;
073: this .startBuffering();
074: this .setContentHandler(null);
075: }
076:
077: public ChannelRenderingBuffer(ChannelManager chanman,
078: boolean ccaching) {
079: this (chanman);
080: this .setCharacterCaching(ccaching);
081: }
082:
083: public ChannelRenderingBuffer(ContentHandler ch,
084: ChannelManager chanman, boolean ccaching) {
085: this (ch, chanman);
086: this .setCharacterCaching(ccaching);
087: }
088:
089: public ChannelRenderingBuffer(XMLReader parent,
090: ChannelManager chanman, boolean ccaching) {
091: this (parent, chanman);
092: this .setCharacterCaching(ccaching);
093: }
094:
095: public void setCharacterCaching(boolean setting) {
096: this .ccaching = setting;
097: }
098:
099: public void startDocument() throws SAXException {
100: insideChannelElement = false;
101: super .startDocument();
102: }
103:
104: public void endDocument() throws SAXException {
105: cm.commitToRenderingChannelSet();
106: super .endDocument();
107: }
108:
109: public void startElement(String url, String localName,
110: String qName, Attributes atts) throws SAXException {
111: if (!insideChannelElement) {
112: // recognizing "channel"
113: if (qName.equals("channel")) {
114: insideChannelElement = true;
115:
116: // get class attribute
117: channelClassName = atts.getValue("class");
118: channelSubscribeId = atts.getValue("ID");
119: channelPublishId = atts.getValue("chanID");
120: timeOut = java.lang.Long.parseLong(atts
121: .getValue("timeout"));
122: params = new Hashtable();
123: }
124: } else if (qName.equals("parameter")) {
125: params.put(atts.getValue("name"), atts.getValue("value"));
126: }
127:
128: super .startElement(url, localName, qName, atts);
129: }
130:
131: public void endElement(String url, String localName, String qName)
132: throws SAXException {
133: if (insideChannelElement) {
134: if (qName.equals("channel")) {
135: try {
136: cm.startChannelRendering(channelSubscribeId);
137: } catch (PortalException pe) {
138: log
139: .error("ChannelRenderingBuffer::endElement() : unable to start rendering channel! (channelSubscribeId=\""
140: + channelSubscribeId + "\")");
141: }
142: insideChannelElement = false;
143: }
144: }
145: super.endElement(url, localName, qName);
146: }
147: }
|