001: /* Copyright 2005 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.properties;
007:
008: import java.util.Iterator;
009: import java.util.Map;
010: import java.util.Set;
011:
012: import javax.xml.parsers.DocumentBuilderFactory;
013:
014: import org.jasig.portal.ChannelStaticData;
015: import org.jasig.portal.PortalEvent;
016: import org.jasig.portal.channels.CAbstractXslt;
017: import org.w3c.dom.Document;
018: import org.w3c.dom.Element;
019:
020: /**
021: * An IChannel for viewing the missing properties.
022: * @version $Revision: 35695 $ $Date: 2005-04-30 13:08:13 -0700 (Sat, 30 Apr 2005) $
023: * @since uPortal 2.5
024: */
025: public class CMissingProperties extends CAbstractXslt {
026:
027: /**
028: * "xslUri" is the name of the ChannelStaticData attribute that we will read and,
029: * if set to a non-null value, we will use its value as our XSLT URI. If this
030: * ChannelStaticData attribute is not set, we will fall back on our default.
031: */
032: public static final String XSL_PARAM_KEY = "xslUri";
033:
034: /**
035: * By default, we use the XSLT 'MissingProperties.xsl' which will be found
036: * in the stylesheets subdirectory corresponding to the package of
037: * this CMissingProperties channel.
038: */
039: public static final String DEFAULT_XSL_URI = "MissingProperties.xsl";
040:
041: protected Document getXml() throws Exception {
042: /*
043: * Here we build a Document conveying the missing properties.
044: */
045:
046: Document doc = DocumentBuilderFactory.newInstance()
047: .newDocumentBuilder().newDocument();
048:
049: Element missingPropsElem = doc
050: .createElement("missingProperties");
051:
052: Set missingProperties = PropertiesManager
053: .getMissingProperties();
054:
055: for (Iterator iter = missingProperties.iterator(); iter
056: .hasNext();) {
057:
058: String missingProperty = (String) iter.next();
059: Element propertyElement = doc.createElement("property");
060: propertyElement.setTextContent(missingProperty);
061:
062: missingPropsElem.appendChild(propertyElement);
063: }
064:
065: doc.appendChild(missingPropsElem);
066:
067: return doc;
068: }
069:
070: /**
071: * This implementation reads and returns the ChannelStaticData attribute 'xsltUri';
072: * if that attribute is not set we return the default value 'MissingProperties.xsl'.
073: * @return the ChannelStaticData attribute 'xsltUri' or 'MissingProperties.xsl' if the attribute was null.
074: */
075: protected String getXsltUri() {
076:
077: try {
078: ChannelStaticData staticData = getStaticData();
079: String xsltUri = staticData.getParameter(XSL_PARAM_KEY);
080:
081: if (xsltUri != null) {
082: return xsltUri;
083: }
084:
085: // if xsltUri was null we will fall back on returning our default.
086:
087: } catch (RuntimeException rte) {
088: log
089: .error(
090: "Error checking ChannelStaticData attribute ["
091: + XSL_PARAM_KEY
092: + "] for alternate XSLT; falling back on default value: ["
093: + DEFAULT_XSL_URI + "]", rte);
094: }
095:
096: // return our default value
097: return DEFAULT_XSL_URI;
098: }
099:
100: /**
101: * This implementation returns null because we have no stylesheet parameters.
102: * @return null
103: */
104: protected Map getStylesheetParams() {
105: return null;
106: }
107:
108: public void receiveEvent(PortalEvent ev) {
109: // we ignore all events
110: }
111:
112: }
|