001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portlet.chart;
021:
022: import javax.portlet.PortletConfig;
023: import javax.portlet.PortletException;
024: import javax.portlet.UnavailableException;
025:
026: import org.jfree.data.AbstractDataset;
027:
028: import com.nabhinc.util.StringUtil;
029:
030: /**
031: *
032: *
033: * @author Wirawan Chokry
034: * (c) 2002, 2003 Nabh Information Systems, Inc. All Rights Reserved.
035: */
036: public abstract class BaseXMLDataset extends AbstractDataset implements
037: ChartDataSource {
038:
039: /**
040: * Parameter name for datasource URL. The <code>xmlDocURL</code> should
041: * begin with http:// or file:// (for local file).
042: * Either <code>xmlDocURL</code>, or <code>xmlDocAbsolutePath</code>, or
043: * <code>xmlDocRelativePath</code> is required.
044: */
045: public static final String XML_DOC_URL_INIT_PARAM = "xmlDocURL";
046:
047: /**
048: * Parameter name for datasource file. The <code>xmlDocAbsolutePath</code> is
049: * the absolute path to the XML file containing chart data.
050: * Either <code>xmlDocURL</code>, or <code>xmlDocAbsolutePath</code>, or
051: * <code>xmlDocRelativePath</code> is required.
052: */
053:
054: public static final String XML_DOC_ABSOLUTE_PATH_INIT_PARAM = "xmlDocAbsolutePath";
055:
056: /**
057: * Parameter name for datasource path. The <code>dataSourcePath</code> is
058: * the relative path of the datasource file to the context path.
059: * Either <code>xmlDocURL</code>, or <code>xmlDocAbsolutePath</code>, or
060: * <code>xmlDocRelativePath</code> is required.
061: */
062: public static final String XML_DOC_RELATIVE_PATH_INIT_PARAM = "xmlDocRelativePath";
063:
064: /**
065: * URL to retrieve XML file
066: */
067: protected String bxdsXMLURL = null;
068:
069: public abstract void executeQuery() throws PortletException;
070:
071: public abstract void createDummyData();
072:
073: public void retrieveChartData() throws PortletException {
074: if (bxdsXMLURL != null)
075: executeQuery();
076: else
077: createDummyData();
078: }
079:
080: /**
081: * Initializes XML data and populates the dataset.
082: * @param datasource The datasource, which should be <code>xml</code>.
083: * @param config The XML document path/URL.
084: */
085: public void init(PortletConfig config) throws PortletException {
086: bxdsXMLURL = config.getInitParameter(XML_DOC_URL_INIT_PARAM);
087: if (bxdsXMLURL == null) {
088: bxdsXMLURL = config
089: .getInitParameter(XML_DOC_ABSOLUTE_PATH_INIT_PARAM);
090:
091: if (bxdsXMLURL == null) {
092: bxdsXMLURL = config
093: .getInitParameter(XML_DOC_RELATIVE_PATH_INIT_PARAM);
094:
095: if (bxdsXMLURL == null) {
096: throw new UnavailableException(
097: "Missing required XML datasource document URL or Path.");
098: }
099: bxdsXMLURL = config.getPortletContext().getRealPath(
100: bxdsXMLURL);
101: }
102: }
103:
104: bxdsXMLURL = StringUtil.transformToURL(bxdsXMLURL, null);
105:
106: }
107:
108: }
|