01: /* Copyright 2002 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.car;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.jasig.portal.tools.RegisterChannelType;
11: import org.xml.sax.Attributes;
12: import org.xml.sax.SAXException;
13: import org.xml.sax.helpers.DefaultHandler;
14:
15: /**
16: * Handles the channel-type tags in CAR deployment descriptors enabling
17: * adding of channel types from within CARs automatically.
18: *
19: * @author Mark Boyd {@link <a href="mailto:mark.boyd@engineer.com">mark.boyd@engineer.com</a>}
20: * @version $Revision: 36690 $
21: */
22: public class ChannelTypeTagHandler extends DefaultHandler {
23: // /////////////////// Content Handler Implementations //////////////////
24:
25: private static final Log log = LogFactory
26: .getLog(ChannelTypeTagHandler.class);
27: private String clazz = null;
28: private String name = null;
29: private String description = null;
30: private String uri = null;
31: private ParsingContext ctx = null;
32: private StringBuffer charBufr = new StringBuffer();
33:
34: /**
35: * @param ctx
36: */
37: public ChannelTypeTagHandler(ParsingContext ctx) {
38: this .ctx = ctx;
39: }
40:
41: /**
42: * Handle start element events.
43: */
44: public void startElement(String namespaceURI, String localName,
45: String qName, Attributes atts) throws SAXException {
46: // if starting a new channel type then clear out old values
47: if (qName.equals(DescriptorHandler.CHANTYPE_TAG_NAME)
48: && ctx.getPath().equals(DescriptorHandler.CHANTYPES)) {
49: this .clazz = null;
50: this .name = null;
51: this .description = null;
52: this .uri = null;
53: }
54: this .charBufr.delete(0, charBufr.length());
55: }
56:
57: /**
58: * Handle the characters event to capture textual content for elements.
59: */
60: public void characters(char[] ch, int start, int length)
61: throws SAXException {
62: charBufr.append(ch, start, length);
63: }
64:
65: /**
66: * Handle the closing element event.
67: */
68: public void endElement(String namespaceURI, String localName,
69: String qName) throws SAXException {
70: if (qName.equals("name"))
71: this .name = charBufr.toString();
72: else if (qName.equals("class"))
73: this .clazz = charBufr.toString();
74: else if (qName.equals("description"))
75: this .description = charBufr.toString();
76: else if (qName.equals("uri"))
77: this .uri = charBufr.toString();
78: else if (qName.equals(DescriptorHandler.CHANTYPE_TAG_NAME)
79: && ctx.getPath().equals(DescriptorHandler.CHANTYPES)) {
80: // leaving block so register the type
81: try {
82: RegisterChannelType.register(clazz, name, description,
83: uri);
84: } catch (Exception e) {
85: log.error(
86: "A problem occurred while registering a channel type. "
87: + e.getMessage(), e);
88: }
89: }
90: }
91: }
|