[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] [20949] improvement: Better support for Jasper report
From: |
Sigurd Nes |
Subject: |
[Phpgroupware-cvs] [20949] improvement: Better support for Jasper reports |
Date: |
Wed, 13 Jan 2010 19:00:21 +0000 |
Revision: 20949
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20949
Author: sigurdne
Date: 2010-01-13 19:00:20 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
improvement: Better support for Jasper reports
Added Paths:
-----------
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/CustomJasperReport.class
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperConfigParser.class
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperConnection.class
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperEngine.class
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperMacros.class
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/log4j.properties
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/ant-1.7.1.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/barcode4j-2.0.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/bcel-5.2.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-beanutils-1.8.0.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-collections-2.1.1.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-logging-1.0.4.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/groovy-all-1.5.5.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/hsqldb-1.8.0-10.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/iText-2.1.0.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jasperreports-3.6.1.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jcommon-1.0.15.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jfreechart-1.0.12.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/log4j-1.2.15.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/mondrian-3.1.1.12687.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/mysql-connector-java-5.1.10-bin.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/poi-3.2-FINAL-20081019.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/postgresql-8.4-701.jdbc4.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/rhino-1.7R1.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/spring-beans-2.5.5.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/spring-core-2.5.5.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/xalan-2.6.0.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/xercesImpl-2.7.0.jar
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/CustomJasperReport.java
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConfigParser.java
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConnection.java
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperEngine.java
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperMacros.java
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/compile.txt
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/CustomJasperReport.class
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/CustomJasperReport.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperConfigParser.class
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperConfigParser.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperConnection.class
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperConnection.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperEngine.class
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperEngine.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperMacros.class
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/JasperMacros.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/log4j.properties
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/log4j.properties
(rev 0)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/jasper/bin/log4j.properties
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1,5 @@
+log4j.rootLogger=OFF, A1
+
+log4j.appender.A1=org.apache.log4j.FileAppender
+log4j.appender.A1.File=debug.log
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/ant-1.7.1.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/ant-1.7.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/barcode4j-2.0.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/barcode4j-2.0.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/bcel-5.2.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/bcel-5.2.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-beanutils-1.8.0.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-beanutils-1.8.0.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-collections-2.1.1.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-collections-2.1.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-logging-1.0.4.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/commons-logging-1.0.4.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/groovy-all-1.5.5.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/groovy-all-1.5.5.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/hsqldb-1.8.0-10.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/hsqldb-1.8.0-10.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/iText-2.1.0.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/iText-2.1.0.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jasperreports-3.6.1.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jasperreports-3.6.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jcommon-1.0.15.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jcommon-1.0.15.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jfreechart-1.0.12.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/jfreechart-1.0.12.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/log4j-1.2.15.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/log4j-1.2.15.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/mondrian-3.1.1.12687.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/mondrian-3.1.1.12687.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/mysql-connector-java-5.1.10-bin.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/mysql-connector-java-5.1.10-bin.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/poi-3.2-FINAL-20081019.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/poi-3.2-FINAL-20081019.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/postgresql-8.4-701.jdbc4.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/postgresql-8.4-701.jdbc4.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/rhino-1.7R1.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/rhino-1.7R1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/spring-beans-2.5.5.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/spring-beans-2.5.5.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/spring-core-2.5.5.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/spring-core-2.5.5.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/xalan-2.6.0.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/xalan-2.6.0.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/xercesImpl-2.7.0.jar
===================================================================
(Binary files differ)
Property changes on:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/lib/xercesImpl-2.7.0.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/CustomJasperReport.java
===================================================================
---
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/CustomJasperReport.java
(rev 0)
+++
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/CustomJasperReport.java
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1,162 @@
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+
+
+import net.sf.jasperreports.engine.JREmptyDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JRExporterParameter;
+import net.sf.jasperreports.engine.JasperCompileManager;
+import net.sf.jasperreports.engine.JasperFillManager;
+import net.sf.jasperreports.engine.JasperPrint;
+import net.sf.jasperreports.engine.JasperReport;
+import net.sf.jasperreports.engine.export.JExcelApiExporter;
+import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
+import net.sf.jasperreports.engine.export.JRCsvExporter;
+import net.sf.jasperreports.engine.export.JRPdfExporter;
+import net.sf.jasperreports.engine.export.JRXlsExporter;
+import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter;
+
+class CustomJasperReport {
+
+ private String name;
+ private String source;
+
+ private JasperPrint jasperPrint;
+
+ public CustomJasperReport(String name, String source) {
+
+ this.name = name;
+ this.source = source;
+ this.jasperPrint = null;
+
+ }
+
+ public void generateReport(HashMap<String, String> parameters,
JasperConnection jc) {
+
+ JasperReport jasperReport = null;
+ // Map parameters = new HashMap();
+
+ try {
+ jasperReport =
JasperCompileManager.compileReport(this.source);
+ } catch (Exception e) {
+// System.err.println("Unable to compile template \"" +
this.source
+// + "\": " + e.getMessage());
+ System.exit(201);
+ }
+
+ Connection connection = jc.makeConnection();
+
+ try {
+
+ if (connection != null) {
+ this.jasperPrint =
JasperFillManager.fillReport(jasperReport,
+ parameters, connection);
+ } else {
+ this.jasperPrint =
JasperFillManager.fillReport(jasperReport,
+ null, new
JREmptyDataSource(50));
+ }
+
+ } catch (JRException e1) {
+// System.err.println("Unable to fill the report for
template \""
+// + this.source + "\": " +
e1.getMessage());
+ System.exit(202);
+ }
+
+ try {
+ if (connection != null) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ System.err.println("Unable to close connection");
+ e.printStackTrace();
+ }
+
+ }
+
+ public void generatePdf() {
+
+ if (this.jasperPrint == null){
+ System.exit(203);
+ }
+
+ JRPdfExporter pdfexp = new JRPdfExporter();
+ pdfexp.setParameter(JRExporterParameter.JASPER_PRINT,
this.jasperPrint);
+ pdfexp.setParameter(JRExporterParameter.OUTPUT_STREAM,
System.out);
+
+ try {
+ pdfexp.exportReport();
+ } catch (JRException e) {
+// System.err.println("Unable to generate PDF file for
report: "
+// + this.name);
+ System.exit(204);
+ }
+
+ }
+
+ public void generateCSV() {
+
+ if (this.jasperPrint == null) {
+ System.exit(203);
+ }
+
+ JRCsvExporter csvexp = new JRCsvExporter();
+ csvexp.setParameter(JRExporterParameter.JASPER_PRINT,
this.jasperPrint);
+ csvexp.setParameter(JRExporterParameter.OUTPUT_STREAM,
System.out);
+
+
+ try {
+ csvexp.exportReport();
+ } catch (JRException e) {
+// System.err.println("Unable to generate CSV file for
report: "
+// + this.name);
+ System.exit(205);
+ }
+
+ }
+
+ public void generateJRXls() {
+ if (this.jasperPrint == null) {
+ System.exit(203);
+ }
+
+ JRXlsExporter jrxls = new JRXlsExporter();
+
+ jrxls.setParameter(JRExporterParameter.JASPER_PRINT,
this.jasperPrint);
+ jrxls.setParameter(JRExporterParameter.OUTPUT_STREAM,
System.out);
+
jrxls.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
Boolean.TRUE);
+
+ try {
+ jrxls.exportReport();
+ } catch (JRException e) {
+// System.err.println("Unable to generate XLS file for
report: "
+// + this.name + ":" + e.getMessage());
+ System.exit(206);
+ }
+
+ }
+
+ public void generateJExcel() {
+ if (this.jasperPrint == null) {
+ System.exit(203);
+ }
+
+ JExcelApiExporter jexcel = new JExcelApiExporter();
+ jexcel.setParameter(JRExporterParameter.JASPER_PRINT,
this.jasperPrint);
+ jexcel.setParameter(JRExporterParameter.OUTPUT_STREAM,
System.out);
+
jexcel.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET,
Boolean.TRUE);
+
+ try{
+ jexcel.exportReport();
+ } catch (JRException e) {
+// System.err.println("Unable to generate Excel XLS file
for report: "
+// + this.name + ":" + e.getMessage());
+ System.exit(206);
+ }
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+}
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConfigParser.java
===================================================================
---
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConfigParser.java
(rev 0)
+++
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConfigParser.java
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1,48 @@
+import java.util.HashMap;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+
+class JasperConfigParser extends DefaultHandler {
+
+ private HashMap<String, CustomJasperReport> reportsHash = null;
+ private HashMap<String, String> parametersHash = null;
+
+ public JasperConfigParser() {
+
+ this.reportsHash = new HashMap<String, CustomJasperReport>();
+ this.parametersHash = new HashMap<String, String>();
+
+ }
+
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) {
+
+ if (localName.equals("Report")) {
+ // the Connections section
+ // should *always* come
+ // before the Reports
+ // section.
+
+ this.reportsHash.put(attributes.getValue("name"),
+ new
CustomJasperReport(attributes.getValue("name"),
+
attributes.getValue("source")));
+
+ } else if (localName.equals("StaticData")) {
+
+ this.parametersHash.put(attributes.getValue("key"),
attributes
+ .getValue("value"));
+
+ }
+
+ }
+
+ public HashMap<String, CustomJasperReport> getReportsHash() {
+ return this.reportsHash;
+ }
+
+ public HashMap<String, String> getParametersHash() {
+ return this.parametersHash;
+ }
+
+}
Added:
people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConnection.java
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConnection.java
(rev 0)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperConnection.java
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1,99 @@
+import java.sql.DriverManager;
+
+//import java.sql.SQLException;
+//import com.mysql.jdbc.Connection;
+
+class JasperConnection {
+
+ private String connection_string;
+ private String username;
+ private String password;
+ private int db_type;
+
+ private final static int DUMMYCONNECTION = 0;
+ private final static int MYSQLCONNECTION = 1;
+ private final static int POSTGRESQLCONNECTION = 2;
+
+ // the real connection object
+ private java.sql.Connection connection;
+
+ public JasperConnection(String connection_string, String username,
String password) {
+
+ this.connection_string = connection_string;
+ this.username = username;
+ this.password = password;
+
+ // use this ugly hack to determine DB type
+ if (this.connection_string.startsWith("jdbc:mysql:")) {
+ this.db_type = JasperConnection.MYSQLCONNECTION;
+ } else if
(this.connection_string.startsWith("jdbc:postgresql:")) {
+ this.db_type = JasperConnection.POSTGRESQLCONNECTION;
+ } else {
+ this.db_type = JasperConnection.DUMMYCONNECTION;
+ }
+
+ }
+
+
+ public java.sql.Connection makeConnection() {
+
+ if (this.db_type == MYSQLCONNECTION) {
+
+ try {
+
Class.forName("com.mysql.jdbc.Driver").newInstance();
+ } catch (Exception ex) {
+
+// System.err.println("Unable to load MySQL
driver: "
+// + ex.getMessage());
+ System.exit(209);
+
+ }
+
+
+ try {
+ connection =
DriverManager.getConnection(this.connection_string,
+ this.username, this.password);
+ } catch (Exception ex) {
+
+// System.err.printf("Unable to connect to MySQL
database (%s): %s",
+// connection_url,
ex.getMessage());
+ System.exit(211);
+
+ }
+
+ } else if (this.db_type == POSTGRESQLCONNECTION) { // postgresql
+
+ try {
+
Class.forName("org.postgresql.Driver").newInstance();
+ } catch (Exception ex) {
+
+// System.err.println("Unable to load PostgreSQL
driver: "
+// + ex.getMessage());
+ System.exit(210);
+
+ }
+
+ try {
+ connection =
DriverManager.getConnection(this.connection_string,
+ this.username, this.password);
+ } catch (Exception ex) {
+
+// System.err.println("Unable to connect to
PostgreSQL database(" + this.dbname + "): "
+// + ex.getMessage());
+ System.exit(211);
+
+ }
+
+ } else { // dummy ( no connection )
+ // some reports may be created with this kind of
connection
+ return null;
+
+ }
+
+ return connection;
+
+ }
+
+
+
+}
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperEngine.java
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperEngine.java
(rev 0)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperEngine.java
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1,141 @@
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+class JasperEngine {
+
+ public static void main(String[] args) throws IOException {
+
+ File file = new File(args[args.length - 1]);
+ InputSource source = null;
+
+ try {
+ source = new InputSource(new FileInputStream(file));
+ } catch (Exception ex) {
+ //System.err.println("Missing configuration file");
+ System.exit(214);
+ }
+
+ HashMap<String, CustomJasperReport> reports;
+ HashMap<String, String> parameters = null;
+
+ JasperConfigParser jcp = new JasperConfigParser();
+
+ JasperMacros jm = new JasperMacros();
+
+ int output_type = 0; // 0 - PDF (default), 1 = CSV, 2 - XLS
+ String report_name = null;
+ String connection_string = null;
+ String db_username = null;
+ String db_password = null;
+
+ for (int i = 0; i < args.length; ++i) {
+
+ if (args[i].equals("-h")) {
+ printHelp();
+ System.exit(0);
+ } else if (args[i].equals("-n")) {
+ report_name = args[i + 1];
+ } else if (args[i].equals("-p")) {
+ jm.loadMacros(args[i + 1]);
+ } else if (args[i].equals("-t")) {
+ if (args[i + 1].equals("CSV")) {
+ output_type = 1;
+ } else if (args[i + 1].equals("XLS")) {
+ output_type = 2;
+ } else if (!args[i + 1].equals("PDF")) {
+ // System.err.printf("Unknown type:
%s\n", args[i + 1]);
+ // printHelp();
+ System.exit(208);
+ }
+ } else if (args[i].equals("-d")) {
+ connection_string = args[i + 1];
+ } else if (args[i].equals("-u")) {
+ db_username = args[i + 1];
+ } else if (args[i].equals("-P")) {
+ db_password = args[i + 1];
+ }
+ }
+
+ if (report_name == null) {
+ //System.err.println("Missing report-name");
+ System.exit(212);
+ }
+
+ if (connection_string == null) {
+ //System.err.println("Missing connection string");
+ System.exit(215);
+ }
+
+ if (db_username == null) {
+ System.exit(216);
+ }
+
+ if (db_password == null) {
+ System.exit(217);
+ }
+
+ parameters = jm.getMacros();
+
+ try {
+ XMLReader reader = XMLReaderFactory
+
.createXMLReader("org.apache.xerces.parsers.SAXParser");
+ reader.setContentHandler(jcp);
+ reader.parse(source);
+ } catch (Exception ex) {
+ // System.err.println("Unable to parse configuration: "
+ // + ex.getMessage());
+ System.exit(207);
+ }
+
+ reports = jcp.getReportsHash();
+ parameters.putAll(jcp.getParametersHash()); // get the rest of
the
+ // parameters from the config file
+
+ // go through all reports
+ CustomJasperReport report = reports.get(report_name);
+
+ if (report == null) {
+ //System.err.println("Invalid report-name");
+ System.exit(213);
+ }
+
+ JasperConnection jc = new JasperConnection(connection_string,
db_username, db_password);
+
+ // System.out.println(report.getName());
+ report.generateReport(parameters, jc);
+
+ switch (output_type) {
+
+ case 0:
+ report.generatePdf();
+ break;
+
+ case 1:
+ report.generateCSV();
+ break;
+
+ case 2:
+ report.generateJRXls();
+ // report.generateJExcel();
+ break;
+
+ }
+
+ System.exit(0);
+
+ }
+
+ private static void printHelp() {
+ System.out
+ .println("USAGE: JasperEngine [-p
<parameter1|value1;parameter2|value2;..parameterX|valueX] [-t <type>] [-h] <-n
<report name>> < -d <connection_string>> < -u <db_username> > < -P
<db_password> > < <config>\n");
+ System.out
+ .println("-t <type> - The type of output,
where type may be: PDF, CSV, XLS");
+ }
+
+}
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperMacros.java
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperMacros.java
(rev 0)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/JasperMacros.java
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1,31 @@
+import java.util.HashMap;
+import java.util.StringTokenizer;
+
+// This class contains static method(s) for generating JasperMacros in
real-time.
+class JasperMacros {
+
+ private HashMap<String, String> macros;
+
+ public JasperMacros() {
+ this.macros = new HashMap<String, String>();
+ }
+
+ public HashMap<String, String> getMacros() {
+ return this.macros;
+ }
+
+ // 'parameters' will be in the following format:
+ // 'key1|value1;key2|value2;key3|value3' where key1, key2 ... keyX are
+ // unique
+ public void loadMacros(String parameters) {
+ StringTokenizer st = new StringTokenizer(parameters, ";");
+ while (st.hasMoreTokens()) {
+
+ String[] parameter_value = st.nextToken().split("\\|");
+ this.macros.put(parameter_value[0],
parameter_value[1].trim());
+
+ }
+
+ }
+
+}
Added: people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/compile.txt
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/compile.txt
(rev 0)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/jasper/src/compile.txt
2010-01-13 19:00:20 UTC (rev 20949)
@@ -0,0 +1 @@
+javac -classpath "$(printf ':%s' ../lib/*.jar | cut -b2-)" *.java
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] [20949] improvement: Better support for Jasper reports,
Sigurd Nes <=