001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * DataSourceReferenceGenerator.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.misc.referencedoc;
030:
031: import java.net.URL;
032: import javax.swing.table.TableModel;
033:
034: import org.jfree.report.JFreeReport;
035: import org.jfree.report.JFreeReportBoot;
036: import org.jfree.report.TableDataFactory;
037: import org.jfree.report.modules.output.pageable.pdf.PdfReportUtil;
038: import org.jfree.report.modules.output.table.html.HtmlReportUtil;
039: import org.jfree.report.modules.parser.base.ReportGenerator;
040: import org.jfree.report.modules.parser.ext.factory.datasource.DataSourceCollector;
041: import org.jfree.report.modules.parser.ext.factory.datasource.DefaultDataSourceFactory;
042: import org.jfree.util.ObjectUtilities;
043:
044: /**
045: * An application that generates a report that provides style key reference information.
046: *
047: * @author Thomas Morgner.
048: */
049: public final class DataSourceReferenceGenerator {
050: /**
051: * The report definition file.
052: */
053: private static final String REFERENCE_REPORT = "DataSourceReferenceReport.xml"; //$NON-NLS-1$
054:
055: /**
056: * DefaultConstructor.
057: */
058: private DataSourceReferenceGenerator() {
059: }
060:
061: /**
062: * Returns the DataSourceReferenceTableModel.
063: *
064: * @return the tablemodel for the reference documentation.
065: */
066: public static TableModel createData() {
067: final DataSourceCollector cc = new DataSourceCollector();
068: cc.addFactory(new DefaultDataSourceFactory());
069:
070: return new DataSourceReferenceTableModel(cc);
071: }
072:
073: /**
074: * The starting point for the application.
075: *
076: * @param args ignored.
077: */
078: public static void main(final String[] args) {
079: JFreeReportBoot.getInstance().start();
080: final ReportGenerator gen = ReportGenerator.getInstance();
081: final URL reportURL = ObjectUtilities.getResourceRelative(
082: REFERENCE_REPORT, DataSourceReferenceGenerator.class);
083: if (reportURL == null) {
084: System.err
085: .println("The report was not found in the classpath"); //$NON-NLS-1$
086: System.err.println("File: " + REFERENCE_REPORT); //$NON-NLS-1$
087: System.exit(1);
088: return;
089: }
090:
091: final JFreeReport report;
092: try {
093: report = gen.parseReport(reportURL);
094: } catch (Exception e) {
095: System.err.println("The report could not be parsed."); //$NON-NLS-1$
096: System.err.println("File: " + REFERENCE_REPORT); //$NON-NLS-1$
097: e.printStackTrace(System.err);
098: System.exit(1);
099: return;
100: }
101: report.setDataFactory(new TableDataFactory(
102: "default", createData())); //$NON-NLS-1$
103: try {
104: HtmlReportUtil.createStreamHTML(report, System
105: .getProperty("user.home") //$NON-NLS-1$
106: + "/datasource-reference.html"); //$NON-NLS-1$
107: PdfReportUtil.createPDF(report, System
108: .getProperty("user.home") //$NON-NLS-1$
109: + "/datasource-reference.pdf"); //$NON-NLS-1$
110: } catch (Exception e) {
111: System.err.println("The report processing failed."); //$NON-NLS-1$
112: System.err.println("File: " + REFERENCE_REPORT); //$NON-NLS-1$
113: e.printStackTrace(System.err);
114: System.exit(1);
115: }
116: }
117:
118: }
|