diff --git a/3680.pdf b/3680.pdf new file mode 100644 index 0000000..269e2f7 Binary files /dev/null and b/3680.pdf differ diff --git a/3681.pdf b/3681.pdf new file mode 100644 index 0000000..4a6d6b0 Binary files /dev/null and b/3681.pdf differ diff --git a/9781590599273.jpg b/9781590599273.jpg new file mode 100644 index 0000000..2d1408a Binary files /dev/null and b/9781590599273.jpg differ diff --git a/Chapter02/demo/samples/antcompile/build.xml b/Chapter02/demo/samples/antcompile/build.xml new file mode 100644 index 0000000..e98d05c --- /dev/null +++ b/Chapter02/demo/samples/antcompile/build.xml @@ -0,0 +1,59 @@ + + + Shows how multiple JRXML files can be compiled in batch mode using ANT. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter02/demo/samples/antcompile/readme.txt b/Chapter02/demo/samples/antcompile/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter02/demo/samples/antcompile/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter02/demo/samples/antcompile/reports/com/bar/BarReport.jrxml b/Chapter02/demo/samples/antcompile/reports/com/bar/BarReport.jrxml new file mode 100644 index 0000000..99d2463 --- /dev/null +++ b/Chapter02/demo/samples/antcompile/reports/com/bar/BarReport.jrxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + + + +
  +
+ + + + +<% + if (pageIndex > 0) + { +%> + + +<% + } + else + { +%> + + +<% + } + + if (pageIndex < lastPageIndex) + { +%> + + +<% + } + else + { +%> + + +<% + } +%> + + +
    
+
+
 
  + +<%=sbuffer.toString()%> + +  
+ + diff --git a/Chapter04/demo/samples/webapp/printer.html b/Chapter04/demo/samples/webapp/printer.html new file mode 100644 index 0000000..e462d58 --- /dev/null +++ b/Chapter04/demo/samples/webapp/printer.html @@ -0,0 +1,62 @@ + + + +JasperReports - Web Application Sample + + + + + +Printer Applet +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Note: Because the preceding applet uses the Swing 1.1 API, it requires Java Plug-in 1.1.2 or Java Plug-in 1.2. It won't work with Java Plug-in 1.1.1 or uncustomized 1.1 browsers. For more information about running applets see the Java Tutorial. +
+ + + diff --git a/Chapter04/demo/samples/webapp/readme.txt b/Chapter04/demo/samples/webapp/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter04/demo/samples/webapp/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter04/demo/samples/webapp/reports/WebappReport.jrxml b/Chapter04/demo/samples/webapp/reports/WebappReport.jrxml new file mode 100644 index 0000000..fd0323f --- /dev/null +++ b/Chapter04/demo/samples/webapp/reports/WebappReport.jrxml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + +
  +
+ + + + +<% + if (pageIndex > 0) + { +%> + + +<% + } + else + { +%> + + +<% + } + + if (pageIndex < lastPageIndex) + { +%> + + +<% + } + else + { +%> + + +<% + } +%> + + +
    
+
+
 
  + +<%=sbuffer.toString()%> + +  
