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 java.util.Enumeration;
09:
10: import org.jasig.portal.utils.SAX2FilterImpl;
11: import org.xml.sax.Attributes;
12: import org.xml.sax.ContentHandler;
13: import org.xml.sax.SAXException;
14: import org.xml.sax.XMLReader;
15: import org.xml.sax.helpers.AttributesImpl;
16:
17: /**
18: * Filter incorporating channel and folder attributes for the structure transformation
19: * @author Peter Kharchenko
20: * @version $Revision: 34820 $
21: */
22:
23: public class StructureAttributesIncorporationFilter extends
24: SAX2FilterImpl {
25: protected StructureStylesheetUserPreferences fsup;
26:
27: // downward
28: public StructureAttributesIncorporationFilter(
29: ContentHandler handler,
30: StructureStylesheetUserPreferences prefs) {
31: super (handler);
32: this .fsup = prefs;
33: }
34:
35: // upward
36: public StructureAttributesIncorporationFilter(XMLReader parent,
37: StructureStylesheetUserPreferences prefs) {
38: super (parent);
39: this .fsup = prefs;
40: }
41:
42: public void startElement(String uri, String localName,
43: String qName, Attributes atts) throws SAXException {
44: // recognizing "channel"
45: if (qName.equals("channel")) {
46: AttributesImpl attsImpl = new AttributesImpl(atts);
47: String channelSubscribeId = attsImpl.getValue("ID");
48: for (Enumeration ca = fsup.getChannelAttributeNames(); ca
49: .hasMoreElements();) {
50: String attrName = (String) ca.nextElement();
51: attsImpl.addAttribute("", attrName, attrName, "CDATA",
52: fsup.getChannelAttributeValue(
53: channelSubscribeId, attrName));
54: // log.debug("adding attribute to channel="+channelID+" "+attrName+"="+fsup.getChannelAttributeValue(channelID,attrName));
55: }
56: super .startElement(uri, localName, qName, attsImpl);
57: } else if (qName.equals("folder")) {
58: AttributesImpl attsImpl = new AttributesImpl(atts);
59: String folderID = attsImpl.getValue("ID");
60: for (Enumeration fe = fsup.getFolderAttributeNames(); fe
61: .hasMoreElements();) {
62: String attrName = (String) fe.nextElement();
63: attsImpl.addAttribute("", attrName, attrName, "CDATA",
64: fsup
65: .getFolderAttributeValue(folderID,
66: attrName));
67: // log.debug("adding attribute to folder="+folderID+" "+attrName+"="+fsup.getFolderAttributeValue(folderID,attrName));
68: }
69: super.startElement(uri, localName, qName, attsImpl);
70: } else
71: super.startElement(uri, localName, qName, atts);
72: }
73: }
|