01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal;
07:
08: import org.jasig.portal.utils.SAX2FilterImpl;
09: import org.xml.sax.Attributes;
10: import org.xml.sax.ContentHandler;
11: import org.xml.sax.SAXException;
12: import org.xml.sax.XMLReader;
13:
14: /**
15: * A filter that incorporates content rendered by the channels in to
16: * the main transformation stream.
17: *
18: * TODO: there are enhancements in CharacterCachingChannelIncorporationFilter as
19: * of uPortal 2.5.1 to support dynamic channel titles. Do those enhancements need
20: * to be copied here? Or is the functionality of this class duplicated by a
21: * degenerate (non-caching) configuration of CharacterCachingChannelIncorporationFilter,
22: * such that it would be a worthwhile reduction of code duplication to drop this
23: * class?
24: *
25: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
26: * @version $Revision: 36690 $
27: */
28: public class ChannelIncorporationFilter extends SAX2FilterImpl {
29:
30: // keep track if we are "in" the <channel> element
31: private boolean insideChannelElement = false;
32: ChannelManager cm;
33:
34: // information about the current channel
35: private String channelSubscribeId;
36:
37: // constructors
38:
39: // bare
40: public ChannelIncorporationFilter(ChannelManager chanm) {
41: this .cm = chanm;
42: }
43:
44: // upward chaining
45: public ChannelIncorporationFilter(XMLReader parent,
46: ChannelManager chanm) {
47: super (parent);
48: this .cm = chanm;
49: }
50:
51: // downward chaining
52: public ChannelIncorporationFilter(ContentHandler handler,
53: ChannelManager chanm) {
54: super (handler);
55: this .cm = chanm;
56: }
57:
58: public void startElement(String uri, String localName,
59: String qName, Attributes atts) throws SAXException {
60: if (!insideChannelElement) {
61: // recognizing "channel"
62: if (qName.equals("channel")) {
63: insideChannelElement = true;
64:
65: // get class attribute
66: channelSubscribeId = atts.getValue("ID");
67: } else {
68: super .startElement(uri, localName, qName, atts);
69: }
70: }
71: }
72:
73: public void endElement(String uri, String localName, String qName)
74: throws SAXException {
75: if (insideChannelElement) {
76: if (qName.equals("channel")) {
77: if (this .getContentHandler() != null) {
78: cm.outputChannel(channelSubscribeId, this
79: .getContentHandler());
80: insideChannelElement = false;
81: }
82: }
83: } else {
84: super.endElement(uri, localName, qName);
85: }
86: }
87: }
|