+ + diff --git a/Chapter06/demo/samples/webapp/printer.html b/Chapter06/demo/samples/webapp/printer.html new file mode 100644 index 0000000..e462d58 --- /dev/null +++ b/Chapter06/demo/samples/webapp/printer.html @@ -0,0 +1,62 @@ + + + +JasperReports - Web Application Sample + + + + + +Printer Applet +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Note: Because the preceding applet uses the Swing 1.1 API, it requires Java Plug-in 1.1.2 or Java Plug-in 1.2. It won't work with Java Plug-in 1.1.1 or uncustomized 1.1 browsers. For more information about running applets see the Java Tutorial. +
+ + + diff --git a/Chapter06/demo/samples/webapp/readme.txt b/Chapter06/demo/samples/webapp/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter06/demo/samples/webapp/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter06/demo/samples/webapp/reports/WebappReport.jrxml b/Chapter06/demo/samples/webapp/reports/WebappReport.jrxml new file mode 100644 index 0000000..fd0323f --- /dev/null +++ b/Chapter06/demo/samples/webapp/reports/WebappReport.jrxml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5)]]> + + + + + + + + + + + <band height="100"> + <elementGroup> + <line> + <reportElement x="0" y="0" width="555" height="1"/> + <graphicElement/> + </line> + <image scaleImage="Clip"> + <reportElement x="0" y="5" width="165" height="40"/> + <graphicElement/> + <imageExpression class="java.lang.String"><![CDATA["jasperreports.gif"]]></imageExpression> + </image> + </elementGroup> + <textField isBlankWhenNull="true"> + <reportElement x="180" y="5" width="375" height="35" style="Comic_Bold"/> + <textElement textAlignment="Right"> + <font size="22"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="180" y="40" width="375" height="15" style="Arial_Italic"/> + <textElement textAlignment="Right"> + <font size="12"/> + </textElement> + <text><![CDATA[(c)2001-2006 by teodord]]></text> + </staticText> + <textField evaluationTime="Report"> + <reportElement x="255" y="55" width="100" height="40"/> + <textElement textAlignment="Justified"/> + <textFieldExpression class="java.lang.String"><![CDATA["There are " + String.valueOf($V{REPORT_COUNT}) + " orders on this report, with a total freight of " + new DecimalFormat("0.00").format($V{FreightSumReport}.doubleValue())]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter08/demo/samples/jasper/JasperApp.java b/Chapter08/demo/samples/jasper/JasperApp.java new file mode 100644 index 0000000..eb3f9cf --- /dev/null +++ b/Chapter08/demo/samples/jasper/JasperApp.java @@ -0,0 +1,328 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.Panel; +import java.awt.Toolkit; +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: JasperApp.java 1644 2007-03-20 09:57:51Z teodord $ + */ +public class JasperApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + private static final String TASK_RUN = "run"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_FILL.equals(taskName)) + { + //Preparing parameters + Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg"); + MediaTracker traker = new MediaTracker(new Panel()); + traker.addImage(image, 0); + try + { + traker.waitForID(0); + } + catch (Exception e) + { + e.printStackTrace(); + } + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "The First Jasper Report Ever"); + parameters.put("MaxOrderID", new Integer(10500)); + parameters.put("SummaryImage", image); + + JasperFillManager.fillReportToFile(fileName, parameters, getConnection()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + JasperExportManager.exportReportToHtmlFile(fileName); + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + File sourceFile = new File(fileName); + Map dateFormats = new HashMap(); + dateFormats.put("EEE, MMM d, yyyy", "ddd, mmm d, yyyy"); + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); + exporter.setParameter(JRXlsExporterParameter.FORMAT_PATTERNS_MAP, dateFormats); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RUN.equals(taskName)) + { + //Preparing parameters + Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg"); + MediaTracker traker = new MediaTracker(new Panel()); + traker.addImage(image, 0); + try + { + traker.waitForID(0); + } + catch (Exception e) + { + e.printStackTrace(); + } + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "The First Jasper Report Ever"); + parameters.put("MaxOrderID", new Integer(10500)); + parameters.put("SummaryImage", image); + + JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection()); + System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "JasperApp usage:" ); + System.out.println( "\tjava JasperApp -Ttask -Ffile" ); + System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" ); + } + + + /** + * + */ + private static Connection getConnection() throws ClassNotFoundException, SQLException + { + //Change these settings according to your local configuration + String driver = "org.hsqldb.jdbcDriver"; + String connectString = "jdbc:hsqldb:hsql://localhost"; + String user = "sa"; + String password = ""; + + + Class.forName(driver); + Connection conn = DriverManager.getConnection(connectString, user, password); + return conn; + } + + +} diff --git a/Chapter08/demo/samples/jasper/build.xml b/Chapter08/demo/samples/jasper/build.xml new file mode 100644 index 0000000..1805925 --- /dev/null +++ b/Chapter08/demo/samples/jasper/build.xml @@ -0,0 +1,183 @@ + + + Shows how different feautures of the library could be used to generate a complex document. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter08/demo/samples/jasper/dukesign.jpg b/Chapter08/demo/samples/jasper/dukesign.jpg new file mode 100644 index 0000000..5d74327 Binary files /dev/null and b/Chapter08/demo/samples/jasper/dukesign.jpg differ diff --git a/Chapter08/demo/samples/jasper/jasperreports.gif b/Chapter08/demo/samples/jasper/jasperreports.gif new file mode 100644 index 0000000..2c230a8 Binary files /dev/null and b/Chapter08/demo/samples/jasper/jasperreports.gif differ diff --git a/Chapter08/demo/samples/jasper/readme.txt b/Chapter08/demo/samples/jasper/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter08/demo/samples/jasper/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter08/demo/samples/mondrian/build.properties b/Chapter08/demo/samples/mondrian/build.properties new file mode 100644 index 0000000..ac7b3f5 --- /dev/null +++ b/Chapter08/demo/samples/mondrian/build.properties @@ -0,0 +1,13 @@ +# for the Mondrian test DBMS, connected via JDBC/ODBC +# This can be downloaded from https://sourceforge.net/project/showfiles.php?group_id=35302 +# See http://mondrian.sourceforge.net for set up details + +#file.name=MondrianFoodMartSalesReport +#monConnection.properties=FoodMartConnection.properties + + +# for a report against the JasperReports test HSQLDB database +# These are the defaults in the build.xml + +#file.name=MondrianReport +#monConnection.properties=monConnection.properties \ No newline at end of file diff --git a/Chapter08/demo/samples/mondrian/build.xml b/Chapter08/demo/samples/mondrian/build.xml new file mode 100644 index 0000000..2a52830 --- /dev/null +++ b/Chapter08/demo/samples/mondrian/build.xml @@ -0,0 +1,202 @@ + + + Shows how different feautures of the library could be used to generate a complex document. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter08/demo/samples/mondrian/lib/commons-dbcp-1.2.1.jar b/Chapter08/demo/samples/mondrian/lib/commons-dbcp-1.2.1.jar new file mode 100644 index 0000000..08440c0 Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/commons-dbcp-1.2.1.jar differ diff --git a/Chapter08/demo/samples/mondrian/lib/commons-pool-1.3.jar b/Chapter08/demo/samples/mondrian/lib/commons-pool-1.3.jar new file mode 100644 index 0000000..623b1c0 Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/commons-pool-1.3.jar differ diff --git a/Chapter08/demo/samples/mondrian/lib/eigenbase-properties.jar b/Chapter08/demo/samples/mondrian/lib/eigenbase-properties.jar new file mode 100644 index 0000000..259cd4a Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/eigenbase-properties.jar differ diff --git a/Chapter08/demo/samples/mondrian/lib/eigenbase-resgen.jar b/Chapter08/demo/samples/mondrian/lib/eigenbase-resgen.jar new file mode 100644 index 0000000..7b4603d Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/eigenbase-resgen.jar differ diff --git a/Chapter08/demo/samples/mondrian/lib/eigenbase-xom.jar b/Chapter08/demo/samples/mondrian/lib/eigenbase-xom.jar new file mode 100644 index 0000000..b042bb6 Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/eigenbase-xom.jar differ diff --git a/Chapter08/demo/samples/mondrian/lib/javacup.jar b/Chapter08/demo/samples/mondrian/lib/javacup.jar new file mode 100644 index 0000000..ea472da Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/javacup.jar differ diff --git a/Chapter08/demo/samples/mondrian/lib/log4j-1.2.9.jar b/Chapter08/demo/samples/mondrian/lib/log4j-1.2.9.jar new file mode 100644 index 0000000..a6568b0 Binary files /dev/null and b/Chapter08/demo/samples/mondrian/lib/log4j-1.2.9.jar differ diff --git a/Chapter08/demo/samples/mondrian/metadata/FoodMart.xml b/Chapter08/demo/samples/mondrian/metadata/FoodMart.xml new file mode 100644 index 0000000..57968d9 --- /dev/null +++ b/Chapter08/demo/samples/mondrian/metadata/FoodMart.xml @@ -0,0 +1,646 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + +
+ + + + + + + + + +
+
+ + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + +
+ + + + + + +"fname" || ' ' || "lname" + + +fname + ' ' + lname + + +"fname" || ' ' || "lname" + + +CONCAT(`customer`.`fname`, ' ', `customer`.`lname`) + + +fname + ' ' + lname + + +"customer"."fullname" + + +CONCAT(CONCAT(fname, ' '), lname) + + +fullname + + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + + + + + + + [Measures].[Store Sales] - [Measures].[Store Cost] + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + +
+
+ + + + + + + +
+ + + + + + + +
+ + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ + + + + + +"fname" || ' ' || "lname" + + +fname + ' ' + lname + + +"fname" || ' ' || "lname" + + +CONCAT(`customer`.`fname`, ' ', `customer`.`lname`) + + +fname + ' ' + lname + + +"customer"."fullname" + + +CONCAT(CONCAT(fname, ' '), lname) + + +fullname + + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter08/demo/samples/mondrian/metadata/FoodMartConnection.properties b/Chapter08/demo/samples/mondrian/metadata/FoodMartConnection.properties new file mode 100644 index 0000000..a334eef --- /dev/null +++ b/Chapter08/demo/samples/mondrian/metadata/FoodMartConnection.properties @@ -0,0 +1,5 @@ +jdbcUrl=jdbc:odbc:MondrianFoodMart +jdbcUser= +jdbcPassword= +catalogUri=file:FoodMart.xml +jdbcDrivers=sun.jdbc.odbc.JdbcOdbcDriver diff --git a/Chapter08/demo/samples/mondrian/metadata/log4j.properties b/Chapter08/demo/samples/mondrian/metadata/log4j.properties new file mode 100644 index 0000000..4459ca0 --- /dev/null +++ b/Chapter08/demo/samples/mondrian/metadata/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=ERROR, err + +log4j.appender.err=org.apache.log4j.ConsoleAppender +log4j.appender.err.Target=System.err +log4j.appender.err.layout=org.apache.log4j.PatternLayout +log4j.appender.err.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c %x - %m%n diff --git a/Chapter08/demo/samples/mondrian/metadata/monConnection.properties b/Chapter08/demo/samples/mondrian/metadata/monConnection.properties new file mode 100644 index 0000000..80cd865 --- /dev/null +++ b/Chapter08/demo/samples/mondrian/metadata/monConnection.properties @@ -0,0 +1,5 @@ +jdbcUrl=jdbc:hsqldb:hsql://localhost +jdbcUser=sa +jdbcPassword= +catalogUri=file:schema.xml +jdbcDrivers=org.hsqldb.jdbcDriver diff --git a/Chapter08/demo/samples/mondrian/metadata/schema.xml b/Chapter08/demo/samples/mondrian/metadata/schema.xml new file mode 100644 index 0000000..a0e38ca --- /dev/null +++ b/Chapter08/demo/samples/mondrian/metadata/schema.xml @@ -0,0 +1,32 @@ + + + + +
+ + +
+ + + + + + +
+
+ + + + + "FIRSTNAME" || ' ' || "LASTNAME" + + + + + + + + + diff --git a/Chapter08/demo/samples/mondrian/reports/MondrianFoodMartSalesReport.jrxml b/Chapter08/demo/samples/mondrian/reports/MondrianFoodMartSalesReport.jrxml new file mode 100644 index 0000000..0e4407b --- /dev/null +++ b/Chapter08/demo/samples/mondrian/reports/MondrianFoodMartSalesReport.jrxml @@ -0,0 +1,143 @@ + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="50"> + <line> + <reportElement x="0" y="0" width="515" height="1"/> + <graphicElement/> + </line> + <textField isBlankWhenNull="true"> + <reportElement x="0" y="10" width="515" height="30" style="Arial_Normal"/> + <textElement textAlignment="Center"> + <font size="22"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter08/demo/samples/scriptlet/SimpleExportProgressMonitor.java b/Chapter08/demo/samples/scriptlet/SimpleExportProgressMonitor.java new file mode 100644 index 0000000..8c5b1ad --- /dev/null +++ b/Chapter08/demo/samples/scriptlet/SimpleExportProgressMonitor.java @@ -0,0 +1,49 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ + +import net.sf.jasperreports.engine.export.JRExportProgressMonitor; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: SimpleExportProgressMonitor.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class SimpleExportProgressMonitor implements JRExportProgressMonitor +{ + + + /** + * + */ + public void afterPageExport() + { + System.out.println("call afterPageExport"); + } + + +} diff --git a/Chapter08/demo/samples/scriptlet/build.xml b/Chapter08/demo/samples/scriptlet/build.xml new file mode 100644 index 0000000..b3f84c8 --- /dev/null +++ b/Chapter08/demo/samples/scriptlet/build.xml @@ -0,0 +1,183 @@ + + + Shows how the scriptlets could be used to manipulate data during report filling. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter08/demo/samples/scriptlet/readme.txt b/Chapter08/demo/samples/scriptlet/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter08/demo/samples/scriptlet/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter08/demo/samples/subreport/AddressReport.jrxml b/Chapter08/demo/samples/subreport/AddressReport.jrxml new file mode 100644 index 0000000..bae52c2 --- /dev/null +++ b/Chapter08/demo/samples/subreport/AddressReport.jrxml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5)]]> + + + + + + + + + + + <band height="100"> + <elementGroup> + <line> + <reportElement x="0" y="0" width="555" height="1"/> + <graphicElement/> + </line> + <image scaleImage="Clip"> + <reportElement x="0" y="5" width="165" height="40"/> + <graphicElement/> + <imageExpression class="java.lang.String"><![CDATA["jasperreports.gif"]]></imageExpression> + </image> + </elementGroup> + <textField isBlankWhenNull="true"> + <reportElement x="180" y="5" width="375" height="35" style="Comic_Bold"/> + <textElement textAlignment="Right"> + <font size="22"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="180" y="40" width="375" height="15" style="Arial_Italic"/> + <textElement textAlignment="Right"> + <font size="12"/> + </textElement> + <text><![CDATA[(c)2001-2006 by teodord]]></text> + </staticText> + <textField evaluationTime="Report"> + <reportElement x="255" y="55" width="100" height="40"/> + <textElement textAlignment="Justified"/> + <textFieldExpression class="java.lang.String"><![CDATA["There are " + String.valueOf($V{REPORT_COUNT}) + " orders on this report, with a total freight of " + new DecimalFormat("0.00").format($V{FreightSumReport}.doubleValue())]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/demo/samples/jasper/JasperApp.java b/Chapter09/demo/samples/jasper/JasperApp.java new file mode 100644 index 0000000..eb3f9cf --- /dev/null +++ b/Chapter09/demo/samples/jasper/JasperApp.java @@ -0,0 +1,328 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.Panel; +import java.awt.Toolkit; +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: JasperApp.java 1644 2007-03-20 09:57:51Z teodord $ + */ +public class JasperApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + private static final String TASK_RUN = "run"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_FILL.equals(taskName)) + { + //Preparing parameters + Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg"); + MediaTracker traker = new MediaTracker(new Panel()); + traker.addImage(image, 0); + try + { + traker.waitForID(0); + } + catch (Exception e) + { + e.printStackTrace(); + } + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "The First Jasper Report Ever"); + parameters.put("MaxOrderID", new Integer(10500)); + parameters.put("SummaryImage", image); + + JasperFillManager.fillReportToFile(fileName, parameters, getConnection()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + JasperExportManager.exportReportToHtmlFile(fileName); + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + File sourceFile = new File(fileName); + Map dateFormats = new HashMap(); + dateFormats.put("EEE, MMM d, yyyy", "ddd, mmm d, yyyy"); + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); + exporter.setParameter(JRXlsExporterParameter.FORMAT_PATTERNS_MAP, dateFormats); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RUN.equals(taskName)) + { + //Preparing parameters + Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg"); + MediaTracker traker = new MediaTracker(new Panel()); + traker.addImage(image, 0); + try + { + traker.waitForID(0); + } + catch (Exception e) + { + e.printStackTrace(); + } + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "The First Jasper Report Ever"); + parameters.put("MaxOrderID", new Integer(10500)); + parameters.put("SummaryImage", image); + + JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection()); + System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "JasperApp usage:" ); + System.out.println( "\tjava JasperApp -Ttask -Ffile" ); + System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" ); + } + + + /** + * + */ + private static Connection getConnection() throws ClassNotFoundException, SQLException + { + //Change these settings according to your local configuration + String driver = "org.hsqldb.jdbcDriver"; + String connectString = "jdbc:hsqldb:hsql://localhost"; + String user = "sa"; + String password = ""; + + + Class.forName(driver); + Connection conn = DriverManager.getConnection(connectString, user, password); + return conn; + } + + +} diff --git a/Chapter09/demo/samples/jasper/build.xml b/Chapter09/demo/samples/jasper/build.xml new file mode 100644 index 0000000..1805925 --- /dev/null +++ b/Chapter09/demo/samples/jasper/build.xml @@ -0,0 +1,183 @@ + + + Shows how different feautures of the library could be used to generate a complex document. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter09/demo/samples/jasper/dukesign.jpg b/Chapter09/demo/samples/jasper/dukesign.jpg new file mode 100644 index 0000000..5d74327 Binary files /dev/null and b/Chapter09/demo/samples/jasper/dukesign.jpg differ diff --git a/Chapter09/demo/samples/jasper/jasperreports.gif b/Chapter09/demo/samples/jasper/jasperreports.gif new file mode 100644 index 0000000..2c230a8 Binary files /dev/null and b/Chapter09/demo/samples/jasper/jasperreports.gif differ diff --git a/Chapter09/demo/samples/jasper/readme.txt b/Chapter09/demo/samples/jasper/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter09/demo/samples/jasper/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter09/demo/samples/query/QueryApp.java b/Chapter09/demo/samples/query/QueryApp.java new file mode 100644 index 0000000..8fdcd6a --- /dev/null +++ b/Chapter09/demo/samples/query/QueryApp.java @@ -0,0 +1,327 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JRParameter; +import net.sf.jasperreports.engine.JasperCompileManager; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: QueryApp.java 1683 2007-03-29 16:04:15Z lucianc $ + */ +public class QueryApp +{ + + + /** + * + */ + private static final String TASK_COMPILE = "compile"; + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + private static final String TASK_RUN = "run"; + private static final String TASK_FILL_IGNORE_PAGINATION = "fillIgnorePagination"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_COMPILE.equals(taskName)) + { + JasperCompileManager.compileReportToFile(fileName); + System.err.println("Compile time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_FILL.equals(taskName) || TASK_FILL_IGNORE_PAGINATION.equals(taskName)) + { + //Preparing parameters + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + + List excludedCities = new ArrayList(); + excludedCities.add("Boston"); + excludedCities.add("Chicago"); + excludedCities.add("Oslo"); + parameters.put("ExcludedCities", excludedCities); + + parameters.put("OrderClause", "City"); + + if (TASK_FILL_IGNORE_PAGINATION.equals(taskName)) + { + parameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); + } + + JasperFillManager.fillReportToFile(fileName, parameters, getConnection()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + JasperExportManager.exportReportToHtmlFile(fileName); + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RUN.equals(taskName)) + { + //Preparing parameters + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + + List excludedCities = new ArrayList(); + excludedCities.add("Boston"); + excludedCities.add("Chicago"); + excludedCities.add("Oslo"); + parameters.put("ExcludedCities", excludedCities); + + parameters.put("OrderClause", "City"); + + JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection()); + System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "QueryApp usage:" ); + System.out.println( "\tjava QueryApp -Ttask -Ffile" ); + System.out.println( "\tTasks : compile | fill | fillIgnorePagination | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" ); + } + + + /** + * + */ + private static Connection getConnection() throws ClassNotFoundException, SQLException + { + //Change these settings according to your local configuration + String driver = "org.hsqldb.jdbcDriver"; + String connectString = "jdbc:hsqldb:hsql://localhost"; + String user = "sa"; + String password = ""; + + + Class.forName(driver); + Connection conn = DriverManager.getConnection(connectString, user, password); + return conn; + } + + +} diff --git a/Chapter09/demo/samples/query/QueryReport.jrxml b/Chapter09/demo/samples/query/QueryReport.jrxml new file mode 100644 index 0000000..89b1419 --- /dev/null +++ b/Chapter09/demo/samples/query/QueryReport.jrxml @@ -0,0 +1,178 @@ + + +]> + + + + &reportStyles; + + + + + + + + + + + + ($V{CityNumber} != null)?(new Integer($V{CityNumber}.intValue() + 1)):(new Integer(1)) + + + + $F{City} + + + + + + + + + + + " " + String.valueOf($V{CityNumber}) + ". " + String.valueOf($F{City}) + + + + + + + + + + + + + + + + Count : + + + + + + $V{CityGroup_COUNT} + + + + + + + + + + "jr.watermark.gif" + + + + + <band height="50"> + <line> + <reportElement x="0" y="0" width="515" height="0" forecolor="black"/> + </line> + <textField isBlankWhenNull="true"> + <reportElement x="0" y="10" width="515" height="30" style="Arial_Normal"/> + <textElement textAlignment="Center" lineSpacing="Single"> + <font size="22"/> + </textElement> + <textFieldExpression class="java.lang.String">$P{ReportTitle}</textFieldExpression> + </textField> + </band> + + + + + + + + + + ID + + + + Name + + + + Street + + + + + + + + + + $F{Id} + + + + + + $F{FirstName} + " " + $F{LastName} + + + + + + $F{Street} + + + + + + + + + + $P{IS_IGNORE_PAGINATION}.booleanValue()?Boolean.FALSE:Boolean.TRUE + + + + + + + + "Page " + String.valueOf($V{PAGE_NUMBER}) + " of" + + + + + + + " " + String.valueOf($V{PAGE_NUMBER}) + + + + + + + + + + + "There were " + + String.valueOf($V{REPORT_COUNT}) + + " address records on this report." + + + + + diff --git a/Chapter09/demo/samples/query/ReportStyles.ent b/Chapter09/demo/samples/query/ReportStyles.ent new file mode 100644 index 0000000..fc1c943 --- /dev/null +++ b/Chapter09/demo/samples/query/ReportStyles.ent @@ -0,0 +1,3 @@ + element containing styled text. elements are introduced by setting the boolean attribute available for the tag to and by formatting the text content using nested tags and simple HTML tags.]]> + + + + + + + ^ logo and some superscript text and subscript text."]]> + + + + + + + style tag used to format the text content inside a styled text element: + +fontName + + + + + +pdfFontName +pdfEncoding +isPdfEmbedded + +]]> + + + + + + + <font size="12"> +<font color="red"> +<font face="Comic Sans MS"> +bold <b> italic <i> underlined <u> +an empty line follows (<br/>): +
+<sup> and <sub> +
+A bulleted list: +
  • item 1 <li>
  • +]]> +
    + + + + + + + + + + + + + + + + + + 1\n\n\n\n\n"]]> + + + + diff --git a/Chapter10/demo/samples/styledtext/build.xml b/Chapter10/demo/samples/styledtext/build.xml new file mode 100644 index 0000000..01da988 --- /dev/null +++ b/Chapter10/demo/samples/styledtext/build.xml @@ -0,0 +1,183 @@ + + + Shows how the styled-text feature works in static and dynamic text elements. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/demo/samples/styledtext/readme.txt b/Chapter10/demo/samples/styledtext/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter10/demo/samples/styledtext/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter10/demo/samples/unicode/UnicodeApp.java b/Chapter10/demo/samples/unicode/UnicodeApp.java new file mode 100644 index 0000000..4066c4c --- /dev/null +++ b/Chapter10/demo/samples/unicode/UnicodeApp.java @@ -0,0 +1,280 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JREmptyDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: UnicodeApp.java 1665 2007-03-26 09:53:29Z teodord $ + */ +public class UnicodeApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + private static final String TASK_RUN = "run"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_FILL.equals(taskName)) + { + Map parameters = new HashMap(); + parameters.put("GreekText", "\u0393 \u0394 \u0398 \u039B \u039E \u03A0 \u03A3 \u03A6 \u03A8 \u03A9"); + parameters.put("CyrillicText", "\u0402 \u040B \u040F \u0414 \u0416 \u0418 \u041B \u0426 \u0429 \u042E"); + parameters.put("ArabicText", "\u0647\u0630\u0627 \u0639\u0631\u0636 \u0644\u0645\u062C\u0645\u0648\u0639\u0629 TextLayout"); + parameters.put("HebrewText", "\u05D0\u05E0\u05D9 \u05DC\u05D0 \u05DE\u05D1\u05D9\u05DF \u05E2\u05D1\u05E8\u05D9\u05EA"); + + JasperFillManager.fillReportToFile(fileName, parameters, new JREmptyDataSource()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + JasperExportManager.exportReportToHtmlFile(fileName); + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RUN.equals(taskName)) + { + Map parameters = new HashMap(); + parameters.put("GreekText", "\u0393 \u0394 \u0398 \u039B \u039E \u03A0 \u03A3 \u03A6 \u03A8 \u03A9"); + parameters.put("CyrillicText", "\u0402 \u040B \u040F \u0414 \u0416 \u0418 \u041B \u0426 \u0429 \u042E"); + parameters.put("ArabicText", "\u0647\u0630\u0627 \u0639\u0631\u0636 \u0644\u0645\u062C\u0645\u0648\u0639\u0629 TextLayout"); + parameters.put("HebrewText", "\u05D0\u05E0\u05D9 \u05DC\u05D0 \u05DE\u05D1\u05D9\u05DF \u05E2\u05D1\u05E8\u05D9\u05EA"); + + JasperRunManager.runReportToPdfFile(fileName, parameters, new JREmptyDataSource()); + System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "UnicodeApp usage:" ); + System.out.println( "\tjava UnicodeApp -Ttask -Ffile" ); + System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" ); + } + + +} diff --git a/Chapter10/demo/samples/unicode/UnicodeReport.jrxml b/Chapter10/demo/samples/unicode/UnicodeReport.jrxml new file mode 100644 index 0000000..982b447 --- /dev/null +++ b/Chapter10/demo/samples/unicode/UnicodeReport.jrxml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + <band height="782"> + <textField> + <reportElement x="0" y="50" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="50" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="50" width="200" height="90"/><textElement><font fontName="Arial" size="14" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="0" y="150" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" isBold="true" pdfFontName="ARIALBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="150" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="150" width="200" height="90"/><textElement><font fontName="Arial" size="14" isBold="true" pdfFontName="ARIALBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="0" y="250" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" isItalic="true" isUnderline="true" pdfFontName="ARIALI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="250" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="250" width="200" height="90"/><textElement><font fontName="Arial" size="14" isItalic="true" isUnderline="true" pdfFontName="ARIALI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="0" y="350" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" isBold="true" isItalic="true" isUnderline="true" pdfFontName="ARIALBI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="350" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="350" width="200" height="90"/><textElement><font fontName="Arial" size="14" isBold="true" isItalic="true" isUnderline="true" pdfFontName="ARIALBI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="100" y="500" width="350" height="50"/> + <textElement textAlignment="Right"> + <font fontName="Arial" size="22" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ArabicText}]]></textFieldExpression> + </textField> + <textField> + <reportElement x="100" y="600" width="350" height="50"/> + <textElement textAlignment="Right"> + <font fontName="Arial" size="22" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{HebrewText}]]></textFieldExpression> + </textField> + </band> + + diff --git a/Chapter10/demo/samples/unicode/build.xml b/Chapter10/demo/samples/unicode/build.xml new file mode 100644 index 0000000..db61ce8 --- /dev/null +++ b/Chapter10/demo/samples/unicode/build.xml @@ -0,0 +1,183 @@ + + + Shows how text in different languages could be used inside reports. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter10/demo/samples/unicode/readme.txt b/Chapter10/demo/samples/unicode/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter10/demo/samples/unicode/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter11/demo/samples/subreport/AddressReport.jrxml b/Chapter11/demo/samples/subreport/AddressReport.jrxml new file mode 100644 index 0000000..bae52c2 --- /dev/null +++ b/Chapter11/demo/samples/subreport/AddressReport.jrxml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + <band height="40"> + <staticText> + <reportElement x="0" y="0" width="555" height="20" style="Title"/> + <textElement verticalAlignment="Middle" textAlignment="Center"/> + <text>Shipped Orders</text> + </staticText> + </band> + + + + + + + + + Order ID + + + + + Country + + + + + Freight + + + + + Order date + + + + + Required date + + + + + Shipped date + + + + + Late (hrs) + + + + + + + + + + + + $F{OrderId}.toString() + + + + + $F{ShipCountry} + + + + + $F{Freight} + + + + + $F{OrderDate} + + + + + $F{RequiredDate} + + + + + $F{ShippedDate} + + + + + $V{DeliveryDelay}.toString() + + + + + + + + + Late deliveries summary (count and total delay) by country and freight range + + + + + + $V{DeliveryDelay} == null ? Boolean.FALSE : Boolean.TRUE + + + + + $F{ShipCountry} + + + + + + + + + + + + + + + + + + + + TOTAL + + + + + + + new Integer($F{Freight}.intValue()/100) + + + + + + + + + + + + + + + + + + + + TOTAL + + + + + + $F{Freight} + + + $V{DeliveryDelay} + + + + + + + + $V{OrderCount} + + + + + $V{Delay} + + + + + + + + + + $V{OrderCount} + + + + + $V{Delay} + + + + + + + + + + $V{OrderCount} + + + + + $V{Delay} + + + + + + + + + + $V{OrderCount} + + + + + $V{Delay} + + + + + + + diff --git a/Chapter14/demo/samples/crosstabs/OrdersReport.jrxml b/Chapter14/demo/samples/crosstabs/OrdersReport.jrxml new file mode 100644 index 0000000..c4ccbaf --- /dev/null +++ b/Chapter14/demo/samples/crosstabs/OrdersReport.jrxml @@ -0,0 +1,164 @@ + + + + + + + + + + + + <band height="20"> + <staticText> + <reportElement x="0" y="0" width="782" height="20" style="Arial_Bold"/> + <textElement verticalAlignment="Middle"> + <font size="12"/> + </textElement> + <text>Number of orders and latest order date by country and freight range.</text> + </staticText> + </band> + + + + + + + + + + + $F{ShipCountry} + + + + + + + + + + + + + + + + + + + + TOTAL + + + + + + + new Integer($F{Freight}.intValue()/100) + + + + + + + + + + + + + + + + + + + + TOTAL + + + + + + $F{Freight} + + + $F{OrderDate} + + + + + + + + $V{OrderCount} + + + + + $V{MaxDate} + + + + + + + + + + $V{OrderCount} + + + + + $V{MaxDate} + + + + + + + + + + $V{OrderCount} + + + + + $V{MaxDate} + + + + + + + + + + $V{OrderCount} + + + + + $V{MaxDate} + + + + + + + \ No newline at end of file diff --git a/Chapter14/demo/samples/crosstabs/ProductsReport.jrxml b/Chapter14/demo/samples/crosstabs/ProductsReport.jrxml new file mode 100644 index 0000000..0ecddd9 --- /dev/null +++ b/Chapter14/demo/samples/crosstabs/ProductsReport.jrxml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="50"> + <line> + <reportElement x="0" y="0" width="515" height="1"/> + <graphicElement/> + </line> + <textField isBlankWhenNull="true"> + <reportElement x="0" y="10" width="515" height="30" style="Arial_Normal"/> + <textElement textAlignment="Center"> + <font size="22"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/demo/samples/scriptlet/SimpleExportProgressMonitor.java b/Chapter15/demo/samples/scriptlet/SimpleExportProgressMonitor.java new file mode 100644 index 0000000..8c5b1ad --- /dev/null +++ b/Chapter15/demo/samples/scriptlet/SimpleExportProgressMonitor.java @@ -0,0 +1,49 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ + +import net.sf.jasperreports.engine.export.JRExportProgressMonitor; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: SimpleExportProgressMonitor.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class SimpleExportProgressMonitor implements JRExportProgressMonitor +{ + + + /** + * + */ + public void afterPageExport() + { + System.out.println("call afterPageExport"); + } + + +} diff --git a/Chapter15/demo/samples/scriptlet/build.xml b/Chapter15/demo/samples/scriptlet/build.xml new file mode 100644 index 0000000..b3f84c8 --- /dev/null +++ b/Chapter15/demo/samples/scriptlet/build.xml @@ -0,0 +1,183 @@ + + + Shows how the scriptlets could be used to manipulate data during report filling. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter15/demo/samples/scriptlet/readme.txt b/Chapter15/demo/samples/scriptlet/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter15/demo/samples/scriptlet/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter16/demo/samples/i18n/I18nApp.java b/Chapter16/demo/samples/i18n/I18nApp.java new file mode 100644 index 0000000..1b4cb32 --- /dev/null +++ b/Chapter16/demo/samples/i18n/I18nApp.java @@ -0,0 +1,344 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.File; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import javax.swing.JOptionPane; + +import net.sf.jasperreports.engine.JREmptyDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JRParameter; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; +import net.sf.jasperreports.view.JasperViewer; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: I18nApp.java 1653 2007-03-23 08:57:13Z teodord $ + */ +public class I18nApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_FILL_DEFAULT = "fillDefault"; + private static final String TASK_VIEW = "view"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + + + /** + * + */ + public static void main(String[] args) + { + if(args.length != 2) + { + usage(); + return; + } + + String taskName = args[0]; + String fileName = args[1]; + + try + { + if (TASK_FILL.equals(taskName)) + { + Locale locale = chooseLocale(); + if (locale != null) + { +// Object[] aw = new Object[] {new Double(1000000.45), "$", "Ferrari", new Integer(20),new Integer(88)}; + Map parameters = new HashMap(); + parameters.put("number", new Double(1234567 + Math.random())); +// parameters.put("array", aw); + parameters.put(JRParameter.REPORT_LOCALE, locale); + long start = System.currentTimeMillis(); + JasperFillManager.fillReportToFile(fileName, parameters, new JREmptyDataSource()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + } + System.exit(0); + } + else if (TASK_FILL_DEFAULT.equals(taskName)) + { + Map parameters = new HashMap(); + parameters.put("number", new Double(1234567 + Math.random())); + long start = System.currentTimeMillis(); + JasperFillManager.fillReportToFile(fileName, parameters, new JREmptyDataSource()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_VIEW.equals(taskName)) + { + Locale locale = chooseLocale(); + if (locale != null) + { + JasperViewer.viewReport(fileName, false, true, locale); + } + else + { + System.exit(0); + } + } + else if (TASK_PDF.equals(taskName)) + { + long start = System.currentTimeMillis(); + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + long start = System.currentTimeMillis(); + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + long start = System.currentTimeMillis(); + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + long start = System.currentTimeMillis(); + JasperExportManager.exportReportToHtmlFile(fileName); + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + long start = System.currentTimeMillis(); + + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + long start = System.currentTimeMillis(); + + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + long start = System.currentTimeMillis(); + + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + long start = System.currentTimeMillis(); + + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + long start = System.currentTimeMillis(); + + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static Locale chooseLocale() + { + LocaleWrapper[] locales = + new LocaleWrapper[] + { + new LocaleWrapper(new Locale("cs", "CZ")), + new LocaleWrapper(Locale.GERMANY), + new LocaleWrapper(Locale.US), + new LocaleWrapper(Locale.FRANCE), + new LocaleWrapper(new Locale("pt", "PT")), + new LocaleWrapper(new Locale("ro", "RO")), + new LocaleWrapper(new Locale("sk", "SK")) + }; + + LocaleWrapper locale = + (LocaleWrapper)JOptionPane.showInputDialog( + null, + "Choose the locale", + "Locale", + JOptionPane.PLAIN_MESSAGE, + null, + locales, + null + ); + + if (locale != null) + return locale.getLocale(); + + return null; + } + + /** + * + */ + private static void usage() + { + System.out.println( "I18nApp usage:" ); + System.out.println( "\tjava I18nApp task file" ); + System.out.println( "\tTasks : fill | fillDefault | view | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt" ); + } + + +} + +class LocaleWrapper +{ + Locale locale = null; + + public LocaleWrapper(Locale locale) + { + this.locale = locale; + } + + public Locale getLocale() + { + return locale; + } + + public String toString() + { + return locale.toString() + " - " + locale.getDisplayName(locale); + } +} diff --git a/Chapter16/demo/samples/i18n/I18nReport.jrxml b/Chapter16/demo/samples/i18n/I18nReport.jrxml new file mode 100644 index 0000000..69f129e --- /dev/null +++ b/Chapter16/demo/samples/i18n/I18nReport.jrxml @@ -0,0 +1,64 @@ + + + + + + + <band height="552"> + <image scaleImage="Clip"> + <reportElement positionType="Float" x="20" y="20" width="100" height="50"/> + <graphicElement/> + <imageExpression class="java.lang.String"><![CDATA[$R{image.flag}]]></imageExpression> + </image> + <textField> + <reportElement positionType="Float" x="150" y="20" width="400" height="50"/> + <textElement> + <font size="24"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{REPORT_LOCALE}.getDisplayName($P{REPORT_LOCALE})]]></textFieldExpression> + </textField> + <textField isStretchWithOverflow="true" isBlankWhenNull="true"> + <reportElement positionType="Float" x="20" y="100" width="530" height="20"/> + <textElement textAlignment="Justified"> + <font size="14"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$R{text.paragraph1}]]></textFieldExpression> + </textField> + <textField isStretchWithOverflow="true" isBlankWhenNull="true"> + <reportElement positionType="Float" x="20" y="125" width="530" height="20"/> + <textElement textAlignment="Justified"> + <font size="14"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$R{text.paragraph2}]]></textFieldExpression> + </textField> + <textField isStretchWithOverflow="true" isBlankWhenNull="true"> + <reportElement positionType="Float" x="20" y="150" width="530" height="20"/> + <textElement textAlignment="Justified"> + <font size="14"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$R{text.paragraph3}]]></textFieldExpression> + </textField> + <textField isStretchWithOverflow="true" isBlankWhenNull="true"> + <reportElement positionType="Float" x="20" y="210" width="530" height="20" forecolor="#ff0000"/> + <textElement> + <font size="14"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[msg($R{text.message}, $P{number})]]></textFieldExpression> + </textField> + <textField isStretchWithOverflow="true" isBlankWhenNull="true" pattern="full,short"> + <reportElement positionType="Float" x="20" y="175" width="530" height="28" forecolor="#ff"/> + <textElement> + <font size="18" isItalic="true" pdfFontName="Helvetica-Oblique"/> + </textElement> + <textFieldExpression class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression> + </textField> + <textField isStretchWithOverflow="true" isBlankWhenNull="true"> + <reportElement positionType="Float" x="20" y="235" width="530" height="15"/> + <textElement textAlignment="Right"> + <font size="10" isItalic="true" pdfFontName="Helvetica-Oblique"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$R{text.contributors}]]></textFieldExpression> + </textField> + </band> + + diff --git a/Chapter16/demo/samples/i18n/build.xml b/Chapter16/demo/samples/i18n/build.xml new file mode 100644 index 0000000..c3de3c4 --- /dev/null +++ b/Chapter16/demo/samples/i18n/build.xml @@ -0,0 +1,168 @@ + + + Shows how a report could be rendered in different languages. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/demo/samples/i18n/cs.gif b/Chapter16/demo/samples/i18n/cs.gif new file mode 100644 index 0000000..317f427 Binary files /dev/null and b/Chapter16/demo/samples/i18n/cs.gif differ diff --git a/Chapter16/demo/samples/i18n/de.gif b/Chapter16/demo/samples/i18n/de.gif new file mode 100644 index 0000000..8872e3c Binary files /dev/null and b/Chapter16/demo/samples/i18n/de.gif differ diff --git a/Chapter16/demo/samples/i18n/fr.gif b/Chapter16/demo/samples/i18n/fr.gif new file mode 100644 index 0000000..47d9241 Binary files /dev/null and b/Chapter16/demo/samples/i18n/fr.gif differ diff --git a/Chapter16/demo/samples/i18n/i18n.properties b/Chapter16/demo/samples/i18n/i18n.properties new file mode 100644 index 0000000..8192edf --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n.properties @@ -0,0 +1,6 @@ +text.paragraph1=JasperReports is a powerful open source Java reporting tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files. +text.paragraph2=It is entirely written in Java and can be used in a variety of Java enabled applications, including J2EE or Web applications, to generate dynamic content. +text.paragraph3=Its main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner. +image.flag=us.gif +text.message=The program picked up {0} as a random number. +text.contributors= diff --git a/Chapter16/demo/samples/i18n/i18n_cs.properties b/Chapter16/demo/samples/i18n/i18n_cs.properties new file mode 100644 index 0000000..552937a --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n_cs.properties @@ -0,0 +1,6 @@ +text.paragraph1= +text.paragraph2= +text.paragraph3= +image.flag=cs.gif +text.message= +text.contributors= diff --git a/Chapter16/demo/samples/i18n/i18n_de_DE.properties b/Chapter16/demo/samples/i18n/i18n_de_DE.properties new file mode 100644 index 0000000..ad64480 --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n_de_DE.properties @@ -0,0 +1,6 @@ +text.paragraph1=JasperReports ist ein leistungsfähiges Open-Source Reporting Tool mit dem es möglich ist seitenorientierte Berichte auf einfache Art aber trotzdem flexibel zu erstellen. Die erzeugten Berichte können in einem Viewer dargestellt, gedruckt oder als PDF, HTML, XLS, CSV oder XML Datei gespeichert werden. +text.paragraph2=Es ist komplett in Java geschrieben und lässt sich in in Java, J2EE und Web Anwendungen verwenden. +text.paragraph3=Seine Hauptaufgabe besteht darin, seitenorientierte und druckfertige Dokumente auf äußerst einfache und flexibele Art und Weise zu erzeugen. +image.flag=de.gif +text.message=Das Programm hob {0} als gelegentliche Zahl auf. +text.contributors=Franco Weichel,\nChristian Höfer,\nhttp://babelfish.altavista.com \ No newline at end of file diff --git a/Chapter16/demo/samples/i18n/i18n_fr_FR.properties b/Chapter16/demo/samples/i18n/i18n_fr_FR.properties new file mode 100644 index 0000000..44a38f4 --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n_fr_FR.properties @@ -0,0 +1,6 @@ +text.paragraph1=JasperReports est un outil open source puissant pour la génération des états avec du contenu riche, soit pour présentation à l'écran, impression papier ou stockage dans des fichiers en format PDF, HTML, XLS, CSV ou XML. +text.paragraph2=Il est développé entièrement en Java et peut être utilisé dans une gamme très variée d'applications Java en incluant les applications J2EE. +text.paragraph3=Son objectif principal est de fournir un moyen simple et flexible pour la création des documents pour impression sur papier. +image.flag=fr.gif +text.message=Le programme a choisi {0} comme nombre aléatoire. +text.contributors= diff --git a/Chapter16/demo/samples/i18n/i18n_pt_PT.properties b/Chapter16/demo/samples/i18n/i18n_pt_PT.properties new file mode 100644 index 0000000..c29375a --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n_pt_PT.properties @@ -0,0 +1,6 @@ +text.paragraph1=JasperReports é uma poderosa ferramenta Open Source de criação de relatórios que tem a capacidade de gerar conteúdos complexos para o ecran, para a impressora ou em ficheiros PDF, HTML, XLS, CSV e XML. +text.paragraph2=É escrita inteiramente em Java e pode ser usada numa variedade de aplicações compatíveis com Java, incluindo J2EE ou aplicações Web, para gerar conteúdos dinâmicos. +text.paragraph3=O objectivo principal é ajudar a criar documentos, paginados e prontos a imprimir, de uma maneira simples e flexível. +image.flag=pt.gif +text.message=O programa escolheu acima {0} como um número aleatório. +text.contributors=Paulo Soares,\nCarlos Martins,\nhttp://babelfish.altavista.com diff --git a/Chapter16/demo/samples/i18n/i18n_ro.properties b/Chapter16/demo/samples/i18n/i18n_ro.properties new file mode 100644 index 0000000..15321a4 --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n_ro.properties @@ -0,0 +1,6 @@ +text.paragraph1=JasperReports este o librarie Java open source specializata in generarea de documente cu continut bogat atat text cat si grafic, destinate afisarii pe ecran, imprimarii sau stocarii în fisiere cu format PDF, HTML, XLS, CSV sau XML. +text.paragraph2=Libraria este scrisa in totalitate utilizand limbajul Java si poate fi folosita intr-o gama larga de aplicatii incluzand pe cele cu arhitectura J2EE. +text.paragraph3=Obiectivul principal al librariei este de a furniza o modalitate simpla si flexibila de creare a documentelor destinate imprimarii. +image.flag=ro.gif +text.message=Programul a ales numarul {0} in mod aleator. +text.contributors= diff --git a/Chapter16/demo/samples/i18n/i18n_sk.properties b/Chapter16/demo/samples/i18n/i18n_sk.properties new file mode 100644 index 0000000..5dc8d76 --- /dev/null +++ b/Chapter16/demo/samples/i18n/i18n_sk.properties @@ -0,0 +1,6 @@ +text.paragraph1= +text.paragraph2= +text.paragraph3= +image.flag=sk.gif +text.message= +text.contributors= diff --git a/Chapter16/demo/samples/i18n/pt.gif b/Chapter16/demo/samples/i18n/pt.gif new file mode 100644 index 0000000..3a4033a Binary files /dev/null and b/Chapter16/demo/samples/i18n/pt.gif differ diff --git a/Chapter16/demo/samples/i18n/readme.txt b/Chapter16/demo/samples/i18n/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter16/demo/samples/i18n/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter16/demo/samples/i18n/ro.gif b/Chapter16/demo/samples/i18n/ro.gif new file mode 100644 index 0000000..b4e8d77 Binary files /dev/null and b/Chapter16/demo/samples/i18n/ro.gif differ diff --git a/Chapter16/demo/samples/i18n/sk.gif b/Chapter16/demo/samples/i18n/sk.gif new file mode 100644 index 0000000..d3dbf39 Binary files /dev/null and b/Chapter16/demo/samples/i18n/sk.gif differ diff --git a/Chapter16/demo/samples/i18n/us.gif b/Chapter16/demo/samples/i18n/us.gif new file mode 100644 index 0000000..4565e85 Binary files /dev/null and b/Chapter16/demo/samples/i18n/us.gif differ diff --git a/Chapter16/demo/samples/unicode/UnicodeApp.java b/Chapter16/demo/samples/unicode/UnicodeApp.java new file mode 100644 index 0000000..4066c4c --- /dev/null +++ b/Chapter16/demo/samples/unicode/UnicodeApp.java @@ -0,0 +1,280 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JREmptyDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: UnicodeApp.java 1665 2007-03-26 09:53:29Z teodord $ + */ +public class UnicodeApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + private static final String TASK_RUN = "run"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_FILL.equals(taskName)) + { + Map parameters = new HashMap(); + parameters.put("GreekText", "\u0393 \u0394 \u0398 \u039B \u039E \u03A0 \u03A3 \u03A6 \u03A8 \u03A9"); + parameters.put("CyrillicText", "\u0402 \u040B \u040F \u0414 \u0416 \u0418 \u041B \u0426 \u0429 \u042E"); + parameters.put("ArabicText", "\u0647\u0630\u0627 \u0639\u0631\u0636 \u0644\u0645\u062C\u0645\u0648\u0639\u0629 TextLayout"); + parameters.put("HebrewText", "\u05D0\u05E0\u05D9 \u05DC\u05D0 \u05DE\u05D1\u05D9\u05DF \u05E2\u05D1\u05E8\u05D9\u05EA"); + + JasperFillManager.fillReportToFile(fileName, parameters, new JREmptyDataSource()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + JasperExportManager.exportReportToHtmlFile(fileName); + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RUN.equals(taskName)) + { + Map parameters = new HashMap(); + parameters.put("GreekText", "\u0393 \u0394 \u0398 \u039B \u039E \u03A0 \u03A3 \u03A6 \u03A8 \u03A9"); + parameters.put("CyrillicText", "\u0402 \u040B \u040F \u0414 \u0416 \u0418 \u041B \u0426 \u0429 \u042E"); + parameters.put("ArabicText", "\u0647\u0630\u0627 \u0639\u0631\u0636 \u0644\u0645\u062C\u0645\u0648\u0639\u0629 TextLayout"); + parameters.put("HebrewText", "\u05D0\u05E0\u05D9 \u05DC\u05D0 \u05DE\u05D1\u05D9\u05DF \u05E2\u05D1\u05E8\u05D9\u05EA"); + + JasperRunManager.runReportToPdfFile(fileName, parameters, new JREmptyDataSource()); + System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "UnicodeApp usage:" ); + System.out.println( "\tjava UnicodeApp -Ttask -Ffile" ); + System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" ); + } + + +} diff --git a/Chapter16/demo/samples/unicode/UnicodeReport.jrxml b/Chapter16/demo/samples/unicode/UnicodeReport.jrxml new file mode 100644 index 0000000..982b447 --- /dev/null +++ b/Chapter16/demo/samples/unicode/UnicodeReport.jrxml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + <band height="782"> + <textField> + <reportElement x="0" y="50" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="50" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="50" width="200" height="90"/><textElement><font fontName="Arial" size="14" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="0" y="150" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" isBold="true" pdfFontName="ARIALBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="150" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="150" width="200" height="90"/><textElement><font fontName="Arial" size="14" isBold="true" pdfFontName="ARIALBD.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="0" y="250" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" isItalic="true" isUnderline="true" pdfFontName="ARIALI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="250" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="250" width="200" height="90"/><textElement><font fontName="Arial" size="14" isItalic="true" isUnderline="true" pdfFontName="ARIALI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="0" y="350" width="200" height="90"/> + <textElement> + <font fontName="Arial" size="14" isBold="true" isItalic="true" isUnderline="true" pdfFontName="ARIALBI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{GreekText} + "\n" + $P{CyrillicText}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="210" y="350" width="340" height="90"/> + <textElement/> + <text><![CDATA[<textField><reportElement x="0" y="350" width="200" height="90"/><textElement><font fontName="Arial" size="14" isBold="true" isItalic="true" isUnderline="true" pdfFontName="ARIALBI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement><textFieldExpression>$P{GreekText} + " " + $P{CyrillicText}</textFieldExpression></textField>]]></text> + </staticText> + <textField> + <reportElement x="100" y="500" width="350" height="50"/> + <textElement textAlignment="Right"> + <font fontName="Arial" size="22" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ArabicText}]]></textFieldExpression> + </textField> + <textField> + <reportElement x="100" y="600" width="350" height="50"/> + <textElement textAlignment="Right"> + <font fontName="Arial" size="22" pdfFontName="ARIAL.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{HebrewText}]]></textFieldExpression> + </textField> + </band> + + diff --git a/Chapter16/demo/samples/unicode/build.xml b/Chapter16/demo/samples/unicode/build.xml new file mode 100644 index 0000000..db61ce8 --- /dev/null +++ b/Chapter16/demo/samples/unicode/build.xml @@ -0,0 +1,183 @@ + + + Shows how text in different languages could be used inside reports. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter16/demo/samples/unicode/readme.txt b/Chapter16/demo/samples/unicode/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter16/demo/samples/unicode/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter17/demo/samples/batchexport/BatchExportApp.java b/Chapter17/demo/samples/batchexport/BatchExportApp.java new file mode 100644 index 0000000..4471650 --- /dev/null +++ b/Chapter17/demo/samples/batchexport/BatchExportApp.java @@ -0,0 +1,257 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ + +import java.util.ArrayList; +import java.util.List; + +import net.sf.jasperreports.engine.JREmptyDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRHtmlExporter; +import net.sf.jasperreports.engine.export.JRPdfExporter; +import net.sf.jasperreports.engine.export.JRPdfExporterParameter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: BatchExportApp.java 1653 2007-03-23 08:57:13Z teodord $ + */ +public class BatchExportApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_FILL.equals(taskName)) + { + JasperFillManager.fillReportToFile("Report1.jasper", null, new JREmptyDataSource(2)); + JasperFillManager.fillReportToFile("Report2.jasper", null, new JREmptyDataSource(2)); + JasperFillManager.fillReportToFile("Report3.jasper", null, new JREmptyDataSource(2)); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JRPdfExporter exporter = new JRPdfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + exporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JRHtmlExporter exporter = new JRHtmlExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + + exporter.exportReport(); + + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + List jasperPrintList = new ArrayList(); + jasperPrintList.add(JRLoader.loadObject("Report1.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report2.jrprint")); + jasperPrintList.add(JRLoader.loadObject("Report3.jrprint")); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "BatchExportApp usage:" ); + System.out.println( "\tjava BatchExportApp -Ttask -Ffile" ); + System.out.println( "\tTasks : fill | pdf | html | rtf | xls | jxl | csv | odt" ); + } + + +} diff --git a/Chapter17/demo/samples/batchexport/Report1.jrxml b/Chapter17/demo/samples/batchexport/Report1.jrxml new file mode 100644 index 0000000..1f05bbe --- /dev/null +++ b/Chapter17/demo/samples/batchexport/Report1.jrxml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/batchexport/Report2.jrxml b/Chapter17/demo/samples/batchexport/Report2.jrxml new file mode 100644 index 0000000..cf65cb0 --- /dev/null +++ b/Chapter17/demo/samples/batchexport/Report2.jrxml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/batchexport/Report3.jrxml b/Chapter17/demo/samples/batchexport/Report3.jrxml new file mode 100644 index 0000000..c84f5e5 --- /dev/null +++ b/Chapter17/demo/samples/batchexport/Report3.jrxml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/batchexport/build.xml b/Chapter17/demo/samples/batchexport/build.xml new file mode 100644 index 0000000..9d46ec0 --- /dev/null +++ b/Chapter17/demo/samples/batchexport/build.xml @@ -0,0 +1,191 @@ + + + Shows how barcodes multiple reports could be concatenated during export. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/batchexport/readme.txt b/Chapter17/demo/samples/batchexport/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter17/demo/samples/batchexport/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter17/demo/samples/nopagebreak/NoPageBreakApp.java b/Chapter17/demo/samples/nopagebreak/NoPageBreakApp.java new file mode 100644 index 0000000..9ae30d0 --- /dev/null +++ b/Chapter17/demo/samples/nopagebreak/NoPageBreakApp.java @@ -0,0 +1,312 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JExcelApiExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRHtmlExporter; +import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: NoPageBreakApp.java 1665 2007-03-26 09:53:29Z teodord $ + */ +public class NoPageBreakApp +{ + + + /** + * + */ + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_XML = "xml"; + private static final String TASK_XML_EMBED = "xmlEmbed"; + private static final String TASK_HTML = "html"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_XLS = "xls"; + private static final String TASK_JXL = "jxl"; + private static final String TASK_CSV = "csv"; + private static final String TASK_ODT = "odt"; + private static final String TASK_RUN = "run"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_FILL.equals(taskName)) + { + //Preparing parameters + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Orders Report"); + + JasperFillManager.fillReportToFile(fileName, parameters, getConnection()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, false); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XML_EMBED.equals(taskName)) + { + JasperExportManager.exportReportToXmlFile(fileName, true); + System.err.println("XML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_HTML.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".html"); + + JRHtmlExporter exporter = new JRHtmlExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, ""); + exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("HTML creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_XLS.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); + exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_JXL.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".jxl.xls"); + + JExcelApiExporter exporter = new JExcelApiExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); + exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); + + exporter.exportReport(); + + System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_CSV.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_ODT.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt"); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("ODT creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RUN.equals(taskName)) + { + //Preparing parameters + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Orders Report"); + + JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection()); + System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "NoPageBreakApp usage:" ); + System.out.println( "\tjava NoPageBreakApp -Ttask -Ffile" ); + System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" ); + } + + + /** + * + */ + private static Connection getConnection() throws ClassNotFoundException, SQLException + { + //Change these settings according to your local configuration + String driver = "org.hsqldb.jdbcDriver"; + String connectString = "jdbc:hsqldb:hsql://localhost"; + String user = "sa"; + String password = ""; + + + Class.forName(driver); + Connection conn = DriverManager.getConnection(connectString, user, password); + return conn; + } + + +} diff --git a/Chapter17/demo/samples/nopagebreak/NoPageBreakReport.jrxml b/Chapter17/demo/samples/nopagebreak/NoPageBreakReport.jrxml new file mode 100644 index 0000000..cc581cd --- /dev/null +++ b/Chapter17/demo/samples/nopagebreak/NoPageBreakReport.jrxml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="50"> + <line> + <reportElement x="0" y="0" width="515" height="1"/> + <graphicElement/> + </line> + <textField isBlankWhenNull="true"> + <reportElement x="0" y="10" width="515" height="30" style="Arial_Normal"/> + <textElement textAlignment="Center"> + <font size="22"/> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/scriptlet/SimpleExportProgressMonitor.java b/Chapter17/demo/samples/scriptlet/SimpleExportProgressMonitor.java new file mode 100644 index 0000000..8c5b1ad --- /dev/null +++ b/Chapter17/demo/samples/scriptlet/SimpleExportProgressMonitor.java @@ -0,0 +1,49 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ + +import net.sf.jasperreports.engine.export.JRExportProgressMonitor; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: SimpleExportProgressMonitor.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class SimpleExportProgressMonitor implements JRExportProgressMonitor +{ + + + /** + * + */ + public void afterPageExport() + { + System.out.println("call afterPageExport"); + } + + +} diff --git a/Chapter17/demo/samples/scriptlet/build.xml b/Chapter17/demo/samples/scriptlet/build.xml new file mode 100644 index 0000000..b3f84c8 --- /dev/null +++ b/Chapter17/demo/samples/scriptlet/build.xml @@ -0,0 +1,183 @@ + + + Shows how the scriptlets could be used to manipulate data during report filling. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/scriptlet/readme.txt b/Chapter17/demo/samples/scriptlet/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter17/demo/samples/scriptlet/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter17/demo/samples/text/TextApp.java b/Chapter17/demo/samples/text/TextApp.java new file mode 100644 index 0000000..5540a35 --- /dev/null +++ b/Chapter17/demo/samples/text/TextApp.java @@ -0,0 +1,211 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperCompileManager; +import net.sf.jasperreports.engine.JasperExportManager; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperRunManager; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXlsExporterParameter; +import net.sf.jasperreports.engine.export.JRTextExporter; +import net.sf.jasperreports.engine.export.JRTextExporterParameter; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: TextApp.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class TextApp +{ + + + /** + * + */ + private static final String TASK_COMPILE = "compile"; + private static final String TASK_FILL = "fill"; + private static final String TASK_PRINT = "print"; + private static final String TASK_PDF = "pdf"; + private static final String TASK_RTF = "rtf"; + private static final String TASK_TEXT = "text"; + + + /** + * + */ + public static void main(String[] args) + { + String fileName = null; + String taskName = null; + + if(args.length == 0) + { + usage(); + return; + } + + int k = 0; + while ( args.length > k ) + { + if ( args[k].startsWith("-T") ) + taskName = args[k].substring(2); + if ( args[k].startsWith("-F") ) + fileName = args[k].substring(2); + + k++; + } + + try + { + long start = System.currentTimeMillis(); + if (TASK_COMPILE.equals(taskName)) + { + JasperCompileManager.compileReportToFile(fileName); + System.err.println("Compile time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_FILL.equals(taskName)) + { + //Preparing parameters + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("FilterClause", "'Boston', 'Chicago', 'Oslo'"); + parameters.put("OrderClause", "City"); + + JasperFillManager.fillReportToFile(fileName, parameters, getConnection()); + System.err.println("Filling time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PRINT.equals(taskName)) + { + JasperPrintManager.printReport(fileName, true); + System.err.println("Printing time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_TEXT.equals(taskName)) + { + JRTextExporter exporter = new JRTextExporter(); + File sourceFile = new File(fileName); + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".txt"); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Integer(10)); + exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Integer(10)); + exporter.exportReport(); + + System.err.println("Text creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_PDF.equals(taskName)) + { + JasperExportManager.exportReportToPdfFile(fileName); + System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else if (TASK_RTF.equals(taskName)) + { + File sourceFile = new File(fileName); + + JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); + + File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".rtf"); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); + + exporter.exportReport(); + + System.err.println("RTF creation time : " + (System.currentTimeMillis() - start)); + System.exit(0); + } + else + { + usage(); + System.exit(0); + } + } + catch (JRException e) + { + e.printStackTrace(); + System.exit(1); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + + /** + * + */ + private static void usage() + { + System.out.println( "TextApp usage:" ); + System.out.println( "\tjava TextApp -Ttask -Ffile" ); + System.out.println( "\tTasks : compile | fill | print | pdf | text" ); + } + + + /** + * + */ + private static Connection getConnection() throws ClassNotFoundException, SQLException + { + //Change these settings according to your local configuration + String driver = "org.hsqldb.jdbcDriver"; + String connectString = "jdbc:hsqldb:hsql://localhost"; + String user = "sa"; + String password = ""; + + + Class.forName(driver); + Connection conn = DriverManager.getConnection(connectString, user, password); + return conn; + } + + +} diff --git a/Chapter17/demo/samples/text/TextReport.jrxml b/Chapter17/demo/samples/text/TextReport.jrxml new file mode 100644 index 0000000..4df48b4 --- /dev/null +++ b/Chapter17/demo/samples/text/TextReport.jrxml @@ -0,0 +1,403 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="60" isSplitAllowed="true" > + <line direction="TopDown"> + <reportElement + mode="Opaque" + x="0" + y="0" + width="515" + height="0" + forecolor="#000000" + backcolor="#FFFFFF" + key="line" + stretchType="NoStretch" + positionType="FixRelativeToTop" + isPrintRepeatedValues="true" + isRemoveLineWhenBlank="false" + isPrintInFirstWholeBand="false" + isPrintWhenDetailOverflows="false"/> + <graphicElement stretchType="NoStretch" pen="Thin" fill="Solid" /> + </line> + <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > + <reportElement + mode="Opaque" + x="0" + y="0" + width="760" + height="60" + forecolor="#000000" + backcolor="#FFFFFF" + key="textField" + stretchType="NoStretch" + positionType="FixRelativeToTop" + isPrintRepeatedValues="true" + isRemoveLineWhenBlank="false" + isPrintInFirstWholeBand="false" + isPrintWhenDetailOverflows="false"/> + <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> + <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single"> + <font fontName="Monospaced" pdfFontName="Courier" size="22" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> + </textElement> + <textFieldExpression class="java.lang.String"><![CDATA[$P{ReportTitle}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/text/build.xml b/Chapter17/demo/samples/text/build.xml new file mode 100644 index 0000000..105f39c --- /dev/null +++ b/Chapter17/demo/samples/text/build.xml @@ -0,0 +1,101 @@ + + + Shows how the pure text exporter could be used to export reports to simple text files. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter17/demo/samples/text/readme.txt b/Chapter17/demo/samples/text/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter17/demo/samples/text/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter19/demo/samples/webapp/WEB-INF/classes/datasource/WebappDataSource.java b/Chapter19/demo/samples/webapp/WEB-INF/classes/datasource/WebappDataSource.java new file mode 100644 index 0000000..458e17b --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/classes/datasource/WebappDataSource.java @@ -0,0 +1,132 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +package datasource; + +import net.sf.jasperreports.engine.JRDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRField; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: WebappDataSource.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class WebappDataSource implements JRDataSource +{ + + + /** + * + */ + private Object[][] data = + { + {"Berne", new Integer(22), "Bill Ott", "250 - 20th Ave."}, + {"Berne", new Integer(9), "James Schneider", "277 Seventh Av."}, + {"Boston", new Integer(32), "Michael Ott", "339 College Av."}, + {"Boston", new Integer(23), "Julia Heiniger", "358 College Av."}, + {"Chicago", new Integer(39), "Mary Karsen", "202 College Av."}, + {"Chicago", new Integer(35), "George Karsen", "412 College Av."}, + {"Chicago", new Integer(11), "Julia White", "412 Upland Pl."}, + {"Dallas", new Integer(47), "Janet Fuller", "445 Upland Pl."}, + {"Dallas", new Integer(43), "Susanne Smith", "2 Upland Pl."}, + {"Dallas", new Integer(40), "Susanne Miller", "440 - 20th Ave."}, + {"Dallas", new Integer(36), "John Steel", "276 Upland Pl."}, + {"Dallas", new Integer(37), "Michael Clancy", "19 Seventh Av."}, + {"Dallas", new Integer(19), "Susanne Heiniger", "86 - 20th Ave."}, + {"Dallas", new Integer(10), "Anne Fuller", "135 Upland Pl."}, + {"Dallas", new Integer(4), "Sylvia Ringer", "365 College Av."}, + {"Dallas", new Integer(0), "Laura Steel", "429 Seventh Av."}, + {"Lyon", new Integer(38), "Andrew Heiniger", "347 College Av."}, + {"Lyon", new Integer(28), "Susanne White", "74 - 20th Ave."}, + {"Lyon", new Integer(17), "Laura Ott", "443 Seventh Av."}, + {"Lyon", new Integer(2), "Anne Miller", "20 Upland Pl."}, + {"New York", new Integer(46), "Andrew May", "172 Seventh Av."}, + {"New York", new Integer(44), "Sylvia Ott", "361 College Av."}, + {"New York", new Integer(41), "Bill King", "546 College Av."}, + {"Oslo", new Integer(45), "Janet May", "396 Seventh Av."}, + {"Oslo", new Integer(42), "Robert Ott", "503 Seventh Av."}, + {"Paris", new Integer(25), "Sylvia Steel", "269 College Av."}, + {"Paris", new Integer(18), "Sylvia Fuller", "158 - 20th Ave."}, + {"Paris", new Integer(5), "Laura Miller", "294 Seventh Av."}, + {"San Francisco", new Integer(48), "Robert White", "549 Seventh Av."}, + {"San Francisco", new Integer(7), "James Peterson", "231 Upland Pl."} + }; + + private int index = -1; + + + /** + * + */ + public WebappDataSource() + { + } + + + /** + * + */ + public boolean next() throws JRException + { + index++; + + return (index < data.length); + } + + + /** + * + */ + public Object getFieldValue(JRField field) throws JRException + { + Object value = null; + + String fieldName = field.getName(); + + if ("City".equals(fieldName)) + { + value = data[index][0]; + } + else if ("Id".equals(fieldName)) + { + value = data[index][1]; + } + else if ("Name".equals(fieldName)) + { + value = data[index][2]; + } + else if ("Street".equals(fieldName)) + { + value = data[index][3]; + } + + return value; + } + + +} diff --git a/Chapter19/demo/samples/webapp/WEB-INF/classes/scriptlets/WebappScriptlet.java b/Chapter19/demo/samples/webapp/WEB-INF/classes/scriptlets/WebappScriptlet.java new file mode 100644 index 0000000..8a9d49d --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/classes/scriptlets/WebappScriptlet.java @@ -0,0 +1,71 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +package scriptlets; + +import net.sf.jasperreports.engine.JRDefaultScriptlet; +import net.sf.jasperreports.engine.JRScriptletException; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: WebappScriptlet.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class WebappScriptlet extends JRDefaultScriptlet +{ + + + /** + * + */ + public void afterGroupInit(String groupName) throws JRScriptletException + { + String allCities = (String)this.getVariableValue("AllCities"); + String city = (String)this.getFieldValue("City"); + StringBuffer sbuffer = new StringBuffer(); + + if (allCities != null) + { + sbuffer.append(allCities); + sbuffer.append(", "); + } + + sbuffer.append(city); + this.setVariableValue("AllCities", sbuffer.toString()); + } + + + /** + * + */ + public String hello() throws JRScriptletException + { + return "Hello! I'm the report's scriptlet object."; + } + + +} diff --git a/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/CompileServlet.java b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/CompileServlet.java new file mode 100644 index 0000000..86d4ffc --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/CompileServlet.java @@ -0,0 +1,106 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +package servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperCompileManager; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: CompileServlet.java 1236 2006-04-22 07:51:44Z teodord $ + */ +public class CompileServlet extends HttpServlet +{ + + + /** + * + */ + public void service( + HttpServletRequest request, + HttpServletResponse response + ) throws IOException, ServletException + { + ServletContext context = this.getServletConfig().getServletContext(); + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + try + { + JasperCompileManager.compileReportToFile(context.getRealPath("/reports/WebappReport.jrxml")); + } + catch (JRException e) + { + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("JasperReports encountered this error :"); + out.println("
    ");
    +
    +			e.printStackTrace(out);
    +
    +			out.println("
    "); + + out.println(""); + out.println(""); + + return; + } + + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("The JRXML report design was successfully compiled."); + + out.println(""); + out.println(""); + } + + +} diff --git a/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java new file mode 100644 index 0000000..5efc1d0 --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java @@ -0,0 +1,127 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +package servlets; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRRuntimeException; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.j2ee.servlets.BaseHttpServlet; +import datasource.WebappDataSource; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: FillServlet.java 1236 2006-04-22 07:51:44Z teodord $ + */ +public class FillServlet extends HttpServlet +{ + + + /** + * + */ + public void service( + HttpServletRequest request, + HttpServletResponse response + ) throws IOException, ServletException + { + ServletContext context = this.getServletConfig().getServletContext(); + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + try + { + String reportFileName = context.getRealPath("/reports/WebappReport.jasper"); + File reportFile = new File(reportFileName); + if (!reportFile.exists()) + throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("BaseDir", reportFile.getParentFile()); + + JasperPrint jasperPrint = + JasperFillManager.fillReport( + reportFileName, + parameters, + new WebappDataSource() + ); + + request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); + } + catch (JRException e) + { + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("JasperReports encountered this error :"); + out.println("
    ");
    +
    +			e.printStackTrace(out);
    +
    +			out.println("
    "); + + out.println(""); + out.println(""); + } + + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("The compiled report design was successfully filled with data."); + + out.println(""); + out.println(""); + } + + +} diff --git a/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java new file mode 100644 index 0000000..5947364 --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java @@ -0,0 +1,128 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +package servlets; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JRRuntimeException; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperReport; +import net.sf.jasperreports.engine.export.JRHtmlExporter; +import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; +import net.sf.jasperreports.engine.util.JRLoader; +import net.sf.jasperreports.j2ee.servlets.ImageServlet; +import datasource.WebappDataSource; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: HtmlServlet.java 1236 2006-04-22 07:51:44Z teodord $ + */ +public class HtmlServlet extends HttpServlet +{ + + + /** + * + */ + public void service( + HttpServletRequest request, + HttpServletResponse response + ) throws IOException, ServletException + { + ServletContext context = this.getServletConfig().getServletContext(); + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + try + { + File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper")); + if (!reportFile.exists()) + throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); + + JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("BaseDir", reportFile.getParentFile()); + + JasperPrint jasperPrint = + JasperFillManager.fillReport( + jasperReport, + parameters, + new WebappDataSource() + ); + + JRHtmlExporter exporter = new JRHtmlExporter(); + + request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); + exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); + + exporter.exportReport(); + } + catch (JRException e) + { + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("JasperReports encountered this error :"); + out.println("
    ");
    +
    +			e.printStackTrace(out);
    +
    +			out.println("
    "); + + out.println(""); + out.println(""); + } + } + + +} diff --git a/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java new file mode 100644 index 0000000..ebc05bb --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java @@ -0,0 +1,150 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +package servlets; + +import java.io.File; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRRuntimeException; +import net.sf.jasperreports.engine.JasperFillManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperReport; +import net.sf.jasperreports.engine.util.JRLoader; +import datasource.WebappDataSource; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: JasperPrintServlet.java 1236 2006-04-22 07:51:44Z teodord $ + */ +public class JasperPrintServlet extends HttpServlet +{ + + + /** + * + */ + public void service( + HttpServletRequest request, + HttpServletResponse response + ) throws IOException, ServletException + { + ServletContext context = this.getServletConfig().getServletContext(); + + File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper")); + if (!reportFile.exists()) + throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("BaseDir", reportFile.getParentFile()); + + JasperPrint jasperPrint = null; + + try + { + JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); + + jasperPrint = + JasperFillManager.fillReport( + jasperReport, + parameters, + new WebappDataSource() + ); + } + catch (JRException e) + { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("JasperReports encountered this error :"); + out.println("
    ");
    +
    +			e.printStackTrace(out);
    +
    +			out.println("
    "); + + out.println(""); + out.println(""); + + return; + } + + if (jasperPrint != null) + { + response.setContentType("application/octet-stream"); + ServletOutputStream ouputStream = response.getOutputStream(); + + ObjectOutputStream oos = new ObjectOutputStream(ouputStream); + oos.writeObject(jasperPrint); + oos.flush(); + oos.close(); + + ouputStream.flush(); + ouputStream.close(); + } + else + { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println("JasperReports - Web Application Sample"); + out.println(""); + out.println(""); + + out.println(""); + + out.println("Empty response."); + + out.println(""); + out.println(""); + } + } + + +} diff --git a/Chapter19/demo/samples/webapp/WEB-INF/web.xml b/Chapter19/demo/samples/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9bde54f --- /dev/null +++ b/Chapter19/demo/samples/webapp/WEB-INF/web.xml @@ -0,0 +1,98 @@ + + + + + + JasperReports + + + CompileServlet + servlets.CompileServlet + + + FillServlet + servlets.FillServlet + + + PdfServlet + net.sf.jasperreports.j2ee.servlets.PdfServlet + + + HtmlServlet + servlets.HtmlServlet + + + ImageServlet + net.sf.jasperreports.j2ee.servlets.ImageServlet + + + XlsServlet + net.sf.jasperreports.j2ee.servlets.XlsServlet + + + JExcelApiServlet + net.sf.jasperreports.j2ee.servlets.JExcelApiServlet + + + RtfServlet + net.sf.jasperreports.j2ee.servlets.RtfServlet + + + OdtServlet + net.sf.jasperreports.j2ee.servlets.OdtServlet + + + JasperPrintServlet + servlets.JasperPrintServlet + + + + CompileServlet + /servlets/compile + + + FillServlet + /servlets/fill + + + PdfServlet + /servlets/pdf + + + HtmlServlet + /servlets/html + + + ImageServlet + /servlets/image + + + XlsServlet + /servlets/xls + + + JExcelApiServlet + /servlets/jxl + + + RtfServlet + /servlets/rtf + + + OdtServlet + /servlets/odt + + + JasperPrintServlet + /servlets/jasperprint + + + + index.html + + + BASIC + + diff --git a/Chapter19/demo/samples/webapp/applets.html b/Chapter19/demo/samples/webapp/applets.html new file mode 100644 index 0000000..ae984af --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets.html @@ -0,0 +1,98 @@ + + + +JasperReports - Web Application Sample + + + + + + + +
    + + + + + + + + + + +
       applet viewer
    + + + + + + + +
     
    +
    + + + + + + + + + + + + +
      +
    +   +
    +
     
      + Applet Viewer +
    +
    + In this section, the reports generated on the server side will be viewed using simple Swing applets. +
    +
    + These applets make use of the core functionality of the JasperReports library that has to do with report viewing, which comes in a special JAR file called jasperreports-x.x.x-applet.jar. +
    +
    + But first, you have to make sure your browser supports Swing applets. +
    +
    + You can run Swing applets in any browser that has the appropriate version of Java Plug-in installed. Other options are to use a JDK 1.1-compliant browser that can find the Swing classes, or to use a 1.2-compliant browser. For information on setting up 1.1-compliant browsers to work with Swing, see Make Your Browser Swing, an article in The Swing Connection. +
    +
    + Click here, to test whether your browser can run Swing applets or not. +
    +
    + You should see a box that looks like the following: +
    +
    +
    + Click this figure to run the applet. +
    + This is a picture of the applet's GUI. To run the applet, click the picture. The applet will appear in a new browser window. +
    +
    +
    + If your browser passed the above test and you are able to run Swing applets with it, then you are ready to test the following JasperReports sample applets. +
    +
    + + + + + + + +
    Embedded Viewer AppletPrinter Applet
    +
    +
    +
     
    + +
    +
    +

    Copyright © 2001-2006 JasperSoft Corporation www.jaspersoft.com
    + + + diff --git a/Chapter19/demo/samples/webapp/applets/EmbeddedViewerApplet.form b/Chapter19/demo/samples/webapp/applets/EmbeddedViewerApplet.form new file mode 100644 index 0000000..e139164 --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/EmbeddedViewerApplet.form @@ -0,0 +1,20 @@ + + +
    + + + + + + + + + + + + + + + + + diff --git a/Chapter19/demo/samples/webapp/applets/EmbeddedViewerApplet.java b/Chapter19/demo/samples/webapp/applets/EmbeddedViewerApplet.java new file mode 100644 index 0000000..9c16014 --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/EmbeddedViewerApplet.java @@ -0,0 +1,111 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.awt.BorderLayout; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URL; + +import javax.swing.JOptionPane; + +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: EmbeddedViewerApplet.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class EmbeddedViewerApplet extends javax.swing.JApplet +{ + + + /** + * + */ + private JasperPrint jasperPrint = null; + + + /** Creates new form AppletViewer */ + public EmbeddedViewerApplet() + { + initComponents(); + } + + + /** + * + */ + public void init() + { + String url = getParameter("REPORT_URL"); + if (url != null) + { + try + { + jasperPrint = (JasperPrint)JRLoader.loadObject(new URL(getCodeBase(), url)); + if (jasperPrint != null) + { + JRViewerSimple viewer = new JRViewerSimple(jasperPrint); + this.pnlMain.add(viewer, BorderLayout.CENTER); + } + } + catch (Exception e) + { + StringWriter swriter = new StringWriter(); + PrintWriter pwriter = new PrintWriter(swriter); + e.printStackTrace(pwriter); + JOptionPane.showMessageDialog(this, swriter.toString()); + } + } + else + { + JOptionPane.showMessageDialog(this, "Source URL not specified"); + } + } + + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + private void initComponents() {//GEN-BEGIN:initComponents + pnlMain = new javax.swing.JPanel(); + + pnlMain.setLayout(new java.awt.BorderLayout()); + + getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER); + + }//GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel pnlMain; + // End of variables declaration//GEN-END:variables + +} diff --git a/Chapter19/demo/samples/webapp/applets/HelloSwingApplet.java b/Chapter19/demo/samples/webapp/applets/HelloSwingApplet.java new file mode 100644 index 0000000..1d27cbc --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/HelloSwingApplet.java @@ -0,0 +1,25 @@ +import javax.swing.*; +import java.awt.*; + +public class HelloSwingApplet extends JApplet +{ + + // This is a hack to avoid an ugly error message in 1.1. + public HelloSwingApplet() + { + getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); + } + + public void init() + { + JLabel label = new JLabel("You are successfully running a Swing applet!"); + label.setHorizontalAlignment(JLabel.CENTER); + + //Add border. Should use createLineBorder, but then the bottom + //and left lines don't appear -- seems to be an off-by-one error. + label.setBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, Color.black)); + + getContentPane().add(label, BorderLayout.CENTER); + } + +} diff --git a/Chapter19/demo/samples/webapp/applets/JRViewerPlus.java b/Chapter19/demo/samples/webapp/applets/JRViewerPlus.java new file mode 100644 index 0000000..decd5ac --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/JRViewerPlus.java @@ -0,0 +1,94 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import javax.swing.JButton; +import javax.swing.JOptionPane; + +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.view.JRViewer; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: JRViewerPlus.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class JRViewerPlus extends JRViewer +{ + + + /** + * + */ + protected JButton btnPlus = new javax.swing.JButton(); + + + /** + * + */ + public JRViewerPlus(JasperPrint jrPrint) throws JRException + { + super(jrPrint); + + tlbToolBar.remove(btnSave); + tlbToolBar.remove(btnReload); + + btnPlus = new javax.swing.JButton(); + btnPlus.setToolTipText("Plus..."); + btnPlus.setText("Plus..."); + btnPlus.setPreferredSize(new java.awt.Dimension(80, 23)); + btnPlus.setMaximumSize(new java.awt.Dimension(80, 23)); + btnPlus.setMinimumSize(new java.awt.Dimension(80, 23)); + btnPlus.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPlusActionPerformed(evt); + } + }); + tlbToolBar.add(btnPlus, 0); + } + + + /** + * + */ + protected void setZooms() + { + this.zooms = new int[]{33, 66, 100, 133, 166, 200, 233}; + this.defaultZoomIndex = 2; + } + + + /** + * + */ + protected void btnPlusActionPerformed(java.awt.event.ActionEvent evt) + { + JOptionPane.showMessageDialog(this, "I just wanted to let you know that you can extend the JRViewer to customize it.\n The button you have pushed was added this way."); + } + + +} diff --git a/Chapter19/demo/samples/webapp/applets/JRViewerSimple.java b/Chapter19/demo/samples/webapp/applets/JRViewerSimple.java new file mode 100644 index 0000000..5c71fdd --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/JRViewerSimple.java @@ -0,0 +1,53 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.view.JRViewer; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: JRViewerSimple.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class JRViewerSimple extends JRViewer +{ + + + /** + * + */ + public JRViewerSimple(JasperPrint jrPrint) throws JRException + { + super(jrPrint); + + tlbToolBar.remove(btnSave); + tlbToolBar.remove(btnReload); + } + + +} diff --git a/Chapter19/demo/samples/webapp/applets/PrinterApplet.form b/Chapter19/demo/samples/webapp/applets/PrinterApplet.form new file mode 100644 index 0000000..c5265b6 --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/PrinterApplet.form @@ -0,0 +1,40 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/demo/samples/webapp/applets/PrinterApplet.java b/Chapter19/demo/samples/webapp/applets/PrinterApplet.java new file mode 100644 index 0000000..673813b --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/PrinterApplet.java @@ -0,0 +1,218 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URL; + +import javax.swing.JOptionPane; + +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.util.JRLoader; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: PrinterApplet.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class PrinterApplet extends javax.swing.JApplet +{ + + + /** + * + */ + private URL url = null; + private JasperPrint jasperPrint = null; + + + /** Creates new form AppletViewer */ + public PrinterApplet() + { + initComponents(); + } + + + /** + * + */ + public void init() + { + String strUrl = getParameter("REPORT_URL"); + if (strUrl != null) + { + try + { + url = new URL(getCodeBase(), strUrl); + } + catch (Exception e) + { + StringWriter swriter = new StringWriter(); + PrintWriter pwriter = new PrintWriter(swriter); + e.printStackTrace(pwriter); + JOptionPane.showMessageDialog(this, swriter.toString()); + } + } + else + { + JOptionPane.showMessageDialog(this, "Source URL not specified"); + } + } + + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + private void initComponents() {//GEN-BEGIN:initComponents + pnlMain = new javax.swing.JPanel(); + btnPrint = new javax.swing.JButton(); + btnView = new javax.swing.JButton(); + + btnPrint.setText("Print the report"); + btnPrint.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPrintActionPerformed(evt); + } + }); + + pnlMain.add(btnPrint); + + btnView.setText("View the report"); + btnView.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnViewActionPerformed(evt); + } + }); + + pnlMain.add(btnView); + + getContentPane().add(pnlMain, java.awt.BorderLayout.WEST); + + }//GEN-END:initComponents + + protected void btnViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewActionPerformed + // Add your handling code here: + if (url != null) + { + try + { + if (jasperPrint == null) + { + jasperPrint = (JasperPrint)JRLoader.loadObject(url); + } + if (jasperPrint != null) + { + ViewerFrame viewerFrame = new ViewerFrame(this.getAppletContext(), jasperPrint); + viewerFrame.show(); + } + else + { + JOptionPane.showMessageDialog(this, "Empty report."); + } + } + catch (Exception e) + { + StringWriter swriter = new StringWriter(); + PrintWriter pwriter = new PrintWriter(swriter); + e.printStackTrace(pwriter); + JOptionPane.showMessageDialog(this, swriter.toString()); + } + } + else + { + JOptionPane.showMessageDialog(this, "Source URL not specified"); + } + }//GEN-LAST:event_btnViewActionPerformed + + protected void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed + // Add your handling code here: + if (url != null) + { + if (jasperPrint == null) + { + try + { + jasperPrint = (JasperPrint)JRLoader.loadObject(url); + } + catch (Exception e) + { + StringWriter swriter = new StringWriter(); + PrintWriter pwriter = new PrintWriter(swriter); + e.printStackTrace(pwriter); + JOptionPane.showMessageDialog(this, swriter.toString()); + } + } + + if (jasperPrint != null) + { + final JasperPrint print = jasperPrint; + + Thread thread = new Thread + ( + new Runnable() + { + public void run() + { + try + { + JasperPrintManager.printReport(print, true); + } + catch (Exception e) + { + StringWriter swriter = new StringWriter(); + PrintWriter pwriter = new PrintWriter(swriter); + e.printStackTrace(pwriter); + JOptionPane.showMessageDialog(null, swriter.toString()); + } + } + } + ); + + thread.start(); + } + else + { + JOptionPane.showMessageDialog(this, "Empty report."); + } + } + else + { + JOptionPane.showMessageDialog(this, "Source URL not specified"); + } + }//GEN-LAST:event_btnPrintActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel pnlMain; + private javax.swing.JButton btnView; + private javax.swing.JButton btnPrint; + // End of variables declaration//GEN-END:variables + +} diff --git a/Chapter19/demo/samples/webapp/applets/ViewerFrame.form b/Chapter19/demo/samples/webapp/applets/ViewerFrame.form new file mode 100644 index 0000000..e706ac8 --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/ViewerFrame.form @@ -0,0 +1,30 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/demo/samples/webapp/applets/ViewerFrame.java b/Chapter19/demo/samples/webapp/applets/ViewerFrame.java new file mode 100644 index 0000000..ba8a813 --- /dev/null +++ b/Chapter19/demo/samples/webapp/applets/ViewerFrame.java @@ -0,0 +1,130 @@ +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +import net.sf.jasperreports.engine.*; +import net.sf.jasperreports.view.*; + +import java.awt.BorderLayout; +import java.applet.AppletContext; +import java.net.*; +import javax.swing.JOptionPane; + + +/** + * @author Teodor Danciu (teodord@users.sourceforge.net) + * @version $Id: ViewerFrame.java 1229 2006-04-19 10:27:35Z teodord $ + */ +public class ViewerFrame extends javax.swing.JFrame implements JRHyperlinkListener +{ + + + /** + * + */ + private AppletContext appletContext = null; + + + /** + * + */ + public ViewerFrame(AppletContext appletContext, JasperPrint jasperPrint) throws JRException + { + initComponents(); + + this.appletContext = appletContext; + + JRViewerPlus viewer = new JRViewerPlus(jasperPrint); + viewer.addHyperlinkListener(this); + this.pnlMain.add(viewer, BorderLayout.CENTER); + } + + + /** + * + */ + public void gotoHyperlink(JRPrintHyperlink hyperlink) + { + switch(hyperlink.getHyperlinkType()) + { + case JRHyperlink.HYPERLINK_TYPE_REFERENCE : + { + try + { + this.appletContext.showDocument(new URL(hyperlink.getHyperlinkReference()), "_blank"); + } + catch (MalformedURLException e) + { + JOptionPane.showMessageDialog(this, e.getMessage()); + } + break; + } + case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR : + case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE : + { + break; + } + case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR : + case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE : + { + JOptionPane.showMessageDialog(this, "Implement your own JRHyperlinkListener to manage this type of event."); + break; + } + case JRHyperlink.HYPERLINK_TYPE_NONE : + default : + { + break; + } + } + } + + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + private void initComponents() {//GEN-BEGIN:initComponents + pnlMain = new javax.swing.JPanel(); + + setTitle("JasperViewer"); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + pnlMain.setLayout(new java.awt.BorderLayout()); + + getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER); + + pack(); + java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); + setSize(new java.awt.Dimension(400, 300)); + setLocation((screenSize.width-400)/2,(screenSize.height-300)/2); + }//GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel pnlMain; + // End of variables declaration//GEN-END:variables + +} diff --git a/Chapter19/demo/samples/webapp/build.xml b/Chapter19/demo/samples/webapp/build.xml new file mode 100644 index 0000000..441bea3 --- /dev/null +++ b/Chapter19/demo/samples/webapp/build.xml @@ -0,0 +1,110 @@ + + + Shows how reporting functionality could be added to a Web application. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Chapter19/demo/samples/webapp/compile.html b/Chapter19/demo/samples/webapp/compile.html new file mode 100644 index 0000000..98cb1e0 --- /dev/null +++ b/Chapter19/demo/samples/webapp/compile.html @@ -0,0 +1,90 @@ + + + +JasperReports - Web Application Sample + + + + + +
    + + + + + + + + + + + + +
       compile JRXML
    + + + + + + + +
     
    +
    + + + + + + + + + + + + +
      +
    +   +
    +
     
      + JRXML Report Design Compilation +
    +
    + Note that in the majority of cases, the JRXML report template compilation process is an application build-time process and not a runtime process. +
    +
    + Normally, report templates have to be compiled only once, just like we compile Java source files and then we deploy them with the application. If the report templates are not dynamic, there is no point on recompiling them at runtime. Report definitions are static and only the data supplied to them is different with every report filling operation. +
    +
    + However, sometimes applications do require runtime report template compilation, so here you can see how this can be achieved in Web environment. +
    +
    + The following example performs the compilation of the WebappReport.jrxml file and produces the WebappReport.jasper file. +
    +
    + + + + + + + + + + + + + + + +
    JSP Exampleexecutesource
    Servlet Exampleexecutesource
    +
    +
    +
     
    + +
    +
    +

    Copyright © 2001-2006 JasperSoft Corporation www.jaspersoft.com
    + + + diff --git a/Chapter19/demo/samples/webapp/export.html b/Chapter19/demo/samples/webapp/export.html new file mode 100644 index 0000000..d2da2c2 --- /dev/null +++ b/Chapter19/demo/samples/webapp/export.html @@ -0,0 +1,156 @@ + + + +JasperReports - Web Application Sample + + + + + +
    + + + + + + + + + + + + +
       export report
    + + + + + + + +
     
    +
    + + + + + + + + + + + + +
      +
    +   +
    +
     
      + Exporting Reports to Other Formats Like PDF, HTML, XLS and RTF +
    +
    + Before testing the exporting functionality exposed on this page, the report has to be already filled using the fill report menu option so that the generated net.sf.jasperreports.engine.JasperPrint be available on the HTTP session for exporting. +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    PDF Export
    Servlet Exampleexecutesource
     
    HTML Export
    JSP Exampleexecutesource
    Servlet Exampleexecutesource
    JSP Page By Page Viewerexecutesource
     
    XLS Export (POI Library)
    Servlet Exampleexecutesource
     
    XLS Export (JExcelApi Library)
    Servlet Exampleexecutesource
     
    RTF Export
    Servlet Exampleexecutesource
     
    ODT Export
    Servlet Exampleexecutesource
    +
    +
    +
     
    + +
    +
    +

    Copyright © 2001-2006 JasperSoft Corporation www.jaspersoft.com
    + + + diff --git a/Chapter19/demo/samples/webapp/fill.html b/Chapter19/demo/samples/webapp/fill.html new file mode 100644 index 0000000..a6ab745 --- /dev/null +++ b/Chapter19/demo/samples/webapp/fill.html @@ -0,0 +1,81 @@ + + + +JasperReports - Web Application Sample + + + + + +
    + + + + + + + + + + + + +
       fill report
    + + + + + + + +
     
    +
    + + + + + + + + + + + + +
      +
    +   +
    +
     
      + Filling Reports with Data +
    +
    + The servlet and the JSP below both show how a compiled report template (.jasper file) could be filled with data. They place the resulting net.sf.jasperreports.engine.JasperPrint object onto the HTTP session from where subsequent report viewing and exporting servlets and JSPs in this sample application will reuse it. +
    +
    + + + + + + + + + + + + + + + +
    JSP Exampleexecutesource
    Servlet Exampleexecutesource
    +
    +
    +
     
    + +
    +
    +

    Copyright © 2001-2006 JasperSoft Corporation www.jaspersoft.com
    + + + diff --git a/Chapter19/demo/samples/webapp/hello.html b/Chapter19/demo/samples/webapp/hello.html new file mode 100644 index 0000000..8efdec8 --- /dev/null +++ b/Chapter19/demo/samples/webapp/hello.html @@ -0,0 +1,63 @@ + + + +JasperReports - Web Application Sample + + + + + + +Hello Swing Applet +
    +
    + + + + + + + + + + + + + + + + + + + + + + +
    +Note: Because the preceding applet uses the Swing 1.1 API, it requires Java Plug-in 1.1.2 or Java Plug-in 1.2. It won't work with Java Plug-in 1.1.1 or uncustomized 1.1 browsers. For more information about running applets see the Java Tutorial. +
    + + + diff --git a/Chapter19/demo/samples/webapp/html.html b/Chapter19/demo/samples/webapp/html.html new file mode 100644 index 0000000..652cc4f --- /dev/null +++ b/Chapter19/demo/samples/webapp/html.html @@ -0,0 +1,91 @@ + + + +JasperReports - Web Application Sample + + + + + +
    + + + + + + + + + + + + +
       HTML output
    + + + + + + + +
     
    +
    + + + + + + + + + + + + +
      +
    +   +
    +
     
      + HTML Export +
    +
    + The following examples will fill the compiled report design (.jasper file) and produce HTML content on the fly, using the JasperRunManager class. +
    +
    + By using this manager class, the intermediate JasperPrint object produced by the report filling operation is not stored on disk in the .jrprint file, but directly transformed into a HTML file, accompanied by a corresponding directory containing all the images. This HTML file will then be sent to the browser. +
    +
    + + + + + + + + + + + + + + + + + + + + + + +
    JSP Exampleexecutesource
    Servlet Exampleexecutesource
    JSP Page By Page Viewerexecutesource
    +
    +
    +
     
    + +
    +
    +

    Copyright © 2001-2006 JasperSoft Corporation www.jaspersoft.com
    + + + diff --git a/Chapter19/demo/samples/webapp/images/HelloSwingApplet.gif b/Chapter19/demo/samples/webapp/images/HelloSwingApplet.gif new file mode 100644 index 0000000..8d2f32d Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/HelloSwingApplet.gif differ diff --git a/Chapter19/demo/samples/webapp/images/execute.gif b/Chapter19/demo/samples/webapp/images/execute.gif new file mode 100644 index 0000000..f64d70f Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/execute.gif differ diff --git a/Chapter19/demo/samples/webapp/images/first.GIF b/Chapter19/demo/samples/webapp/images/first.GIF new file mode 100644 index 0000000..0d5e9e7 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/first.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/first_grey.GIF b/Chapter19/demo/samples/webapp/images/first_grey.GIF new file mode 100644 index 0000000..86be71e Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/first_grey.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/jasperreports.gif b/Chapter19/demo/samples/webapp/images/jasperreports.gif new file mode 100644 index 0000000..2c230a8 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/jasperreports.gif differ diff --git a/Chapter19/demo/samples/webapp/images/last.GIF b/Chapter19/demo/samples/webapp/images/last.GIF new file mode 100644 index 0000000..a401af8 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/last.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/last_grey.GIF b/Chapter19/demo/samples/webapp/images/last_grey.GIF new file mode 100644 index 0000000..97a8d82 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/last_grey.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/next.GIF b/Chapter19/demo/samples/webapp/images/next.GIF new file mode 100644 index 0000000..6653565 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/next.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/next_grey.GIF b/Chapter19/demo/samples/webapp/images/next_grey.GIF new file mode 100644 index 0000000..d7cdae2 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/next_grey.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/previous.GIF b/Chapter19/demo/samples/webapp/images/previous.GIF new file mode 100644 index 0000000..f5d9ac0 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/previous.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/previous_grey.GIF b/Chapter19/demo/samples/webapp/images/previous_grey.GIF new file mode 100644 index 0000000..9468c6d Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/previous_grey.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/reload.GIF b/Chapter19/demo/samples/webapp/images/reload.GIF new file mode 100644 index 0000000..ad25fb2 Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/reload.GIF differ diff --git a/Chapter19/demo/samples/webapp/images/source.gif b/Chapter19/demo/samples/webapp/images/source.gif new file mode 100644 index 0000000..93af2cd Binary files /dev/null and b/Chapter19/demo/samples/webapp/images/source.gif differ diff --git a/Chapter19/demo/samples/webapp/index.html b/Chapter19/demo/samples/webapp/index.html new file mode 100644 index 0000000..f07e63b --- /dev/null +++ b/Chapter19/demo/samples/webapp/index.html @@ -0,0 +1,69 @@ + + + +JasperReports - Web Application Sample + + + + + +
    + + + + + + + + + + + + +
       home
    + + + + + + + +
     
    +
    + + + + + + + + + + + + +
      +
    +   +
    +
     
      + Web Application Sample +
    +
    + This sample Web application was created to show that the JasperReports library is perfect for using in Web environment. +
    +
    + You can see here how to generate reports on the server side using Java Server Pages or Java Servlets and how to view them on the client side, either by using Java Applets or by exporting them to PDF, HTML, XLS or RTF format. +
    +
    + Attention! Try the application menu options in the same order in which they are displayed. Otherwise, important steps involved when working with the JasperReports library might get skipped and error messages will be displayed, instead of the expected output. +
    +
    +
     
    + +
    +
    +

    Copyright © 2001-2006 JasperSoft Corporation www.jaspersoft.com
    + + + diff --git a/Chapter19/demo/samples/webapp/jsp/compile.jsp b/Chapter19/demo/samples/webapp/jsp/compile.jsp new file mode 100644 index 0000000..666bbbb --- /dev/null +++ b/Chapter19/demo/samples/webapp/jsp/compile.jsp @@ -0,0 +1,49 @@ +<%-- +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +--%> + +<%@ page errorPage="error.jsp" %> +<%@ page import="net.sf.jasperreports.engine.*,net.sf.jasperreports.engine.util.JRProperties" %> + +<% + JasperCompileManager.compileReportToFile(application.getRealPath("/reports/WebappReport.jrxml")); +%> + + + +JasperReports - Web Application Sample + + + + + +The JRXML report design was successfully compiled. + + + diff --git a/Chapter19/demo/samples/webapp/jsp/error.jsp b/Chapter19/demo/samples/webapp/jsp/error.jsp new file mode 100644 index 0000000..82a5696 --- /dev/null +++ b/Chapter19/demo/samples/webapp/jsp/error.jsp @@ -0,0 +1,48 @@ +<%-- +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +--%> + +<%@ page isErrorPage="true" %> +<%@ page import="java.io.*" %> + + + + +JasperReports - Web Application Sample + + + + + +JasperReports encountered this error : +
    +<% exception.printStackTrace(new PrintWriter(out)); %>
    +
    + + diff --git a/Chapter19/demo/samples/webapp/jsp/fill.jsp b/Chapter19/demo/samples/webapp/jsp/fill.jsp new file mode 100644 index 0000000..9d303fa --- /dev/null +++ b/Chapter19/demo/samples/webapp/jsp/fill.jsp @@ -0,0 +1,72 @@ +<%-- +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +--%> + +<%@ page errorPage="error.jsp" %> +<%@ page import="datasource.*" %> +<%@ page import="net.sf.jasperreports.engine.*" %> +<%@ page import="net.sf.jasperreports.engine.util.*" %> +<%@ page import="net.sf.jasperreports.engine.export.*" %> +<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %> +<%@ page import="java.util.*" %> +<%@ page import="java.io.*" %> + +<% + String reportFileName = application.getRealPath("/reports/WebappReport.jasper"); + File reportFile = new File(reportFileName); + if (!reportFile.exists()) + throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("BaseDir", reportFile.getParentFile()); + + JasperPrint jasperPrint = + JasperFillManager.fillReport( + reportFileName, + parameters, + new WebappDataSource() + ); + + session.setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); +%> + + + +JasperReports - Web Application Sample + + + + + +The compiled report design was successfully filled with data. + + + + diff --git a/Chapter19/demo/samples/webapp/jsp/html.jsp b/Chapter19/demo/samples/webapp/jsp/html.jsp new file mode 100644 index 0000000..bb4255d --- /dev/null +++ b/Chapter19/demo/samples/webapp/jsp/html.jsp @@ -0,0 +1,70 @@ +<%-- +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +--%> + +<%@ page errorPage="error.jsp" %> +<%@ page import="datasource.*" %> +<%@ page import="net.sf.jasperreports.engine.*" %> +<%@ page import="net.sf.jasperreports.engine.util.*" %> +<%@ page import="net.sf.jasperreports.engine.export.*" %> +<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %> +<%@ page import="java.util.*" %> +<%@ page import="java.io.*" %> + +<% + File reportFile = new File(application.getRealPath("/reports/WebappReport.jasper")); + if (!reportFile.exists()) + throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); + + JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("BaseDir", reportFile.getParentFile()); + + JasperPrint jasperPrint = + JasperFillManager.fillReport( + jasperReport, + parameters, + new WebappDataSource() + ); + + JRHtmlExporter exporter = new JRHtmlExporter(); + + StringBuffer sbuffer = new StringBuffer(); + + session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); + exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../servlets/image?image="); + + exporter.exportReport(); +%> + diff --git a/Chapter19/demo/samples/webapp/jsp/source.jsp b/Chapter19/demo/samples/webapp/jsp/source.jsp new file mode 100644 index 0000000..93b52be --- /dev/null +++ b/Chapter19/demo/samples/webapp/jsp/source.jsp @@ -0,0 +1,57 @@ +<%-- +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +--%> + +<%@ page errorPage="error.jsp" %> +<%@ page import="net.sf.jasperreports.engine.util.*" %> +<%@ page import="java.io.*" %> + + + +
    +<%
    +	String filename = request.getParameter("filename");
    +	
    +	if (filename != null)
    +	{
    +		InputStream is = new FileInputStream(application.getRealPath(filename));
    +		InputStreamReader reader = new InputStreamReader(is);
    +		
    +		int ln = 0;
    +		char[] chars = new char[1000];
    +		
    +		while((ln = reader.read(chars)) > 0)
    +		{
    +			out.print(JRStringUtil.xmlEncode(new String(chars, 0, ln)));
    +		}
    +	}
    +%>
    +
    + + diff --git a/Chapter19/demo/samples/webapp/jsp/viewer.jsp b/Chapter19/demo/samples/webapp/jsp/viewer.jsp new file mode 100644 index 0000000..1a6b1d8 --- /dev/null +++ b/Chapter19/demo/samples/webapp/jsp/viewer.jsp @@ -0,0 +1,172 @@ +<%-- +/* + * ============================================================================ + * GNU Lesser General Public License + * ============================================================================ + * + * JasperReports - Free Java report-generating library. + * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * JasperSoft Corporation + * 303 Second Street, Suite 450 North + * San Francisco, CA 94107 + * http://www.jaspersoft.com + */ +--%> + +<%@ page errorPage="error.jsp" %> +<%@ page import="datasource.*" %> +<%@ page import="net.sf.jasperreports.engine.*" %> +<%@ page import="net.sf.jasperreports.engine.util.*" %> +<%@ page import="net.sf.jasperreports.engine.export.*" %> +<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %> +<%@ page import="java.util.*" %> +<%@ page import="java.io.*" %> + +<% + JasperPrint jasperPrint = (JasperPrint)session.getAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE); + + if (request.getParameter("reload") != null || jasperPrint == null) + { + File reportFile = new File(application.getRealPath("/reports/WebappReport.jasper")); + if (!reportFile.exists()) + throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); + + JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); + + Map parameters = new HashMap(); + parameters.put("ReportTitle", "Address Report"); + parameters.put("BaseDir", reportFile.getParentFile()); + + jasperPrint = + JasperFillManager.fillReport( + jasperReport, + parameters, + new WebappDataSource() + ); + + session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); + } + + JRHtmlExporter exporter = new JRHtmlExporter(); + + int pageIndex = 0; + int lastPageIndex = 0; + if (jasperPrint.getPages() != null) + { + lastPageIndex = jasperPrint.getPages().size() - 1; + } + + String pageStr = request.getParameter("page"); + try + { + pageIndex = Integer.parseInt(pageStr); + } + catch(Exception e) + { + } + + if (pageIndex < 0) + { + pageIndex = 0; + } + + if (pageIndex > lastPageIndex) + { + pageIndex = lastPageIndex; + } + + StringBuffer sbuffer = new StringBuffer(); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer); + exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../servlets/image?image="); + exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); + exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, ""); + exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, ""); + exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, ""); + + exporter.exportReport(); +%> + + + + + + + + + + + + + + + + + + +
      +
    + + + + +<% + if (pageIndex > 0) + { +%> + + +<% + } + else + { +%> + + +<% + } + + if (pageIndex < lastPageIndex) + { +%> + + +<% + } + else + { +%> + + +<% + } +%> + + +
        
    +
    +
     
      + +<%=sbuffer.toString()%> + +  
    + + diff --git a/Chapter19/demo/samples/webapp/printer.html b/Chapter19/demo/samples/webapp/printer.html new file mode 100644 index 0000000..e462d58 --- /dev/null +++ b/Chapter19/demo/samples/webapp/printer.html @@ -0,0 +1,62 @@ + + + +JasperReports - Web Application Sample + + + + + +Printer Applet +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Note: Because the preceding applet uses the Swing 1.1 API, it requires Java Plug-in 1.1.2 or Java Plug-in 1.2. It won't work with Java Plug-in 1.1.1 or uncustomized 1.1 browsers. For more information about running applets see the Java Tutorial. +
    + + + diff --git a/Chapter19/demo/samples/webapp/readme.txt b/Chapter19/demo/samples/webapp/readme.txt new file mode 100644 index 0000000..880564d --- /dev/null +++ b/Chapter19/demo/samples/webapp/readme.txt @@ -0,0 +1,9 @@ + +You need to have the ANT build tool correctly installed on your system +to easily run this sample application. This tool can be downloaded from +this location: http://ant.apache.org/ +Please follow their installing instructions to have ANT working on your +system before trying our sample application. + +Once you have ANT installed, launch "ant -p" from the command line in this directory +to learn more about what tasks you could run to build and test the sample. diff --git a/Chapter19/demo/samples/webapp/reports/WebappReport.jrxml b/Chapter19/demo/samples/webapp/reports/WebappReport.jrxml new file mode 100644 index 0000000..fd0323f --- /dev/null +++ b/Chapter19/demo/samples/webapp/reports/WebappReport.jrxml @@ -0,0 +1,166 @@ + + + + +