");
+
+ 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/Chapter04/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java b/Chapter04/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java
new file mode 100644
index 0000000..5efc1d0
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java b/Chapter04/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java
new file mode 100644
index 0000000..5947364
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java b/Chapter04/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java
new file mode 100644
index 0000000..ebc05bb
--- /dev/null
+++ b/Chapter04/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("
+ 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:
+
+
+
+
+
+ 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.
+
+
+
+
+
+
diff --git a/Chapter04/demo/samples/webapp/applets/EmbeddedViewerApplet.form b/Chapter04/demo/samples/webapp/applets/EmbeddedViewerApplet.form
new file mode 100644
index 0000000..e139164
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/applets/EmbeddedViewerApplet.form
@@ -0,0 +1,20 @@
+
+
+
diff --git a/Chapter04/demo/samples/webapp/applets/EmbeddedViewerApplet.java b/Chapter04/demo/samples/webapp/applets/EmbeddedViewerApplet.java
new file mode 100644
index 0000000..9c16014
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/applets/HelloSwingApplet.java b/Chapter04/demo/samples/webapp/applets/HelloSwingApplet.java
new file mode 100644
index 0000000..1d27cbc
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/applets/JRViewerPlus.java b/Chapter04/demo/samples/webapp/applets/JRViewerPlus.java
new file mode 100644
index 0000000..decd5ac
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/applets/JRViewerSimple.java b/Chapter04/demo/samples/webapp/applets/JRViewerSimple.java
new file mode 100644
index 0000000..5c71fdd
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/applets/PrinterApplet.form b/Chapter04/demo/samples/webapp/applets/PrinterApplet.form
new file mode 100644
index 0000000..c5265b6
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/applets/PrinterApplet.form
@@ -0,0 +1,40 @@
+
+
+
diff --git a/Chapter04/demo/samples/webapp/applets/PrinterApplet.java b/Chapter04/demo/samples/webapp/applets/PrinterApplet.java
new file mode 100644
index 0000000..673813b
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/applets/ViewerFrame.form b/Chapter04/demo/samples/webapp/applets/ViewerFrame.form
new file mode 100644
index 0000000..e706ac8
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/applets/ViewerFrame.form
@@ -0,0 +1,30 @@
+
+
+
diff --git a/Chapter04/demo/samples/webapp/applets/ViewerFrame.java b/Chapter04/demo/samples/webapp/applets/ViewerFrame.java
new file mode 100644
index 0000000..ba8a813
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/build.xml b/Chapter04/demo/samples/webapp/build.xml
new file mode 100644
index 0000000..441bea3
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/build.xml
@@ -0,0 +1,110 @@
+
+
+ Shows how reporting functionality could be added to a Web application.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter04/demo/samples/webapp/compile.html b/Chapter04/demo/samples/webapp/compile.html
new file mode 100644
index 0000000..98cb1e0
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/compile.html
@@ -0,0 +1,90 @@
+
+
+
+JasperReports - Web Application Sample
+
+
+
+
+
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+
+
+
diff --git a/Chapter04/demo/samples/webapp/jsp/compile.jsp b/Chapter04/demo/samples/webapp/jsp/compile.jsp
new file mode 100644
index 0000000..666bbbb
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/jsp/error.jsp b/Chapter04/demo/samples/webapp/jsp/error.jsp
new file mode 100644
index 0000000..82a5696
--- /dev/null
+++ b/Chapter04/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 :
+
+
+
diff --git a/Chapter04/demo/samples/webapp/jsp/fill.jsp b/Chapter04/demo/samples/webapp/jsp/fill.jsp
new file mode 100644
index 0000000..9d303fa
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/jsp/html.jsp b/Chapter04/demo/samples/webapp/jsp/html.jsp
new file mode 100644
index 0000000..bb4255d
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/jsp/source.jsp b/Chapter04/demo/samples/webapp/jsp/source.jsp
new file mode 100644
index 0000000..93b52be
--- /dev/null
+++ b/Chapter04/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/Chapter04/demo/samples/webapp/jsp/viewer.jsp b/Chapter04/demo/samples/webapp/jsp/viewer.jsp
new file mode 100644
index 0000000..1a6b1d8
--- /dev/null
+++ b/Chapter04/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();
+%>
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter04/demo/samples/webapp/stylesheet.css b/Chapter04/demo/samples/webapp/stylesheet.css
new file mode 100644
index 0000000..1129168
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/stylesheet.css
@@ -0,0 +1,170 @@
+.menu
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#FFFFFF;
+ background:#999999;
+ text-decoration:none
+}
+
+.menu:hover
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+ background:#999999;
+ text-decoration:none
+}
+
+.mnew
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#990000;
+ background:#999999;
+ text-decoration:none
+}
+
+.header
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#FFFFFF;
+ background:#808080;
+}
+
+.doc
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:12pt;
+ font-weight:bold;
+ color:#000000;
+ background:#808080;
+}
+
+.title
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#000000;
+}
+
+.bold
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#000000;
+}
+
+.bnew
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#990000;
+}
+
+.elem
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#000000;
+ background:#EEEEEE;
+}
+
+.attr
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ font-style:italic;
+ color:#000000;
+}
+
+.val
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-style:italic;
+ color:#000000;
+}
+
+.normal
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+}
+
+.justify
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+ text-align:justify;
+}
+
+.desc
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+}
+
+.notImpl
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ color:#FF0000;
+}
+
+.note
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:8pt;
+ font-style:italic;
+ color:#000000;
+}
+
+.small
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:8pt;
+ color:#000000;
+}
+
+.version
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:8pt;
+ font-style:italic;
+ color:#FFFFFF;
+}
diff --git a/Chapter04/demo/samples/webapp/viewer.html b/Chapter04/demo/samples/webapp/viewer.html
new file mode 100644
index 0000000..ed90f90
--- /dev/null
+++ b/Chapter04/demo/samples/webapp/viewer.html
@@ -0,0 +1,62 @@
+
+
+
+JasperReports - Web Application Sample
+
+
+
+
+
+Embedded Viewer 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/Chapter05/demo/samples/virtualizer/VirtualizerApp.java b/Chapter05/demo/samples/virtualizer/VirtualizerApp.java
new file mode 100644
index 0000000..b6d3524
--- /dev/null
+++ b/Chapter05/demo/samples/virtualizer/VirtualizerApp.java
@@ -0,0 +1,234 @@
+/*
+ * ============================================================================
+ * 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.HashMap;
+import java.util.Map;
+
+import net.sf.jasperreports.engine.JRDataSource;
+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.JasperPrintManager;
+import net.sf.jasperreports.engine.export.JRCsvExporter;
+import net.sf.jasperreports.engine.fill.JRFileVirtualizer;
+import net.sf.jasperreports.view.JasperViewer;
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: VirtualizerApp.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class VirtualizerApp
+{
+
+ /**
+ *
+ */
+ 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_CSV = "csv";
+
+ private static final String TASK_VIEW = "view";
+
+ private static final String TASK_EXPORT = "export";
+
+ /**
+ *
+ */
+ public static void main(String[] args)
+ {
+ String fileName = null;
+ String outFileName = 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);
+ else if (args[k].startsWith("-F"))
+ fileName = args[k].substring(2);
+ else if (args[k].startsWith("-O"))
+ outFileName = args[k].substring(2);
+
+ k++;
+ }
+
+ try
+ {
+ // Virtualization works only with in memory JasperPrint objects.
+ // All the operations will first fill the report and then export
+ // the filled object.
+
+ // creating the data source
+ JRDataSource ds = new JREmptyDataSource(1000);
+
+ // creating the virtualizer
+ JRFileVirtualizer virtualizer = new JRFileVirtualizer(2, "tmp");
+
+ // filling the report
+ JasperPrint jasperPrint = fillReport(fileName, ds, virtualizer);
+
+
+ if (TASK_PRINT.equals(taskName))
+ {
+ JasperPrintManager.printReport(jasperPrint, true);
+ }
+ else if (TASK_PDF.equals(taskName))
+ {
+ exportPDF(outFileName, jasperPrint);
+ }
+ else if (TASK_XML.equals(taskName))
+ {
+ exportXML(outFileName, jasperPrint, false);
+ }
+ else if (TASK_XML_EMBED.equals(taskName))
+ {
+ exportXML(outFileName, jasperPrint, true);
+ }
+ else if (TASK_HTML.equals(taskName))
+ {
+ exportHTML(outFileName, jasperPrint);
+ }
+ else if (TASK_CSV.equals(taskName))
+ {
+ exportCSV(outFileName, jasperPrint);
+ }
+ else if (TASK_EXPORT.equals(taskName))
+ {
+ exportPDF(outFileName + ".pdf", jasperPrint);
+ exportXML(outFileName + ".jrpxml", jasperPrint, false);
+ exportHTML(outFileName + ".html", jasperPrint);
+ exportCSV(outFileName + ".csv", jasperPrint);
+
+ // manually cleaning up
+ virtualizer.cleanup();
+ }
+ else if (TASK_VIEW.equals(taskName))
+ {
+ JasperViewer.viewReport(jasperPrint, true);
+ }
+ else
+ {
+ usage();
+ System.exit(0);
+ }
+ }
+ catch (JRException e)
+ {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ private static void exportCSV(String outFileName, JasperPrint jasperPrint) throws JRException
+ {
+ long start = System.currentTimeMillis();
+ JRCsvExporter exporter = new JRCsvExporter();
+
+ exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
+ exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName);
+
+ exporter.exportReport();
+
+ System.err.println("CSV creation time : " + (System.currentTimeMillis() - start));
+ }
+
+ private static void exportHTML(String outFileName, JasperPrint jasperPrint) throws JRException
+ {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToHtmlFile(jasperPrint, outFileName);
+ System.err.println("HTML creation time : " + (System.currentTimeMillis() - start));
+ }
+
+ private static void exportXML(String outFileName, JasperPrint jasperPrint, boolean embedded) throws JRException
+ {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToXmlFile(jasperPrint, outFileName, embedded);
+ System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
+ }
+
+ private static void exportPDF(String outFileName, JasperPrint jasperPrint) throws JRException
+ {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToPdfFile(jasperPrint, outFileName);
+ System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));
+ }
+
+
+
+ private static JasperPrint fillReport(String fileName, JRDataSource dataSource, JRFileVirtualizer virtualizer) throws JRException
+ {
+ long start = System.currentTimeMillis();
+
+ // Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
+
+ JasperPrint jasperPrint = JasperFillManager.fillReport(fileName, parameters, dataSource);
+
+ virtualizer.setReadOnly(true);
+
+ System.err.println("Filling time : " + (System.currentTimeMillis() - start));
+ return jasperPrint;
+ }
+
+ /**
+ *
+ */
+ private static void usage()
+ {
+ System.out.println("VirtualizerApp usage:");
+ System.out.println("\tjava VirtualizerApp -Ttask -Ffile");
+ System.out.println("\tTasks : print | pdf | xml | xmlEmbed | html | csv | export | view");
+ }
+
+}
diff --git a/Chapter05/demo/samples/virtualizer/VirtualizerReport.jrxml b/Chapter05/demo/samples/virtualizer/VirtualizerReport.jrxml
new file mode 100644
index 0000000..ea93b03
--- /dev/null
+++ b/Chapter05/demo/samples/virtualizer/VirtualizerReport.jrxml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter05/demo/samples/virtualizer/build.xml b/Chapter05/demo/samples/virtualizer/build.xml
new file mode 100644
index 0000000..c0e909c
--- /dev/null
+++ b/Chapter05/demo/samples/virtualizer/build.xml
@@ -0,0 +1,140 @@
+
+
+ Shows how very large reports could be generated using a report virtualizer to optimize memory consumption.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter05/demo/samples/virtualizer/readme.txt b/Chapter05/demo/samples/virtualizer/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter05/demo/samples/virtualizer/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/Chapter05/demo/samples/virtualizer/tmp/readme.txt b/Chapter05/demo/samples/virtualizer/tmp/readme.txt
new file mode 100644
index 0000000..847f104
--- /dev/null
+++ b/Chapter05/demo/samples/virtualizer/tmp/readme.txt
@@ -0,0 +1 @@
+This is where the virtualizer will serialize the pages.
\ No newline at end of file
diff --git a/Chapter06/demo/samples/datasource/CustomBean.java b/Chapter06/demo/samples/datasource/CustomBean.java
new file mode 100644
index 0000000..be3aa96
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/CustomBean.java
@@ -0,0 +1,109 @@
+/*
+ * ============================================================================
+ * 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
+ */
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: CustomBean.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class CustomBean
+{
+
+
+ /**
+ *
+ */
+ private String city = null;
+ private Integer id = null;
+ private String name = null;
+ private String street = null;
+
+
+ /**
+ *
+ */
+ public CustomBean(
+ String pcity,
+ Integer pid,
+ String pname,
+ String pstreet
+ )
+ {
+ city = pcity;
+ id = pid;
+ name = pname;
+ street = pstreet;
+ }
+
+
+ /**
+ *
+ */
+ public CustomBean getMe()
+ {
+ return this;
+ }
+
+
+ /**
+ *
+ */
+ public String getCity()
+ {
+ return city;
+ }
+
+
+ /**
+ *
+ */
+ public Integer getId()
+ {
+ return id;
+ }
+
+
+ /**
+ *
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+
+ /**
+ *
+ */
+ public String getStreet()
+ {
+ return street;
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/datasource/CustomBeanFactory.java b/Chapter06/demo/samples/datasource/CustomBeanFactory.java
new file mode 100644
index 0000000..1ccd76e
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/CustomBeanFactory.java
@@ -0,0 +1,97 @@
+/*
+ * ============================================================================
+ * 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.Arrays;
+import java.util.Collection;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: CustomBeanFactory.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class CustomBeanFactory
+{
+
+
+ /**
+ *
+ */
+ private static CustomBean[] data =
+ {
+ new CustomBean("Berne", new Integer(9), "James Schneider", "277 Seventh Av."),
+ new CustomBean("Berne", new Integer(22), "Bill Ott", "250 - 20th Ave."),
+ new CustomBean("Boston", new Integer(23), "Julia Heiniger", "358 College Av."),
+ new CustomBean("Boston", new Integer(32), "Michael Ott", "339 College Av."),
+ new CustomBean("Chicago", new Integer(39), "Mary Karsen", "202 College Av."),
+ new CustomBean("Chicago", new Integer(35), "George Karsen", "412 College Av."),
+ new CustomBean("Chicago", new Integer(11), "Julia White", "412 Upland Pl."),
+ new CustomBean("Dallas", new Integer(47), "Janet Fuller", "445 Upland Pl."),
+ new CustomBean("Dallas", new Integer(43), "Susanne Smith", "2 Upland Pl."),
+ new CustomBean("Dallas", new Integer(40), "Susanne Miller", "440 - 20th Ave."),
+ new CustomBean("Dallas", new Integer(36), "John Steel", "276 Upland Pl."),
+ new CustomBean("Dallas", new Integer(37), "Michael Clancy", "19 Seventh Av."),
+ new CustomBean("Dallas", new Integer(19), "Susanne Heiniger", "86 - 20th Ave."),
+ new CustomBean("Dallas", new Integer(10), "Anne Fuller", "135 Upland Pl."),
+ new CustomBean("Dallas", new Integer(4), "Sylvia Ringer", "365 College Av."),
+ new CustomBean("Dallas", new Integer(0), "Laura Steel", "429 Seventh Av."),
+ new CustomBean("Lyon", new Integer(38), "Andrew Heiniger", "347 College Av."),
+ new CustomBean("Lyon", new Integer(28), "Susanne White", "74 - 20th Ave."),
+ new CustomBean("Lyon", new Integer(17), "Laura Ott", "443 Seventh Av."),
+ new CustomBean("Lyon", new Integer(2), "Anne Miller", "20 Upland Pl."),
+ new CustomBean("New York", new Integer(46), "Andrew May", "172 Seventh Av."),
+ new CustomBean("New York", new Integer(44), "Sylvia Ott", "361 College Av."),
+ new CustomBean("New York", new Integer(41), "Bill King", "546 College Av."),
+ new CustomBean("Oslo", new Integer(45), "Janet May", "396 Seventh Av."),
+ new CustomBean("Oslo", new Integer(42), "Robert Ott", "503 Seventh Av."),
+ new CustomBean("Paris", new Integer(25), "Sylvia Steel", "269 College Av."),
+ new CustomBean("Paris", new Integer(18), "Sylvia Fuller", "158 - 20th Ave."),
+ new CustomBean("Paris", new Integer(5), "Laura Miller", "294 Seventh Av."),
+ new CustomBean("San Francisco", new Integer(48), "Robert White", "549 Seventh Av."),
+ new CustomBean("San Francisco", new Integer(7), "James Peterson", "231 Upland Pl.")
+ };
+
+
+ /**
+ *
+ */
+ public static Object[] getBeanArray()
+ {
+ return data;
+ }
+
+
+ /**
+ *
+ */
+ public static Collection getBeanCollection()
+ {
+ return Arrays.asList(data);
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/datasource/CustomDataSource.java b/Chapter06/demo/samples/datasource/CustomDataSource.java
new file mode 100644
index 0000000..44971fb
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/CustomDataSource.java
@@ -0,0 +1,131 @@
+/*
+ * ============================================================================
+ * 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.JRDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JRField;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: CustomDataSource.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class CustomDataSource 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 CustomDataSource()
+ {
+ }
+
+
+ /**
+ *
+ */
+ 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 ("the_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/Chapter06/demo/samples/datasource/CustomTableModel.java b/Chapter06/demo/samples/datasource/CustomTableModel.java
new file mode 100644
index 0000000..27fc078
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/CustomTableModel.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
+ */
+
+import javax.swing.table.AbstractTableModel;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: CustomTableModel.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class CustomTableModel extends AbstractTableModel
+{
+
+
+ /**
+ *
+ */
+ private String[] columnNames = {"the_city", "id", "name", "street"};
+
+ /**
+ *
+ */
+ private Object[][] data =
+ {
+ {"Berne", new Integer(9), "James Schneider", "277 Seventh Av."},
+ {"Berne", new Integer(22), "Bill Ott", "250 - 20th Ave."},
+ {"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."}
+ };
+
+
+ /**
+ *
+ */
+ public CustomTableModel()
+ {
+ }
+
+
+ /**
+ *
+ */
+ public int getColumnCount()
+ {
+ return this.columnNames.length;
+ }
+
+
+ /**
+ *
+ */
+ public String getColumnName(int columnIndex)
+ {
+ return this.columnNames[columnIndex];
+ }
+
+
+ /**
+ *
+ */
+ public int getRowCount()
+ {
+ return this.data.length;
+ }
+
+
+ /**
+ *
+ */
+ public Object getValueAt(int rowIndex, int columnIndex)
+ {
+ return this.data[rowIndex][columnIndex];
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/datasource/DataSourceApp.java b/Chapter06/demo/samples/datasource/DataSourceApp.java
new file mode 100644
index 0000000..4d88e60
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/DataSourceApp.java
@@ -0,0 +1,313 @@
+/*
+ * ============================================================================
+ * 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.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.data.JRBeanArrayDataSource;
+import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
+import net.sf.jasperreports.engine.data.JRTableModelDataSource;
+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: DataSourceApp.java 1653 2007-03-23 08:57:13Z teodord $
+ */
+public class DataSourceApp
+{
+
+
+ /**
+ *
+ */
+ private static final String TASK_FILL_1 = "fill1";
+ private static final String TASK_FILL_2 = "fill2";
+ private static final String TASK_FILL_3 = "fill3";
+ private static final String TASK_FILL_4 = "fill4";
+ 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_1.equals(taskName))
+ {
+ //Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put("ReportTitle", "Address Report");
+ parameters.put("DataFile", "CustomDataSource.java");
+
+ JasperFillManager.fillReportToFile(fileName, parameters, new CustomDataSource());
+ System.err.println("Filling time : " + (System.currentTimeMillis() - start));
+ System.exit(0);
+ }
+ else if (TASK_FILL_2.equals(taskName))
+ {
+ //Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put("ReportTitle", "Address Report");
+ parameters.put("DataFile", "CustomTableModel.java");
+
+ JasperFillManager.fillReportToFile(fileName, parameters, new JRTableModelDataSource(new CustomTableModel()));
+ System.err.println("Filling time : " + (System.currentTimeMillis() - start));
+ System.exit(0);
+ }
+ else if (TASK_FILL_3.equals(taskName))
+ {
+ //Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put("ReportTitle", "Address Report");
+ parameters.put("DataFile", "CustomBeanFactory.java - Bean Array");
+
+ JasperFillManager.fillReportToFile(fileName, parameters, new JRBeanArrayDataSource(CustomBeanFactory.getBeanArray()));
+ System.err.println("Filling time : " + (System.currentTimeMillis() - start));
+ System.exit(0);
+ }
+ else if (TASK_FILL_4.equals(taskName))
+ {
+ //Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put("ReportTitle", "Address Report");
+ parameters.put("DataFile", "CustomBeanFactory.java - Bean Collection");
+
+ JasperFillManager.fillReportToFile(fileName, parameters, new JRBeanCollectionDataSource(CustomBeanFactory.getBeanCollection()));
+ 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);
+
+ 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");
+
+ JasperRunManager.runReportToPdfFile(fileName, parameters, new CustomDataSource());
+ 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( "DataSourceApp usage:" );
+ System.out.println( "\tjava DataSourceApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill1 | fill2 | fill3 | fill4 | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" );
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/datasource/DataSourceReport.jrxml b/Chapter06/demo/samples/datasource/DataSourceReport.jrxml
new file mode 100644
index 0000000..c396873
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/DataSourceReport.jrxml
@@ -0,0 +1,162 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ me.me.city
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/datasource/build.xml b/Chapter06/demo/samples/datasource/build.xml
new file mode 100644
index 0000000..77c16d9
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/build.xml
@@ -0,0 +1,207 @@
+
+
+ Shows how custom or JavaBean-based data sources implementation could be used to fill reports.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/datasource/readme.txt b/Chapter06/demo/samples/datasource/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter06/demo/samples/datasource/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/fonts/FontsApp.java b/Chapter06/demo/samples/fonts/FontsApp.java
new file mode 100644
index 0000000..fac3e46
--- /dev/null
+++ b/Chapter06/demo/samples/fonts/FontsApp.java
@@ -0,0 +1,323 @@
+/*
+ * ============================================================================
+ * 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 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.JRHtmlExporter;
+import net.sf.jasperreports.engine.export.JRPdfExporter;
+import net.sf.jasperreports.engine.export.FontKey;
+import net.sf.jasperreports.engine.export.PdfFont;
+import net.sf.jasperreports.engine.export.oasis.JROdtExporter;
+import net.sf.jasperreports.engine.util.JRLoader;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: FontsApp.java 1644 2007-03-20 09:57:51Z teodord $
+ */
+public class FontsApp
+{
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperFillManager.fillReportToFile(fileName, null, 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))
+ {
+ File sourceFile = new File(fileName);
+
+ JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
+
+ File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pdf");
+
+ JRPdfExporter exporter = new JRPdfExporter();
+
+ HashMap fontMap = new HashMap();
+ FontKey key = new FontKey("Comic Sans MS", true, false);
+ PdfFont font = new PdfFont("COMICBD.TTF", "Cp1252", true);
+ fontMap.put(key, font);
+
+ exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
+ exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
+ exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);
+
+ exporter.exportReport();
+
+ 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))
+ {
+ File sourceFile = new File(fileName);
+
+ JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
+
+ File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".html");
+
+ JRHtmlExporter exporter = new JRHtmlExporter();
+
+ HashMap fontMap = new HashMap();
+ fontMap.put("sansserif", "Arial, Verdana, Tahoma");
+ fontMap.put("serif", "Times New Roman");
+ fontMap.put("monospaced", "Courier, Courier New");
+
+ exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
+ exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
+ exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);
+
+ exporter.exportReport();
+
+ 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");
+
+ HashMap fontMap = new HashMap();
+ fontMap.put("sansserif", "Arial");
+ fontMap.put("serif", "Times New Roman");
+ fontMap.put("monospaced", "Courier");
+
+ JRRtfExporter exporter = new JRRtfExporter();
+
+ exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
+ exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
+ exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);
+
+ 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);
+
+ JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
+
+ File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls");
+
+ JRXlsExporter exporter = new JRXlsExporter();
+
+ HashMap fontMap = new HashMap();
+ fontMap.put("sansserif", "Arial");
+ fontMap.put("serif", "Times New Roman");
+ fontMap.put("monospaced", "Courier");
+
+ 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(JRExporterParameter.FONT_MAP, fontMap);
+
+ 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();
+
+ HashMap fontMap = new HashMap();
+ fontMap.put("sansserif", "Arial");
+ fontMap.put("serif", "Times New Roman");
+ fontMap.put("monospaced", "Courier");
+
+ 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(JRExporterParameter.FONT_MAP, fontMap);
+
+ 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))
+ {
+ JasperRunManager.runReportToPdfFile(fileName, null, 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( "FontsApp usage:" );
+ System.out.println( "\tjava FontsApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" );
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/fonts/FontsReport.jrxml b/Chapter06/demo/samples/fonts/FontsReport.jrxml
new file mode 100644
index 0000000..e28d2b4
--- /dev/null
+++ b/Chapter06/demo/samples/fonts/FontsReport.jrxml
@@ -0,0 +1,151 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
+
+
+
+
+
+
+
+ The quick brown fox jumps over the lazy dog.]]>
+
+
+
+
diff --git a/Chapter06/demo/samples/fonts/build.xml b/Chapter06/demo/samples/fonts/build.xml
new file mode 100644
index 0000000..b07f7f2
--- /dev/null
+++ b/Chapter06/demo/samples/fonts/build.xml
@@ -0,0 +1,183 @@
+
+
+ Shows how to work with fonts.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/fonts/jasperreports.properties b/Chapter06/demo/samples/fonts/jasperreports.properties
new file mode 100644
index 0000000..42e8255
--- /dev/null
+++ b/Chapter06/demo/samples/fonts/jasperreports.properties
@@ -0,0 +1,7 @@
+# Locations of font files can be specified.
+# As the PDF font name you can use the font name or the suffix of the key (e.g. Arial.Slanted).
+net.sf.jasperreports.export.pdf.font.Arial.Bold=../fonts/ARIALBD.TTF
+net.sf.jasperreports.export.pdf.font.Arial.Slanted=../fonts/ARIALI.TTF
+
+# Also font directories can be specified.
+# net.sf.jasperreports.export.pdf.fontdir.jasper=../fonts
diff --git a/Chapter06/demo/samples/fonts/readme.txt b/Chapter06/demo/samples/fonts/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter06/demo/samples/fonts/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/images/1redpixel.gif b/Chapter06/demo/samples/images/1redpixel.gif
new file mode 100644
index 0000000..2eb5c83
Binary files /dev/null and b/Chapter06/demo/samples/images/1redpixel.gif differ
diff --git a/Chapter06/demo/samples/images/ImagesApp.java b/Chapter06/demo/samples/images/ImagesApp.java
new file mode 100644
index 0000000..048e4ce
--- /dev/null
+++ b/Chapter06/demo/samples/images/ImagesApp.java
@@ -0,0 +1,264 @@
+/*
+ * ============================================================================
+ * 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 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: ImagesApp.java 1644 2007-03-20 09:57:51Z teodord $
+ */
+public class ImagesApp
+{
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperFillManager.fillReportToFile(fileName, null, 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_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);
+
+ 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))
+ {
+ JasperRunManager.runReportToPdfFile(fileName, null, 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( "ImagesApp usage:" );
+ System.out.println( "\tjava ImagesApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" );
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/images/ImagesReport.jrxml b/Chapter06/demo/samples/images/ImagesReport.jrxml
new file mode 100644
index 0000000..65fc320
--- /dev/null
+++ b/Chapter06/demo/samples/images/ImagesReport.jrxml
@@ -0,0 +1,174 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "http://jasperreports.sourceforge.net/jasperreports.png"]]>
+
+
+
+
+
+
+
+
+
+ "dukesign.jpg"]]>
+
+
+
+
+
+
+
+
+
+ "dukesign.jpg"]]>
+
+
+
+
+
+
+
+
+
+ "dukesign.jpg"]]>
+
+
+
+
+
+
+
+
+
+ "dukesign.jpg"]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+ "transparent.gif"]]>
+
+
+
+
+
+
+
+
+
+ "1redpixel.gif"]]>
+
+
+
+
diff --git a/Chapter06/demo/samples/images/build.xml b/Chapter06/demo/samples/images/build.xml
new file mode 100644
index 0000000..fa6f9d4
--- /dev/null
+++ b/Chapter06/demo/samples/images/build.xml
@@ -0,0 +1,183 @@
+
+
+ Shows how images could be used in a report tempalte.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/images/dukesign.jpg b/Chapter06/demo/samples/images/dukesign.jpg
new file mode 100644
index 0000000..5d74327
Binary files /dev/null and b/Chapter06/demo/samples/images/dukesign.jpg differ
diff --git a/Chapter06/demo/samples/images/readme.txt b/Chapter06/demo/samples/images/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter06/demo/samples/images/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/images/transparent.gif b/Chapter06/demo/samples/images/transparent.gif
new file mode 100644
index 0000000..793d3e4
Binary files /dev/null and b/Chapter06/demo/samples/images/transparent.gif differ
diff --git a/Chapter06/demo/samples/noxmldesign/NoXmlDesignApp.java b/Chapter06/demo/samples/noxmldesign/NoXmlDesignApp.java
new file mode 100644
index 0000000..d43d1cf
--- /dev/null
+++ b/Chapter06/demo/samples/noxmldesign/NoXmlDesignApp.java
@@ -0,0 +1,656 @@
+/*
+ * ============================================================================
+ * 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.Color;
+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.JRAlignment;
+import net.sf.jasperreports.engine.JRElement;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JRExporterParameter;
+import net.sf.jasperreports.engine.JRVariable;
+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.design.JRDesignBand;
+import net.sf.jasperreports.engine.design.JRDesignExpression;
+import net.sf.jasperreports.engine.design.JRDesignField;
+import net.sf.jasperreports.engine.design.JRDesignGroup;
+import net.sf.jasperreports.engine.design.JRDesignLine;
+import net.sf.jasperreports.engine.design.JRDesignParameter;
+import net.sf.jasperreports.engine.design.JRDesignQuery;
+import net.sf.jasperreports.engine.design.JRDesignRectangle;
+import net.sf.jasperreports.engine.design.JRDesignStaticText;
+import net.sf.jasperreports.engine.design.JRDesignStyle;
+import net.sf.jasperreports.engine.design.JRDesignTextField;
+import net.sf.jasperreports.engine.design.JRDesignVariable;
+import net.sf.jasperreports.engine.design.JasperDesign;
+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: NoXmlDesignApp.java 1665 2007-03-26 09:53:29Z teodord $
+ */
+public class NoXmlDesignApp
+{
+
+
+ /**
+ *
+ */
+ 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_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";
+ private static final String TASK_WRITE_XML = "writeXml";
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperDesign jasperDesign = getJasperDesign();
+ JasperCompileManager.compileReportToFile(jasperDesign, 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("OrderByClause", "ORDER BY 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_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");
+ parameters.put("OrderByClause", "ORDER BY City");
+
+ JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection());
+ System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
+ System.exit(0);
+ }
+ else if (TASK_WRITE_XML.equals(taskName))
+ {
+ JasperCompileManager.writeReportToXmlFile(fileName);
+ System.err.println("XML design 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( "NoXmlDesignApp usage:" );
+ System.out.println( "\tjava NoXmlDesignApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : compile | fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run | writeXml" );
+ }
+
+
+ /**
+ *
+ */
+ 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;
+ }
+
+
+ /**
+ *
+ */
+ private static JasperDesign getJasperDesign() throws JRException
+ {
+ //JasperDesign
+ JasperDesign jasperDesign = new JasperDesign();
+ jasperDesign.setName("NoXmlDesignReport");
+ jasperDesign.setPageWidth(595);
+ jasperDesign.setPageHeight(842);
+ jasperDesign.setColumnWidth(515);
+ jasperDesign.setColumnSpacing(0);
+ jasperDesign.setLeftMargin(40);
+ jasperDesign.setRightMargin(40);
+ jasperDesign.setTopMargin(50);
+ jasperDesign.setBottomMargin(50);
+
+ //Fonts
+ JRDesignStyle normalStyle = new JRDesignStyle();
+ normalStyle.setName("Arial_Normal");
+ normalStyle.setDefault(true);
+ normalStyle.setFontName("Arial");
+ normalStyle.setFontSize(12);
+ normalStyle.setPdfFontName("Helvetica");
+ normalStyle.setPdfEncoding("Cp1252");
+ normalStyle.setPdfEmbedded(false);
+ jasperDesign.addStyle(normalStyle);
+
+ JRDesignStyle boldStyle = new JRDesignStyle();
+ boldStyle.setName("Arial_Bold");
+ boldStyle.setFontName("Arial");
+ boldStyle.setFontSize(12);
+ boldStyle.setBold(true);
+ boldStyle.setPdfFontName("Helvetica-Bold");
+ boldStyle.setPdfEncoding("Cp1252");
+ boldStyle.setPdfEmbedded(false);
+ jasperDesign.addStyle(boldStyle);
+
+ JRDesignStyle italicStyle = new JRDesignStyle();
+ italicStyle.setName("Arial_Italic");
+ italicStyle.setFontName("Arial");
+ italicStyle.setFontSize(12);
+ italicStyle.setItalic(true);
+ italicStyle.setPdfFontName("Helvetica-Oblique");
+ italicStyle.setPdfEncoding("Cp1252");
+ italicStyle.setPdfEmbedded(false);
+ jasperDesign.addStyle(italicStyle);
+
+ //Parameters
+ JRDesignParameter parameter = new JRDesignParameter();
+ parameter.setName("ReportTitle");
+ parameter.setValueClass(java.lang.String.class);
+ jasperDesign.addParameter(parameter);
+
+ parameter = new JRDesignParameter();
+ parameter.setName("OrderByClause");
+ parameter.setValueClass(java.lang.String.class);
+ jasperDesign.addParameter(parameter);
+
+ //Query
+ JRDesignQuery query = new JRDesignQuery();
+ query.setText("SELECT * FROM Address $P!{OrderByClause}");
+ jasperDesign.setQuery(query);
+
+ //Fields
+ JRDesignField field = new JRDesignField();
+ field.setName("Id");
+ field.setValueClass(java.lang.Integer.class);
+ jasperDesign.addField(field);
+
+ field = new JRDesignField();
+ field.setName("FirstName");
+ field.setValueClass(java.lang.String.class);
+ jasperDesign.addField(field);
+
+ field = new JRDesignField();
+ field.setName("LastName");
+ field.setValueClass(java.lang.String.class);
+ jasperDesign.addField(field);
+
+ field = new JRDesignField();
+ field.setName("Street");
+ field.setValueClass(java.lang.String.class);
+ jasperDesign.addField(field);
+
+ field = new JRDesignField();
+ field.setName("City");
+ field.setValueClass(java.lang.String.class);
+ jasperDesign.addField(field);
+
+ //Variables
+ JRDesignVariable variable = new JRDesignVariable();
+ variable.setName("CityNumber");
+ variable.setValueClass(java.lang.Integer.class);
+ variable.setResetType(JRVariable.RESET_TYPE_GROUP);
+ JRDesignGroup group = new JRDesignGroup();
+ group.setName("CityGroup");
+ variable.setResetGroup(group);
+ variable.setCalculation(JRVariable.CALCULATION_SYSTEM);
+ JRDesignExpression expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.Integer.class);
+ expression.setText("($V{CityNumber} != null)?(new Integer($V{CityNumber}.intValue() + 1)):(new Integer(1))");
+ variable.setInitialValueExpression(expression);
+ jasperDesign.addVariable(variable);
+
+ variable = new JRDesignVariable();
+ variable.setName("AllCities");
+ variable.setValueClass(java.lang.String.class);
+ variable.setResetType(JRVariable.RESET_TYPE_REPORT);
+ variable.setCalculation(JRVariable.CALCULATION_SYSTEM);
+ jasperDesign.addVariable(variable);
+
+ //Groups
+ group.setMinHeightToStartNewPage(60);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.String.class);
+ expression.setText("$F{City}");
+ group.setExpression(expression);
+
+ JRDesignBand band = new JRDesignBand();
+ band.setHeight(20);
+ JRDesignRectangle rectangle = new JRDesignRectangle();
+ rectangle.setX(0);
+ rectangle.setY(4);
+ rectangle.setWidth(515);
+ rectangle.setHeight(15);
+ rectangle.setForecolor(new Color(0xC0, 0xC0, 0xC0));
+ rectangle.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
+ band.addElement(rectangle);
+ JRDesignTextField textField = new JRDesignTextField();
+ textField.setX(0);
+ textField.setY(4);
+ textField.setWidth(515);
+ textField.setHeight(15);
+ textField.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
+ textField.setMode(JRElement.MODE_OPAQUE);
+ textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);
+ textField.setStyle(boldStyle);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.String.class);
+ expression.setText("\" \" + String.valueOf($V{CityNumber}) + \". \" + String.valueOf($F{City})");
+ textField.setExpression(expression);
+ band.addElement(textField);
+ JRDesignLine line = new JRDesignLine();
+ line.setX(0);
+ line.setY(19);
+ line.setWidth(515);
+ line.setHeight(0);
+ band.addElement(line);
+ group.setGroupHeader(band);
+
+ band = new JRDesignBand();
+ band.setHeight(20);
+ line = new JRDesignLine();
+ line.setX(0);
+ line.setY(-1);
+ line.setWidth(515);
+ line.setHeight(0);
+ band.addElement(line);
+ JRDesignStaticText staticText = new JRDesignStaticText();
+ staticText.setX(400);
+ staticText.setY(0);
+ staticText.setWidth(60);
+ staticText.setHeight(15);
+ staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
+ staticText.setStyle(boldStyle);
+ staticText.setText("Count : ");
+ band.addElement(staticText);
+ textField = new JRDesignTextField();
+ textField.setX(460);
+ textField.setY(0);
+ textField.setWidth(30);
+ textField.setHeight(15);
+ textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
+ textField.setStyle(boldStyle);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.Integer.class);
+ expression.setText("$V{CityGroup_COUNT}");
+ textField.setExpression(expression);
+ band.addElement(textField);
+ group.setGroupFooter(band);
+
+ jasperDesign.addGroup(group);
+
+ //Title
+ band = new JRDesignBand();
+ band.setHeight(50);
+ line = new JRDesignLine();
+ line.setX(0);
+ line.setY(0);
+ line.setWidth(515);
+ line.setHeight(0);
+ band.addElement(line);
+ textField = new JRDesignTextField();
+ textField.setBlankWhenNull(true);
+ textField.setX(0);
+ textField.setY(10);
+ textField.setWidth(515);
+ textField.setHeight(30);
+ textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
+ textField.setStyle(normalStyle);
+ textField.setFontSize(22);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.String.class);
+ expression.setText("$P{ReportTitle}");
+ textField.setExpression(expression);
+ band.addElement(textField);
+ jasperDesign.setTitle(band);
+
+ //Page header
+ band = new JRDesignBand();
+ band.setHeight(20);
+ rectangle = new JRDesignRectangle();
+ rectangle.setX(0);
+ rectangle.setY(5);
+ rectangle.setWidth(515);
+ rectangle.setHeight(15);
+ rectangle.setForecolor(new Color(0x33, 0x33, 0x33));
+ rectangle.setBackcolor(new Color(0x33, 0x33, 0x33));
+ band.addElement(rectangle);
+ staticText = new JRDesignStaticText();
+ staticText.setX(0);
+ staticText.setY(5);
+ staticText.setWidth(55);
+ staticText.setHeight(15);
+ staticText.setForecolor(Color.white);
+ staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
+ staticText.setMode(JRElement.MODE_OPAQUE);
+ staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
+ staticText.setStyle(boldStyle);
+ staticText.setText("ID");
+ band.addElement(staticText);
+ staticText = new JRDesignStaticText();
+ staticText.setX(55);
+ staticText.setY(5);
+ staticText.setWidth(205);
+ staticText.setHeight(15);
+ staticText.setForecolor(Color.white);
+ staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
+ staticText.setMode(JRElement.MODE_OPAQUE);
+ staticText.setStyle(boldStyle);
+ staticText.setText("Name");
+ band.addElement(staticText);
+ staticText = new JRDesignStaticText();
+ staticText.setX(260);
+ staticText.setY(5);
+ staticText.setWidth(255);
+ staticText.setHeight(15);
+ staticText.setForecolor(Color.white);
+ staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
+ staticText.setMode(JRElement.MODE_OPAQUE);
+ staticText.setStyle(boldStyle);
+ staticText.setText("Street");
+ band.addElement(staticText);
+ jasperDesign.setPageHeader(band);
+
+ //Column header
+ band = new JRDesignBand();
+ jasperDesign.setColumnHeader(band);
+
+ //Detail
+ band = new JRDesignBand();
+ band.setHeight(20);
+ textField = new JRDesignTextField();
+ textField.setX(0);
+ textField.setY(4);
+ textField.setWidth(50);
+ textField.setHeight(15);
+ textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
+ textField.setStyle(normalStyle);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.Integer.class);
+ expression.setText("$F{Id}");
+ textField.setExpression(expression);
+ band.addElement(textField);
+ textField = new JRDesignTextField();
+ textField.setStretchWithOverflow(true);
+ textField.setX(55);
+ textField.setY(4);
+ textField.setWidth(200);
+ textField.setHeight(15);
+ textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);
+ textField.setStyle(normalStyle);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.String.class);
+ expression.setText("$F{FirstName} + \" \" + $F{LastName}");
+ textField.setExpression(expression);
+ band.addElement(textField);
+ textField = new JRDesignTextField();
+ textField.setStretchWithOverflow(true);
+ textField.setX(260);
+ textField.setY(4);
+ textField.setWidth(255);
+ textField.setHeight(15);
+ textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);
+ textField.setStyle(normalStyle);
+ expression = new JRDesignExpression();
+ expression.setValueClass(java.lang.String.class);
+ expression.setText("$F{Street}");
+ textField.setExpression(expression);
+ band.addElement(textField);
+ line = new JRDesignLine();
+ line.setX(0);
+ line.setY(19);
+ line.setWidth(515);
+ line.setHeight(0);
+ line.setForecolor(new Color(0x80, 0x80, 0x80));
+ line.setPositionType(JRElement.POSITION_TYPE_FLOAT);
+ band.addElement(line);
+ jasperDesign.setDetail(band);
+
+ //Column footer
+ band = new JRDesignBand();
+ jasperDesign.setColumnFooter(band);
+
+ //Page footer
+ band = new JRDesignBand();
+ jasperDesign.setPageFooter(band);
+
+ //Summary
+ band = new JRDesignBand();
+ jasperDesign.setSummary(band);
+
+ return jasperDesign;
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/noxmldesign/build.xml b/Chapter06/demo/samples/noxmldesign/build.xml
new file mode 100644
index 0000000..14f5434
--- /dev/null
+++ b/Chapter06/demo/samples/noxmldesign/build.xml
@@ -0,0 +1,178 @@
+
+
+ Shows how report templates can be created using the API and not JRXML files.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/noxmldesign/readme.txt b/Chapter06/demo/samples/noxmldesign/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter06/demo/samples/noxmldesign/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/shapes/ShapesApp.java b/Chapter06/demo/samples/shapes/ShapesApp.java
new file mode 100644
index 0000000..c55e877
--- /dev/null
+++ b/Chapter06/demo/samples/shapes/ShapesApp.java
@@ -0,0 +1,264 @@
+/*
+ * ============================================================================
+ * 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 net.sf.jasperreports.engine.JRDataSource;
+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: ShapesApp.java 1644 2007-03-20 09:57:51Z teodord $
+ */
+public class ShapesApp
+{
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperFillManager.fillReportToFile(fileName, null, (JRDataSource)null);
+ 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))
+ {
+ JasperRunManager.runReportToPdfFile(fileName, null, (JRDataSource)null);
+ 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( "ShapesApp usage:" );
+ System.out.println( "\tjava ShapesApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" );
+ }
+
+
+}
diff --git a/Chapter06/demo/samples/shapes/ShapesReport.jrxml b/Chapter06/demo/samples/shapes/ShapesReport.jrxml
new file mode 100644
index 0000000..83b5b42
--- /dev/null
+++ b/Chapter06/demo/samples/shapes/ShapesReport.jrxml
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
diff --git a/Chapter06/demo/samples/shapes/build.xml b/Chapter06/demo/samples/shapes/build.xml
new file mode 100644
index 0000000..0101ec9
--- /dev/null
+++ b/Chapter06/demo/samples/shapes/build.xml
@@ -0,0 +1,183 @@
+
+
+ Shows how various graphic elements could be used inside report templates.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/shapes/readme.txt b/Chapter06/demo/samples/shapes/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter06/demo/samples/shapes/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/unicode/UnicodeApp.java b/Chapter06/demo/samples/unicode/UnicodeApp.java
new file mode 100644
index 0000000..4066c4c
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/unicode/UnicodeReport.jrxml b/Chapter06/demo/samples/unicode/UnicodeReport.jrxml
new file mode 100644
index 0000000..982b447
--- /dev/null
+++ b/Chapter06/demo/samples/unicode/UnicodeReport.jrxml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/unicode/build.xml b/Chapter06/demo/samples/unicode/build.xml
new file mode 100644
index 0000000..db61ce8
--- /dev/null
+++ b/Chapter06/demo/samples/unicode/build.xml
@@ -0,0 +1,183 @@
+
+
+ Shows how text in different languages could be used inside reports.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/unicode/readme.txt b/Chapter06/demo/samples/unicode/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/WEB-INF/classes/datasource/WebappDataSource.java b/Chapter06/demo/samples/webapp/WEB-INF/classes/datasource/WebappDataSource.java
new file mode 100644
index 0000000..458e17b
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/WEB-INF/classes/scriptlets/WebappScriptlet.java b/Chapter06/demo/samples/webapp/WEB-INF/classes/scriptlets/WebappScriptlet.java
new file mode 100644
index 0000000..8a9d49d
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/CompileServlet.java b/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/CompileServlet.java
new file mode 100644
index 0000000..86d4ffc
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java b/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/FillServlet.java
new file mode 100644
index 0000000..5efc1d0
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java b/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/HtmlServlet.java
new file mode 100644
index 0000000..5947364
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java b/Chapter06/demo/samples/webapp/WEB-INF/classes/servlets/JasperPrintServlet.java
new file mode 100644
index 0000000..ebc05bb
--- /dev/null
+++ b/Chapter06/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("
+ 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:
+
+
+
+
+
+ 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.
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/webapp/applets/EmbeddedViewerApplet.form b/Chapter06/demo/samples/webapp/applets/EmbeddedViewerApplet.form
new file mode 100644
index 0000000..e139164
--- /dev/null
+++ b/Chapter06/demo/samples/webapp/applets/EmbeddedViewerApplet.form
@@ -0,0 +1,20 @@
+
+
+
diff --git a/Chapter06/demo/samples/webapp/applets/EmbeddedViewerApplet.java b/Chapter06/demo/samples/webapp/applets/EmbeddedViewerApplet.java
new file mode 100644
index 0000000..9c16014
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/applets/HelloSwingApplet.java b/Chapter06/demo/samples/webapp/applets/HelloSwingApplet.java
new file mode 100644
index 0000000..1d27cbc
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/applets/JRViewerPlus.java b/Chapter06/demo/samples/webapp/applets/JRViewerPlus.java
new file mode 100644
index 0000000..decd5ac
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/applets/JRViewerSimple.java b/Chapter06/demo/samples/webapp/applets/JRViewerSimple.java
new file mode 100644
index 0000000..5c71fdd
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/applets/PrinterApplet.form b/Chapter06/demo/samples/webapp/applets/PrinterApplet.form
new file mode 100644
index 0000000..c5265b6
--- /dev/null
+++ b/Chapter06/demo/samples/webapp/applets/PrinterApplet.form
@@ -0,0 +1,40 @@
+
+
+
diff --git a/Chapter06/demo/samples/webapp/applets/PrinterApplet.java b/Chapter06/demo/samples/webapp/applets/PrinterApplet.java
new file mode 100644
index 0000000..673813b
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/applets/ViewerFrame.form b/Chapter06/demo/samples/webapp/applets/ViewerFrame.form
new file mode 100644
index 0000000..e706ac8
--- /dev/null
+++ b/Chapter06/demo/samples/webapp/applets/ViewerFrame.form
@@ -0,0 +1,30 @@
+
+
+
diff --git a/Chapter06/demo/samples/webapp/applets/ViewerFrame.java b/Chapter06/demo/samples/webapp/applets/ViewerFrame.java
new file mode 100644
index 0000000..ba8a813
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/build.xml b/Chapter06/demo/samples/webapp/build.xml
new file mode 100644
index 0000000..441bea3
--- /dev/null
+++ b/Chapter06/demo/samples/webapp/build.xml
@@ -0,0 +1,110 @@
+
+
+ Shows how reporting functionality could be added to a Web application.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/webapp/compile.html b/Chapter06/demo/samples/webapp/compile.html
new file mode 100644
index 0000000..98cb1e0
--- /dev/null
+++ b/Chapter06/demo/samples/webapp/compile.html
@@ -0,0 +1,90 @@
+
+
+
+JasperReports - Web Application Sample
+
+
+
+
+
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+
+
+
diff --git a/Chapter06/demo/samples/webapp/jsp/compile.jsp b/Chapter06/demo/samples/webapp/jsp/compile.jsp
new file mode 100644
index 0000000..666bbbb
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/jsp/error.jsp b/Chapter06/demo/samples/webapp/jsp/error.jsp
new file mode 100644
index 0000000..82a5696
--- /dev/null
+++ b/Chapter06/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 :
+
+
+
diff --git a/Chapter06/demo/samples/webapp/jsp/fill.jsp b/Chapter06/demo/samples/webapp/jsp/fill.jsp
new file mode 100644
index 0000000..9d303fa
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/jsp/html.jsp b/Chapter06/demo/samples/webapp/jsp/html.jsp
new file mode 100644
index 0000000..bb4255d
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/jsp/source.jsp b/Chapter06/demo/samples/webapp/jsp/source.jsp
new file mode 100644
index 0000000..93b52be
--- /dev/null
+++ b/Chapter06/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/Chapter06/demo/samples/webapp/jsp/viewer.jsp b/Chapter06/demo/samples/webapp/jsp/viewer.jsp
new file mode 100644
index 0000000..1a6b1d8
--- /dev/null
+++ b/Chapter06/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();
+%>
+
+
+
+
+
+
+
+
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter11/demo/samples/subreport/MasterReport.jrxml b/Chapter11/demo/samples/subreport/MasterReport.jrxml
new file mode 100644
index 0000000..b4774fc
--- /dev/null
+++ b/Chapter11/demo/samples/subreport/MasterReport.jrxml
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Total order value: " + $V{ProductTotalPrice}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter11/demo/samples/subreport/ProductReport.jrxml b/Chapter11/demo/samples/subreport/ProductReport.jrxml
new file mode 100644
index 0000000..efe4ba5
--- /dev/null
+++ b/Chapter11/demo/samples/subreport/ProductReport.jrxml
@@ -0,0 +1,194 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter11/demo/samples/subreport/SubreportApp.java b/Chapter11/demo/samples/subreport/SubreportApp.java
new file mode 100644
index 0000000..8c574e9
--- /dev/null
+++ b/Chapter11/demo/samples/subreport/SubreportApp.java
@@ -0,0 +1,299 @@
+/*
+ * ============================================================================
+ * 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.JasperReport;
+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: SubreportApp.java 1665 2007-03-26 09:53:29Z teodord $
+ */
+public class SubreportApp
+{
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperReport subreport = (JasperReport)JRLoader.loadObject("ProductReport.jasper");
+
+ //Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put("ProductsSubreport", subreport);
+
+ 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.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.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))
+ {
+ JasperReport subreport = (JasperReport)JRLoader.loadObject("ProductReport.jasper");
+
+ //Preparing parameters
+ Map parameters = new HashMap();
+ parameters.put("ProductsSubreport", subreport);
+
+ 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( "SubreportApp usage:" );
+ System.out.println( "\tjava SubreportApp -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/Chapter11/demo/samples/subreport/build.xml b/Chapter11/demo/samples/subreport/build.xml
new file mode 100644
index 0000000..408c2fc
--- /dev/null
+++ b/Chapter11/demo/samples/subreport/build.xml
@@ -0,0 +1,238 @@
+
+
+ Shows how subreport could be used to create complex document layouts..
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter11/demo/samples/subreport/jasperreports-javaflow.properties b/Chapter11/demo/samples/subreport/jasperreports-javaflow.properties
new file mode 100644
index 0000000..0332024
--- /dev/null
+++ b/Chapter11/demo/samples/subreport/jasperreports-javaflow.properties
@@ -0,0 +1,2 @@
+# Uncomment the following line to use Javaflow continuations instead of threads for subreports
+net.sf.jasperreports.subreport.runner.factory=net.sf.jasperreports.engine.fill.JRContinuationSubreportRunnerFactory
diff --git a/Chapter11/demo/samples/subreport/readme.txt b/Chapter11/demo/samples/subreport/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter11/demo/samples/subreport/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/Chapter13/demo/samples/charts/AreaChartReport.jrxml b/Chapter13/demo/samples/charts/AreaChartReport.jrxml
new file mode 100644
index 0000000..29fed88
--- /dev/null
+++ b/Chapter13/demo/samples/charts/AreaChartReport.jrxml
@@ -0,0 +1,347 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/Bar3DChartReport.jrxml b/Chapter13/demo/samples/charts/Bar3DChartReport.jrxml
new file mode 100644
index 0000000..927af0d
--- /dev/null
+++ b/Chapter13/demo/samples/charts/Bar3DChartReport.jrxml
@@ -0,0 +1,386 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/BarChartCustomizer.java b/Chapter13/demo/samples/charts/BarChartCustomizer.java
new file mode 100644
index 0000000..ae50b69
--- /dev/null
+++ b/Chapter13/demo/samples/charts/BarChartCustomizer.java
@@ -0,0 +1,50 @@
+/*
+ * ============================================================================
+ * 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.JRChartCustomizer;
+import net.sf.jasperreports.engine.JRChartDataset;
+import net.sf.jasperreports.engine.JRChartPlot;
+import net.sf.jasperreports.engine.JRChart;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.renderer.category.BarRenderer;
+
+import java.awt.*;
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: BarChartCustomizer.java 1663 2007-03-26 08:54:33Z teodord $
+ */
+public class BarChartCustomizer implements JRChartCustomizer
+{
+
+ public void customize(JFreeChart chart, JRChart jasperChart)
+ {
+ BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
+ renderer.setSeriesPaint(0, Color.green);
+ renderer.setSeriesPaint(1, Color.orange);
+ }
+}
\ No newline at end of file
diff --git a/Chapter13/demo/samples/charts/BarChartReport.jrxml b/Chapter13/demo/samples/charts/BarChartReport.jrxml
new file mode 100644
index 0000000..7baff69
--- /dev/null
+++ b/Chapter13/demo/samples/charts/BarChartReport.jrxml
@@ -0,0 +1,386 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/BubbleChartReport.jrxml b/Chapter13/demo/samples/charts/BubbleChartReport.jrxml
new file mode 100644
index 0000000..993a202
--- /dev/null
+++ b/Chapter13/demo/samples/charts/BubbleChartReport.jrxml
@@ -0,0 +1,388 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{OrderID}
+ $F{Freight}
+ new Double(30.00)
+
+
+ "Half Freight"
+ $F{OrderID}
+ new Double($F{Freight}.doubleValue() / 2d)
+ new Double(20.00)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/CandlestickChartReport.jrxml b/Chapter13/demo/samples/charts/CandlestickChartReport.jrxml
new file mode 100644
index 0000000..9fd138e
--- /dev/null
+++ b/Chapter13/demo/samples/charts/CandlestickChartReport.jrxml
@@ -0,0 +1,383 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $V{DateHighestCountryGroup}
+ new Double($V{FreightSumCountryGroup}.doubleValue() * 1.6d)
+ new Double($V{FreightSumCountryGroup}.doubleValue() * 0.4d)
+ new Double($V{FreightSumCountryGroup}.doubleValue() * 0.7)
+ new Double($V{FreightSumCountryGroup}.doubleValue() * 1.4)
+ new Double($V{FreightSumCountryGroup}.doubleValue() * 0.5)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/ChartsApp.java b/Chapter13/demo/samples/charts/ChartsApp.java
new file mode 100644
index 0000000..a5e9dd6
--- /dev/null
+++ b/Chapter13/demo/samples/charts/ChartsApp.java
@@ -0,0 +1,221 @@
+/*
+ * ============================================================================
+ * 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.Calendar;
+import java.util.Date;
+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.util.JRLoader;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: ChartsApp.java 1559 2007-01-15 10:53:54Z shertage $
+ */
+public class ChartsApp
+{
+
+
+ /**
+ *
+ */
+ 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_WRITE_XML = "writeXml";
+
+ private static final String[] reportNames =
+ {
+ "PieChartReport",
+ "Pie3DChartReport",
+ "BarChartReport",
+ "Bar3DChartReport",
+ "StackedBarChartReport",
+ "StackedBar3DChartReport",
+ "XYBarChartTimePeriodReport",
+ "XYBarChartTimeSeriesReport",
+ "XYBarChartReport",
+ "AreaChartReport",
+ "XYAreaChartReport",
+ "ScatterChartReport",
+ "LineChartReport",
+ "XYLineChartReport",
+ "TimeSeriesChartReport",
+ "BubbleChartReport",
+ "SubDatasetChartReport",
+ "MeterChartReport",
+ "MultipleAxisChartReport",
+ "ThermometerChartReport",
+ "HighLowChartReport",
+ "CandlestickChartReport",
+ "StackedAreaChartReport"
+ };
+
+ /**
+ *
+ */
+ public static void main(String[] args)
+ {
+ 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);
+
+ k++;
+ }
+
+ try
+ {
+ if (TASK_FILL.equals(taskName))
+ {
+ Map parameters = new HashMap();
+ parameters.put("MaxOrderID", new Integer(12500));
+
+ for(int i = 0; i < reportNames.length; i++)
+ {
+ long start = System.currentTimeMillis();
+ JasperFillManager.fillReportToFile(reportNames[i] + ".jasper", parameters, getConnection());
+ System.err.println("Report : " + reportNames[i] + ". Filling time : " + (System.currentTimeMillis() - start));
+ }
+
+ System.exit(0);
+ }
+ else if (TASK_PDF.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++)
+ {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToPdfFile(reportNames[i] + ".jrprint");
+ System.err.println("Report : " + reportNames[i] + ". PDF export time : " + (System.currentTimeMillis() - start));
+ }
+
+ System.exit(0);
+ }
+ else if (TASK_HTML.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++)
+ {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToHtmlFile(reportNames[i] + ".jrprint");
+ System.err.println("Report : " + reportNames[i] + ". Html export time : " + (System.currentTimeMillis() - start));
+ }
+
+ System.exit(0);
+ }
+ else if (TASK_WRITE_XML.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++)
+ {
+ long start = System.currentTimeMillis();
+ JasperCompileManager.writeReportToXmlFile(reportNames[i] + ".jasper", reportNames[i] + ".jasper.jrxml");
+ System.err.println("Report : " + reportNames[i] + ". XML write 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( "ChartsApp usage:" );
+ System.out.println( "\tjava ChartsApp -Ttask" );
+ System.out.println( "\tTasks : fill | pdf | html" );
+ }
+
+
+ /**
+ *
+ */
+ 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;
+ }
+
+
+
+ public static final Date truncateToMonth(Date date)
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ int year = calendar.get(Calendar.YEAR);
+ int month = calendar.get(Calendar.MONTH);
+ calendar.clear();
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, month);
+ return calendar.getTime();
+ }
+
+}
diff --git a/Chapter13/demo/samples/charts/HighLowChartReport.jrxml b/Chapter13/demo/samples/charts/HighLowChartReport.jrxml
new file mode 100644
index 0000000..1c52eb9
--- /dev/null
+++ b/Chapter13/demo/samples/charts/HighLowChartReport.jrxml
@@ -0,0 +1,383 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $F{ShipCountry}
+ $F{OrderDate}
+ new Double($F{Freight}.doubleValue() + $F{Freight}.doubleValue()*0.6)
+ new Double($F{Freight}.doubleValue() - $F{Freight}.doubleValue()*0.6)
+ new Double($F{Freight}.doubleValue() - $F{Freight}.doubleValue()*0.3)
+ new Double($F{Freight}.doubleValue() + $F{Freight}.doubleValue()*0.4)
+ new Double($F{Freight}.doubleValue() / 2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/LineChartReport.jrxml b/Chapter13/demo/samples/charts/LineChartReport.jrxml
new file mode 100644
index 0000000..830310d
--- /dev/null
+++ b/Chapter13/demo/samples/charts/LineChartReport.jrxml
@@ -0,0 +1,398 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+ "Double Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() * 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/MeterChartReport.jrxml b/Chapter13/demo/samples/charts/MeterChartReport.jrxml
new file mode 100644
index 0000000..208af91
--- /dev/null
+++ b/Chapter13/demo/samples/charts/MeterChartReport.jrxml
@@ -0,0 +1,402 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSumFirstLetterGroup}
+
+
+
+
+
+
+
+
+
+
+
+
+ new Double(0.0)
+ new Double(2000.0)
+
+
+
+
+ new Double(2000.0)
+ new Double(12000.0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/MultipleAxisChartReport.jrxml b/Chapter13/demo/samples/charts/MultipleAxisChartReport.jrxml
new file mode 100644
index 0000000..6e09b38
--- /dev/null
+++ b/Chapter13/demo/samples/charts/MultipleAxisChartReport.jrxml
@@ -0,0 +1,865 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Countries Starting With Letter :" + $V{FirstLetter} + ""]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "# Orders"
+
+ $V{CityGroup_COUNT}
+
+
+
+
+
+
+
+ "# Orders"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight/Orders"
+
+ new Double($V{FreightSumCityGroup}.doubleValue() / $V{CityGroup_COUNT}.doubleValue())
+
+
+
+
+
+
+
+ "Freight per Order"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/Pie3DChartReport.jrxml b/Chapter13/demo/samples/charts/Pie3DChartReport.jrxml
new file mode 100644
index 0000000..8399cc6
--- /dev/null
+++ b/Chapter13/demo/samples/charts/Pie3DChartReport.jrxml
@@ -0,0 +1,378 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/PieChartReport.jrxml b/Chapter13/demo/samples/charts/PieChartReport.jrxml
new file mode 100644
index 0000000..7662f40
--- /dev/null
+++ b/Chapter13/demo/samples/charts/PieChartReport.jrxml
@@ -0,0 +1,382 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+ "http://en.wikipedia.org/wiki/" + $F{ShipCountry}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/ScatterChartReport.jrxml b/Chapter13/demo/samples/charts/ScatterChartReport.jrxml
new file mode 100644
index 0000000..0d87a77
--- /dev/null
+++ b/Chapter13/demo/samples/charts/ScatterChartReport.jrxml
@@ -0,0 +1,391 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{OrderID}
+ $F{Freight}
+
+ $F{OrderID}.toString()
+ "Go to item " + $F{OrderID}
+
+
+
+ "Half Freight"
+ $F{OrderID}
+ new Double($F{Freight}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $F{OrderID}.toString()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/StackedAreaChartReport.jrxml b/Chapter13/demo/samples/charts/StackedAreaChartReport.jrxml
new file mode 100644
index 0000000..4404fbe
--- /dev/null
+++ b/Chapter13/demo/samples/charts/StackedAreaChartReport.jrxml
@@ -0,0 +1,403 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+ "Google it!"
+
+
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+ "Google it!"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/StackedBar3DChartReport.jrxml b/Chapter13/demo/samples/charts/StackedBar3DChartReport.jrxml
new file mode 100644
index 0000000..3f2513c
--- /dev/null
+++ b/Chapter13/demo/samples/charts/StackedBar3DChartReport.jrxml
@@ -0,0 +1,388 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/StackedBarChartReport.jrxml b/Chapter13/demo/samples/charts/StackedBarChartReport.jrxml
new file mode 100644
index 0000000..2813b6e
--- /dev/null
+++ b/Chapter13/demo/samples/charts/StackedBarChartReport.jrxml
@@ -0,0 +1,388 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{ShipCountry}
+ $V{FreightSumCountryGroup}
+
+
+
+ "Half Freight"
+ $F{ShipCountry}
+ new Double($V{FreightSumCountryGroup}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/SubDatasetChartReport.jrxml b/Chapter13/demo/samples/charts/SubDatasetChartReport.jrxml
new file mode 100644
index 0000000..97dff4d
--- /dev/null
+++ b/Chapter13/demo/samples/charts/SubDatasetChartReport.jrxml
@@ -0,0 +1,124 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ChartsApp.truncateToMonth($F{OrderDate})
+
+
+ $F{Freight}
+
+
+ $V{OrderMonth}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/ThermometerChartReport.jrxml b/Chapter13/demo/samples/charts/ThermometerChartReport.jrxml
new file mode 100644
index 0000000..0013288
--- /dev/null
+++ b/Chapter13/demo/samples/charts/ThermometerChartReport.jrxml
@@ -0,0 +1,403 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSumFirstLetterGroup}
+
+
+
+
+
+
+
+ new Double(0.0)
+ new Double(17500.0)
+
+
+
+ new Double(0.0)
+ new Double(2000.0)
+
+
+
+
+ new Double(2000.0)
+ new Double(12000.0)
+
+
+
+
+ new Double(12000.0)
+ new Double(17500)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/TimeSeriesChartReport.jrxml b/Chapter13/demo/samples/charts/TimeSeriesChartReport.jrxml
new file mode 100644
index 0000000..a6cdd30
--- /dev/null
+++ b/Chapter13/demo/samples/charts/TimeSeriesChartReport.jrxml
@@ -0,0 +1,388 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{OrderDate}
+ $F{Freight}
+
+
+
+ "Half-Freight"
+ $F{OrderDate}
+ new Double( $F{Freight}.doubleValue()/2d )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/XYAreaChartReport.jrxml b/Chapter13/demo/samples/charts/XYAreaChartReport.jrxml
new file mode 100644
index 0000000..bb407b3
--- /dev/null
+++ b/Chapter13/demo/samples/charts/XYAreaChartReport.jrxml
@@ -0,0 +1,391 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ = $P{ChartFreightThreshold}.doubleValue() ? Boolean.TRUE : Boolean.FALSE
+ ]]>
+
+
+ "Half Freight"
+ $F{OrderID}
+ new Double($F{Freight}.doubleValue() / 2d)
+
+
+ "Freight"
+ $F{OrderID}
+ $F{Freight}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/XYBarChartReport.jrxml b/Chapter13/demo/samples/charts/XYBarChartReport.jrxml
new file mode 100644
index 0000000..3c0d7c2
--- /dev/null
+++ b/Chapter13/demo/samples/charts/XYBarChartReport.jrxml
@@ -0,0 +1,392 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Half Freight"
+ $F{OrderID}
+ new Double($F{Freight}.doubleValue() / 2d)
+
+
+ "Freight"
+ $F{OrderID}
+ $F{Freight}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/XYBarChartTimePeriodReport.jrxml b/Chapter13/demo/samples/charts/XYBarChartTimePeriodReport.jrxml
new file mode 100644
index 0000000..b07f4d9
--- /dev/null
+++ b/Chapter13/demo/samples/charts/XYBarChartTimePeriodReport.jrxml
@@ -0,0 +1,394 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Half Freight"
+ $F{OrderDate}
+ $F{ShippedDate}
+ new Double($F{Freight}.doubleValue() / 2d)
+
+
+ "Freight"
+ $F{OrderDate}
+ $F{ShippedDate}
+ $F{Freight}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/XYBarChartTimeSeriesReport.jrxml b/Chapter13/demo/samples/charts/XYBarChartTimeSeriesReport.jrxml
new file mode 100644
index 0000000..4462cff
--- /dev/null
+++ b/Chapter13/demo/samples/charts/XYBarChartTimeSeriesReport.jrxml
@@ -0,0 +1,392 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Half Freight"
+ $F{OrderDate}
+ new Double($F{Freight}.doubleValue() / 2d)
+
+
+ "Freight"
+ $F{OrderDate}
+ $F{Freight}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/XYLineChartReport.jrxml b/Chapter13/demo/samples/charts/XYLineChartReport.jrxml
new file mode 100644
index 0000000..e9d31de
--- /dev/null
+++ b/Chapter13/demo/samples/charts/XYLineChartReport.jrxml
@@ -0,0 +1,386 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Freight"
+ $F{OrderID}
+ $F{Freight}
+
+
+ "Half Freight"
+ $F{OrderID}
+ new Double($F{Freight}.doubleValue() / 2d)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/build.xml b/Chapter13/demo/samples/charts/build.xml
new file mode 100644
index 0000000..2dc8838
--- /dev/null
+++ b/Chapter13/demo/samples/charts/build.xml
@@ -0,0 +1,94 @@
+
+
+ Shows how the chart element could be used to render different types of charts.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/charts/readme.txt b/Chapter13/demo/samples/charts/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter13/demo/samples/charts/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/Chapter13/demo/samples/jcharts/build.xml b/Chapter13/demo/samples/jcharts/build.xml
new file mode 100644
index 0000000..64d4b4a
--- /dev/null
+++ b/Chapter13/demo/samples/jcharts/build.xml
@@ -0,0 +1,175 @@
+
+
+ Shows how third-party charting APIs could be used for rendering charts as images.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/jcharts/lib/LICENSE.jcharts.txt b/Chapter13/demo/samples/jcharts/lib/LICENSE.jcharts.txt
new file mode 100644
index 0000000..f8a64a8
--- /dev/null
+++ b/Chapter13/demo/samples/jcharts/lib/LICENSE.jcharts.txt
@@ -0,0 +1,31 @@
+Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
+
+Redistribution and use of this software and associated documentation ("Software"), with or
+without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain copyright statements and notices.
+Redistributions must also contain a copy of this document.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of
+conditions and the following disclaimer in the documentation and/or other materials
+provided with the distribution.
+
+3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
+products derived from this Software without prior written permission of Nathaniel G.
+Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
+
+4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
+in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
+registered trademark of Nathaniel G. Auvil.
+
+5. Due credit should be given to the jCharts Project (http://jcharts.krysalis.org).
+
+THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
+EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
diff --git a/Chapter13/demo/samples/jcharts/lib/jCharts-0.6.0.jar b/Chapter13/demo/samples/jcharts/lib/jCharts-0.6.0.jar
new file mode 100644
index 0000000..11fbeb0
Binary files /dev/null and b/Chapter13/demo/samples/jcharts/lib/jCharts-0.6.0.jar differ
diff --git a/Chapter13/demo/samples/jcharts/readme.txt b/Chapter13/demo/samples/jcharts/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter13/demo/samples/jcharts/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/Chapter13/demo/samples/jcharts/reports/JChartsReport.jrxml b/Chapter13/demo/samples/jcharts/reports/JChartsReport.jrxml
new file mode 100644
index 0000000..d99bd84
--- /dev/null
+++ b/Chapter13/demo/samples/jcharts/reports/JChartsReport.jrxml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/jcharts/src/JChartsApp.java b/Chapter13/demo/samples/jcharts/src/JChartsApp.java
new file mode 100644
index 0000000..ee29ac5
--- /dev/null
+++ b/Chapter13/demo/samples/jcharts/src/JChartsApp.java
@@ -0,0 +1,258 @@
+/*
+ * ============================================================================
+ * 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 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: JChartsApp.java 1665 2007-03-26 09:53:29Z teodord $
+ */
+public class JChartsApp
+{
+ 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))
+ {
+ JasperFillManager.fillReportToFile(fileName, null, 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("XLS 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.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))
+ {
+ JasperRunManager.runReportToPdfFile(fileName, null, 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( "JChartsApp usage:" );
+ System.out.println( "\tjava JChartsApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" );
+ }
+
+
+}
diff --git a/Chapter13/demo/samples/jcharts/src/JChartsScriptlet.java b/Chapter13/demo/samples/jcharts/src/JChartsScriptlet.java
new file mode 100644
index 0000000..37eaa8a
--- /dev/null
+++ b/Chapter13/demo/samples/jcharts/src/JChartsScriptlet.java
@@ -0,0 +1,95 @@
+/*
+ * ============================================================================
+ * 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.Color;
+import java.awt.Paint;
+import java.awt.image.BufferedImage;
+
+import net.sf.jasperreports.engine.JRDefaultScriptlet;
+import net.sf.jasperreports.engine.JRScriptletException;
+
+import org.jCharts.axisChart.AxisChart;
+import org.jCharts.chartData.AxisChartDataSet;
+import org.jCharts.chartData.ChartDataException;
+import org.jCharts.chartData.DataSeries;
+import org.jCharts.properties.AreaChartProperties;
+import org.jCharts.properties.AxisProperties;
+import org.jCharts.properties.ChartProperties;
+import org.jCharts.properties.LegendProperties;
+import org.jCharts.types.ChartType;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: JChartsScriptlet.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class JChartsScriptlet extends JRDefaultScriptlet
+{
+
+
+ /**
+ *
+ */
+ public void afterReportInit() throws JRScriptletException
+ {
+ try
+ {
+ AreaChartProperties areaChartProperties = new AreaChartProperties();
+
+ double[][] data = {{10, 15, 30, 53}, {6, 30, 10, 21}, {20, 25, 20, 8}};
+ Paint[] paints = {new Color( 0, 255, 0, 100 ), new Color( 255, 0, 0, 100 ), new Color( 0, 0, 255, 100 )};
+ String[] legendLabels = {"Games", "Events", "Players" };
+ AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data, legendLabels, paints, ChartType.AREA, areaChartProperties);
+
+ String[] axisLabels = {"January", "March", "May", "June"};
+ DataSeries dataSeries = new DataSeries(axisLabels, "Months", "People", "Popular Events");
+ dataSeries.addIAxisPlotDataSet(axisChartDataSet);
+
+ ChartProperties chartProperties = new ChartProperties();
+ AxisProperties axisProperties = new AxisProperties();
+ axisProperties.setYAxisRoundValuesToNearest(0);
+ LegendProperties legendProperties = new LegendProperties();
+
+ AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, 500, 350);
+
+ BufferedImage bufferedImage = new BufferedImage(500, 350, BufferedImage.TYPE_INT_RGB);
+
+ axisChart.setGraphics2D(bufferedImage.createGraphics());
+ axisChart.render();
+
+ super.setVariableValue("ChartImage", bufferedImage);
+ }
+ catch(ChartDataException chartDataException)
+ {
+ throw new JRScriptletException(chartDataException);
+ }
+ }
+
+
+}
diff --git a/Chapter13/demo/samples/jfreechart/build.xml b/Chapter13/demo/samples/jfreechart/build.xml
new file mode 100644
index 0000000..56cced5
--- /dev/null
+++ b/Chapter13/demo/samples/jfreechart/build.xml
@@ -0,0 +1,172 @@
+
+
+ Shows how third-party charting APIs could be used for rendering charts as images.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/jfreechart/readme.txt b/Chapter13/demo/samples/jfreechart/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter13/demo/samples/jfreechart/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/Chapter13/demo/samples/jfreechart/reports/JFreeChartReport.jrxml b/Chapter13/demo/samples/jfreechart/reports/JFreeChartReport.jrxml
new file mode 100644
index 0000000..706e434
--- /dev/null
+++ b/Chapter13/demo/samples/jfreechart/reports/JFreeChartReport.jrxml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter13/demo/samples/jfreechart/src/JFreeChartApp.java b/Chapter13/demo/samples/jfreechart/src/JFreeChartApp.java
new file mode 100644
index 0000000..cc56ea0
--- /dev/null
+++ b/Chapter13/demo/samples/jfreechart/src/JFreeChartApp.java
@@ -0,0 +1,265 @@
+/*
+ * ============================================================================
+ * 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 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: JFreeChartApp.java 1665 2007-03-26 09:53:29Z teodord $
+ */
+public class JFreeChartApp
+{
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperFillManager.fillReportToFile(fileName, null, 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.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))
+ {
+ JasperRunManager.runReportToPdfFile(fileName, null, 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( "JFreeChartApp usage:" );
+ System.out.println( "\tjava JFreeChartApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | rtf | xls | jxl | csv | odt | run" );
+ }
+
+
+}
diff --git a/Chapter13/demo/samples/jfreechart/src/JFreeChartScriptlet.java b/Chapter13/demo/samples/jfreechart/src/JFreeChartScriptlet.java
new file mode 100644
index 0000000..a0697ca
--- /dev/null
+++ b/Chapter13/demo/samples/jfreechart/src/JFreeChartScriptlet.java
@@ -0,0 +1,85 @@
+/*
+ * ============================================================================
+ * 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
+ */
+
+/*
+ * Contributors:
+ * David Gilbert - david.gilbert@object-refinery.com
+ */
+
+import net.sf.jasperreports.engine.JRDefaultScriptlet;
+import net.sf.jasperreports.engine.JRScriptletException;
+import net.sf.jasperreports.renderers.JCommonDrawableRenderer;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PiePlot3D;
+import org.jfree.data.general.DefaultPieDataset;
+import org.jfree.util.Rotation;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: JFreeChartScriptlet.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class JFreeChartScriptlet extends JRDefaultScriptlet
+{
+
+
+ /**
+ *
+ */
+ public void afterReportInit() throws JRScriptletException
+ {
+ DefaultPieDataset dataset = new DefaultPieDataset();
+ dataset.setValue("Java", new Double(43.2));
+ dataset.setValue("Visual Basic", new Double(10.0));
+ dataset.setValue("C/C++", new Double(17.5));
+ dataset.setValue("PHP", new Double(32.5));
+ dataset.setValue("Perl", new Double(1.0));
+
+ JFreeChart chart =
+ ChartFactory.createPieChart3D(
+ "Pie Chart 3D Demo 1",
+ dataset,
+ true,
+ true,
+ false
+ );
+
+ PiePlot3D plot = (PiePlot3D) chart.getPlot();
+ plot.setStartAngle(290);
+ plot.setDirection(Rotation.CLOCKWISE);
+ plot.setForegroundAlpha(0.5f);
+ plot.setNoDataMessage("No data to display");
+
+ /* */
+ this.setVariableValue("Chart", new JCommonDrawableRenderer(chart));
+ }
+
+
+}
diff --git a/Chapter14/demo/samples/crosstabs/CrosstabApp.java b/Chapter14/demo/samples/crosstabs/CrosstabApp.java
new file mode 100644
index 0000000..1ad0a2c
--- /dev/null
+++ b/Chapter14/demo/samples/crosstabs/CrosstabApp.java
@@ -0,0 +1,352 @@
+/*
+ * ============================================================================
+ * 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.Calendar;
+import java.util.Date;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+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 Lucian Chirita (lucianc@users.sourceforge.net)
+ * @version $Id: CrosstabApp.java 1644 2007-03-20 09:57:51Z teodord $
+ */
+public class CrosstabApp
+{
+
+
+ /**
+ *
+ */
+ 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";
+
+ private static final String[] reportNames = {
+ "OrdersReport",
+ "ProductsReport",
+ "ShipmentsReport",
+ "LateOrdersReport"
+ };
+
+ /**
+ *
+ */
+ 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);
+
+
+ k++;
+ }
+
+ try
+ {
+ if (TASK_FILL.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperFillManager.fillReportToFile(reportNames[i] + ".jasper", null, getConnection());
+ System.err.println("Report : " + reportNames[i] + ". Filling time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_PRINT.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperPrintManager.printReport(reportNames[i] + ".jrprint", true);
+ System.err.println("Report : " + reportNames[i] + ". Printing time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_PDF.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToPdfFile(reportNames[i] + ".jrprint");
+ System.err.println("Report : " + reportNames[i] + ". PDF creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_XML.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToXmlFile(reportNames[i] + ".jrprint", false);
+ System.err.println("Report : " + reportNames[i] + ". XML creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_XML_EMBED.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToXmlFile(reportNames[i] + ".jrprint", true);
+ System.err.println("Report : " + reportNames[i] + ". XML creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_HTML.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperExportManager.exportReportToHtmlFile(reportNames[i] + ".jrprint");
+ System.err.println("Report : " + reportNames[i] + ". HTML creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_RTF.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ File sourceFile = new File(reportNames[i] + ".jrprint");
+
+ 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("Report : " + reportNames[i] + ". RTF creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_XLS.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ File sourceFile = new File(reportNames[i] + ".jrprint");
+
+ 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("Report : " + reportNames[i] + ". XLS creation time : " + (System.currentTimeMillis() - start));
+ }
+
+ System.exit(0);
+ }
+ else if (TASK_JXL.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ File sourceFile = new File(reportNames[i] + ".jrprint");
+
+ 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("Report : " + reportNames[i] + ". XLS creation time : " + (System.currentTimeMillis() - start));
+ }
+
+ System.exit(0);
+ }
+ else if (TASK_CSV.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ File sourceFile = new File(reportNames[i] + ".jrprint");
+
+ 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("Report : " + reportNames[i] + ". CSV creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_ODT.equals(taskName))
+ {
+ for(int i = 0; i < reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ File sourceFile = new File(reportNames[i] + ".jrprint");
+
+ 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("Report : " + reportNames[i] + ". ODT creation time : " + (System.currentTimeMillis() - start));
+ }
+ System.exit(0);
+ }
+ else if (TASK_RUN.equals(taskName))
+ {
+ for(int i = 0; i< reportNames.length; i++) {
+ long start = System.currentTimeMillis();
+ JasperRunManager.runReportToPdfFile(reportNames[i] + ".jrprint", null, getConnection());
+ System.err.println("Report : " + reportNames[i] + ". 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( "CrosstabApp usage:" );
+ System.out.println( "\tjava CrosstabApp -Ttask" );
+ 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;
+ }
+
+
+
+ public static final Date truncateToMonth(Date date)
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ int year = calendar.get(Calendar.YEAR);
+ int month = calendar.get(Calendar.MONTH);
+ calendar.clear();
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, month);
+ return calendar.getTime();
+ }
+
+
+ public static final Date truncateToYear(Date date)
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ int year = calendar.get(Calendar.YEAR);
+ calendar.clear();
+ calendar.set(Calendar.YEAR, year);
+ return calendar.getTime();
+ }
+
+}
diff --git a/Chapter14/demo/samples/crosstabs/LateOrdersReport.jrxml b/Chapter14/demo/samples/crosstabs/LateOrdersReport.jrxml
new file mode 100644
index 0000000..8ce5e85
--- /dev/null
+++ b/Chapter14/demo/samples/crosstabs/LateOrdersReport.jrxml
@@ -0,0 +1,270 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Shipped Orders
+
+
+
+
+
+
+
+
+
+
+ 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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Number of orders and latest order date by country and freight range.
+
+
+
+
+
+
+
+
+
+
+
+
+ $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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Number of orders by product and customer in " + $F{City}
+
+
+
+
+ $F{City}
+
+
+
+
+
+
+
+
+
+
+
+
+ $F{FirstName} + " " + $F{LastName}
+
+
+
+
+
+
+ $V{NameGroup}
+
+
+
+
+
+
+
+
+ TOTAL
+
+
+
+
+
+
+ $F{Name}
+
+
+
+
+
+
+
+ $V{ProductGroup}
+
+
+
+
+
+
+
+
+
+ TOTAL
+
+
+
+
+
+ $F{Quantity}
+
+
+
+
+
+
+
+ $V{QuantityMesure}
+
+
+
+
+
+
+
+
+
+ $V{QuantityMesure}
+
+
+
+
+
+
+
+
+
+ $V{QuantityMesure}
+
+
+
+
+
+
+
+
+
+ $V{QuantityMesure}
+
+
+
+
+
+
+
+ No data
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter14/demo/samples/crosstabs/ShipmentsReport.jrxml b/Chapter14/demo/samples/crosstabs/ShipmentsReport.jrxml
new file mode 100644
index 0000000..ca7c496
--- /dev/null
+++ b/Chapter14/demo/samples/crosstabs/ShipmentsReport.jrxml
@@ -0,0 +1,292 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "Shipments to " + $F{ShipCountry}
+
+
+
+
+
+
+ $F{ShipCountry}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Shipments total freight
+
+
+
+
+
+
+ $F{ShipRegion}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $P{Country} + " Total"
+
+
+
+
+
+
+
+ $F{ShipCity}
+
+
+
+
+
+
+
+ $V{City}
+
+
+
+
+
+
+
+
+
+ Total
+
+
+
+
+
+
+
+ CrosstabApp.truncateToYear($F{ShippedDate})
+
+
+
+
+
+
+
+
+
+
+
+ $V{ShipYear}
+
+
+
+
+
+
+
+
+ Total
+
+
+
+
+
+
+
+ CrosstabApp.truncateToMonth($F{ShippedDate})
+
+
+
+
+
+
+ $V{ShipMonth}
+
+
+
+
+
+
+
+
+ msg("{0,date,yyyy} Total", $V{ShipYear})
+
+
+
+
+
+
+ $F{Freight}
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+ msg("({0,number,percent})", new Float($V{FreightSum}.floatValue() / $V{FreightSum_ShipYear_ALL}.floatValue()))
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+ msg("({0,number,percent})", new Float($V{FreightSum}.floatValue() / $V{FreightSum_ShipYear_ALL}.floatValue()))
+
+
+
+
+
+
+
+
+
+
+ $V{FreightSum}
+
+
+
+
+ msg("({0,number,percent})", new Float($V{FreightSum}.floatValue() / $V{FreightSum_ShipYear_ALL}.floatValue()))
+
+
+
+
+
+
+
+
diff --git a/Chapter14/demo/samples/crosstabs/build.xml b/Chapter14/demo/samples/crosstabs/build.xml
new file mode 100644
index 0000000..fc6a7dd
--- /dev/null
+++ b/Chapter14/demo/samples/crosstabs/build.xml
@@ -0,0 +1,169 @@
+
+
+ Crosstab and subdataset sample.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter14/demo/samples/crosstabs/readme.txt b/Chapter14/demo/samples/crosstabs/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter14/demo/samples/crosstabs/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/Chapter15/demo/samples/scriptlet/Scriptlet.java b/Chapter15/demo/samples/scriptlet/Scriptlet.java
new file mode 100644
index 0000000..84ad658
--- /dev/null
+++ b/Chapter15/demo/samples/scriptlet/Scriptlet.java
@@ -0,0 +1,158 @@
+/*
+ * ============================================================================
+ * 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.JRDefaultScriptlet;
+import net.sf.jasperreports.engine.JRScriptletException;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: Scriptlet.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class Scriptlet extends JRDefaultScriptlet
+{
+
+
+ /**
+ *
+ */
+ public void beforeReportInit() throws JRScriptletException
+ {
+ System.out.println("call beforeReportInit");
+ }
+
+
+ /**
+ *
+ */
+ public void afterReportInit() throws JRScriptletException
+ {
+ System.out.println("call afterReportInit");
+ }
+
+
+ /**
+ *
+ */
+ public void beforePageInit() throws JRScriptletException
+ {
+ System.out.println("call beforePageInit : PAGE_NUMBER = " + this.getVariableValue("PAGE_NUMBER"));
+ }
+
+
+ /**
+ *
+ */
+ public void afterPageInit() throws JRScriptletException
+ {
+ System.out.println("call afterPageInit : PAGE_NUMBER = " + this.getVariableValue("PAGE_NUMBER"));
+ }
+
+
+ /**
+ *
+ */
+ public void beforeColumnInit() throws JRScriptletException
+ {
+ System.out.println("call beforeColumnInit");
+ }
+
+
+ /**
+ *
+ */
+ public void afterColumnInit() throws JRScriptletException
+ {
+ System.out.println("call afterColumnInit");
+ }
+
+
+ /**
+ *
+ */
+ public void beforeGroupInit(String groupName) throws JRScriptletException
+ {
+ if (groupName.equals("CityGroup"))
+ {
+ System.out.println("call beforeGroupInit : City = " + this.getFieldValue("City"));
+ }
+ }
+
+
+ /**
+ *
+ */
+ public void afterGroupInit(String groupName) throws JRScriptletException
+ {
+ if (groupName.equals("CityGroup"))
+ {
+ System.out.println("call afterGroupInit : City = " + this.getFieldValue("City"));
+
+ 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 void beforeDetailEval() throws JRScriptletException
+ {
+ System.out.println(" detail");
+ }
+
+
+ /**
+ *
+ */
+ public void afterDetailEval() throws JRScriptletException
+ {
+ }
+
+
+ /**
+ *
+ */
+ public String hello() throws JRScriptletException
+ {
+ return "Hello! I'm the report's scriptlet object.";
+ }
+
+
+}
diff --git a/Chapter15/demo/samples/scriptlet/ScriptletApp.java b/Chapter15/demo/samples/scriptlet/ScriptletApp.java
new file mode 100644
index 0000000..f3304ca
--- /dev/null
+++ b/Chapter15/demo/samples/scriptlet/ScriptletApp.java
@@ -0,0 +1,299 @@
+/*
+ * ============================================================================
+ * 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.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: ScriptletApp.java 1665 2007-03-26 09:53:29Z teodord $
+ */
+public class ScriptletApp
+{
+
+
+ /**
+ *
+ */
+ 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", "Address 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.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
+ exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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.setParameter(JRExporterParameter.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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");
+
+ 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( "ScriptletApp usage:" );
+ System.out.println( "\tjava ScriptletApp -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/Chapter15/demo/samples/scriptlet/ScriptletReport.jrxml b/Chapter15/demo/samples/scriptlet/ScriptletReport.jrxml
new file mode 100644
index 0000000..846b200
--- /dev/null
+++ b/Chapter15/demo/samples/scriptlet/ScriptletReport.jrxml
@@ -0,0 +1,164 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+ $P{GreekText} + " " + $P{CyrillicText}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter17/demo/samples/nopagebreak/build.xml b/Chapter17/demo/samples/nopagebreak/build.xml
new file mode 100644
index 0000000..921afec
--- /dev/null
+++ b/Chapter17/demo/samples/nopagebreak/build.xml
@@ -0,0 +1,183 @@
+
+
+ Shows how reports can be designed and exported in a way that hides the existance of page breaks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter17/demo/samples/nopagebreak/readme.txt b/Chapter17/demo/samples/nopagebreak/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter17/demo/samples/nopagebreak/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/pdfencrypt/PdfEncryptApp.java b/Chapter17/demo/samples/pdfencrypt/PdfEncryptApp.java
new file mode 100644
index 0000000..532781e
--- /dev/null
+++ b/Chapter17/demo/samples/pdfencrypt/PdfEncryptApp.java
@@ -0,0 +1,147 @@
+/*
+ * ============================================================================
+ * 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 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.JasperPrint;
+import net.sf.jasperreports.engine.export.JRPdfExporter;
+import net.sf.jasperreports.engine.export.JRPdfExporterParameter;
+import net.sf.jasperreports.engine.util.JRLoader;
+
+import com.lowagie.text.pdf.PdfWriter;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: PdfEncryptApp.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class PdfEncryptApp
+{
+
+
+ /**
+ *
+ */
+ private static final String TASK_FILL = "fill";
+ private static final String TASK_PDF = "pdf";
+
+
+ /**
+ *
+ */
+ 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(fileName, null, new JREmptyDataSource());
+ System.err.println("Filling time : " + (System.currentTimeMillis() - start));
+ System.exit(0);
+ }
+ else if (TASK_PDF.equals(taskName))
+ {
+ File sourceFile = new File(fileName);
+
+ JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
+
+ File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pdf");
+
+ JRPdfExporter exporter = new JRPdfExporter();
+
+ exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
+ exporter.setParameter(JRExporterParameter.OUTPUT_FILE, destFile);
+ exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
+ exporter.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);
+ exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "jasper");
+ exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "reports");
+ exporter.setParameter(
+ JRPdfExporterParameter.PERMISSIONS,
+ new Integer(PdfWriter.AllowCopy | PdfWriter.AllowPrinting)
+ );
+
+ exporter.exportReport();
+
+ System.err.println("PDF 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( "PdfEncryptApp usage:" );
+ System.out.println( "\tjava PdfEncryptApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | pdf" );
+ }
+
+
+}
diff --git a/Chapter17/demo/samples/pdfencrypt/PdfEncryptReport.jrxml b/Chapter17/demo/samples/pdfencrypt/PdfEncryptReport.jrxml
new file mode 100644
index 0000000..0049fea
--- /dev/null
+++ b/Chapter17/demo/samples/pdfencrypt/PdfEncryptReport.jrxml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter17/demo/samples/pdfencrypt/build.xml b/Chapter17/demo/samples/pdfencrypt/build.xml
new file mode 100644
index 0000000..95e4237
--- /dev/null
+++ b/Chapter17/demo/samples/pdfencrypt/build.xml
@@ -0,0 +1,103 @@
+
+
+ Shows how reports could be encrypted when exported to PDF.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter17/demo/samples/pdfencrypt/readme.txt b/Chapter17/demo/samples/pdfencrypt/readme.txt
new file mode 100644
index 0000000..b75c678
--- /dev/null
+++ b/Chapter17/demo/samples/pdfencrypt/readme.txt
@@ -0,0 +1,14 @@
+
+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.
+
+
+The generated PDF document is encrypted using a 128 bit key.
+User password: jasper
+Owner password: reports
\ No newline at end of file
diff --git a/Chapter17/demo/samples/printservice/PrintServiceApp.java b/Chapter17/demo/samples/printservice/PrintServiceApp.java
new file mode 100644
index 0000000..4acb784
--- /dev/null
+++ b/Chapter17/demo/samples/printservice/PrintServiceApp.java
@@ -0,0 +1,274 @@
+/*
+ * ============================================================================
+ * 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.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.HashPrintServiceAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.attribute.standard.MediaSizeName;
+
+import net.sf.jasperreports.engine.JRAlignment;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JRExporterParameter;
+import net.sf.jasperreports.engine.JRImage;
+import net.sf.jasperreports.engine.JRImageRenderer;
+import net.sf.jasperreports.engine.JRPrintImage;
+import net.sf.jasperreports.engine.JRPrintLine;
+import net.sf.jasperreports.engine.JRPrintPage;
+import net.sf.jasperreports.engine.JRPrintText;
+import net.sf.jasperreports.engine.JasperPrint;
+import net.sf.jasperreports.engine.base.JRBasePrintImage;
+import net.sf.jasperreports.engine.base.JRBasePrintLine;
+import net.sf.jasperreports.engine.base.JRBasePrintPage;
+import net.sf.jasperreports.engine.base.JRBasePrintText;
+import net.sf.jasperreports.engine.design.JRDesignStyle;
+import net.sf.jasperreports.engine.export.JRPrintServiceExporter;
+import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;
+import net.sf.jasperreports.engine.util.JRLoader;
+import net.sf.jasperreports.engine.util.JRSaver;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: PrintServiceApp.java 1507 2006-11-27 15:12:17Z teodord $
+ */
+public class PrintServiceApp
+{
+
+
+ /**
+ *
+ */
+ private static final String TASK_FILL = "fill";
+ private static final String TASK_PRINT = "print";
+
+
+ /**
+ *
+ */
+ 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))
+ {
+ JasperPrint jasperPrint = getJasperPrint();
+ JRSaver.saveObject(jasperPrint, fileName);
+ System.err.println("Filling time : " + (System.currentTimeMillis() - start));
+ System.exit(0);
+ }
+ else if (TASK_PRINT.equals(taskName))
+ {
+ PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
+ printRequestAttributeSet.add(MediaSizeName.ISO_A4);
+
+ PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
+ //printServiceAttributeSet.add(new PrinterName("Epson Stylus 800 ESC/P 2", null));
+ //printServiceAttributeSet.add(new PrinterName("HP LaserJet 4P", null));
+
+ JRPrintServiceExporter exporter = new JRPrintServiceExporter();
+
+ exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, fileName);
+ exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
+ exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
+ exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
+ exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
+
+ exporter.exportReport();
+
+ System.err.println("Printing 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( "PrintServiceApp usage:" );
+ System.out.println( "\tjava PrintServiceApp -Ttask -Ffile" );
+ System.out.println( "\tTasks : fill | print" );
+ }
+
+
+ /**
+ *
+ */
+ private static JasperPrint getJasperPrint() throws JRException
+ {
+ //JasperPrint
+ JasperPrint jasperPrint = new JasperPrint();
+ jasperPrint.setName("NoReport");
+ jasperPrint.setPageWidth(595);
+ jasperPrint.setPageHeight(842);
+
+ //Fonts
+ JRDesignStyle normalStyle = new JRDesignStyle();
+ normalStyle.setName("Arial_Normal");
+ normalStyle.setDefault(true);
+ normalStyle.setFontName("Arial");
+ normalStyle.setFontSize(8);
+ normalStyle.setPdfFontName("Helvetica");
+ normalStyle.setPdfEncoding("Cp1252");
+ normalStyle.setPdfEmbedded(false);
+ jasperPrint.addStyle(normalStyle);
+
+ JRDesignStyle boldStyle = new JRDesignStyle();
+ boldStyle.setName("Arial_Bold");
+ boldStyle.setFontName("Arial");
+ boldStyle.setFontSize(8);
+ boldStyle.setBold(true);
+ boldStyle.setPdfFontName("Helvetica-Bold");
+ boldStyle.setPdfEncoding("Cp1252");
+ boldStyle.setPdfEmbedded(false);
+ jasperPrint.addStyle(boldStyle);
+
+ JRDesignStyle italicStyle = new JRDesignStyle();
+ italicStyle.setName("Arial_Italic");
+ italicStyle.setFontName("Arial");
+ italicStyle.setFontSize(8);
+ italicStyle.setItalic(true);
+ italicStyle.setPdfFontName("Helvetica-Oblique");
+ italicStyle.setPdfEncoding("Cp1252");
+ italicStyle.setPdfEmbedded(false);
+ jasperPrint.addStyle(italicStyle);
+
+ JRPrintPage page = new JRBasePrintPage();
+
+ JRPrintLine line = new JRBasePrintLine(jasperPrint.getDefaultStyleProvider());
+ line.setX(40);
+ line.setY(50);
+ line.setWidth(515);
+ line.setHeight(0);
+ page.addElement(line);
+
+ JRPrintImage image = new JRBasePrintImage(jasperPrint.getDefaultStyleProvider());
+ image.setX(45);
+ image.setY(55);
+ image.setWidth(165);
+ image.setHeight(40);
+ image.setScaleImage(JRImage.SCALE_IMAGE_CLIP);
+ image.setRenderer(
+ JRImageRenderer.getInstance(
+ JRLoader.loadBytesFromLocation("jasperreports.gif")
+ )
+ );
+ page.addElement(image);
+
+ JRPrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
+ text.setX(210);
+ text.setY(55);
+ text.setWidth(345);
+ text.setHeight(30);
+ text.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
+ text.setLineSpacingFactor(1.3133681f);
+ text.setLeadingOffset(-4.955078f);
+ text.setStyle(boldStyle);
+ text.setFontSize(18);
+ text.setText("JasperReports Project Description");
+ page.addElement(text);
+
+ text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
+ text.setX(210);
+ text.setY(85);
+ text.setWidth(325);
+ text.setHeight(15);
+ text.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
+ text.setLineSpacingFactor(1.329241f);
+ text.setLeadingOffset(-4.076172f);
+ text.setStyle(italicStyle);
+ text.setFontSize(12);
+ text.setText((new SimpleDateFormat("EEE, MMM d, yyyy")).format(new Date()));
+ page.addElement(text);
+
+ text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
+ text.setX(40);
+ text.setY(150);
+ text.setWidth(515);
+ text.setHeight(200);
+ text.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED);
+ text.setLineSpacingFactor(1.329241f);
+ text.setLeadingOffset(-4.076172f);
+ text.setStyle(normalStyle);
+ text.setFontSize(14);
+ text.setText(
+ "JasperReports is a powerful report-generating tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV or XML files.\n\n" +
+ "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.\n\n" +
+ "Its main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner."
+ );
+ page.addElement(text);
+
+ jasperPrint.addPage(page);
+
+ return jasperPrint;
+ }
+
+
+}
diff --git a/Chapter17/demo/samples/printservice/build.xml b/Chapter17/demo/samples/printservice/build.xml
new file mode 100644
index 0000000..4eae69d
--- /dev/null
+++ b/Chapter17/demo/samples/printservice/build.xml
@@ -0,0 +1,71 @@
+
+
+ Shows how the Java Print Service API could be used to print reports.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter17/demo/samples/printservice/jasperreports.gif b/Chapter17/demo/samples/printservice/jasperreports.gif
new file mode 100644
index 0000000..2c230a8
Binary files /dev/null and b/Chapter17/demo/samples/printservice/jasperreports.gif differ
diff --git a/Chapter17/demo/samples/printservice/readme.txt b/Chapter17/demo/samples/printservice/readme.txt
new file mode 100644
index 0000000..880564d
--- /dev/null
+++ b/Chapter17/demo/samples/printservice/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/scriptlet/Scriptlet.java b/Chapter17/demo/samples/scriptlet/Scriptlet.java
new file mode 100644
index 0000000..84ad658
--- /dev/null
+++ b/Chapter17/demo/samples/scriptlet/Scriptlet.java
@@ -0,0 +1,158 @@
+/*
+ * ============================================================================
+ * 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.JRDefaultScriptlet;
+import net.sf.jasperreports.engine.JRScriptletException;
+
+
+/**
+ * @author Teodor Danciu (teodord@users.sourceforge.net)
+ * @version $Id: Scriptlet.java 1229 2006-04-19 10:27:35Z teodord $
+ */
+public class Scriptlet extends JRDefaultScriptlet
+{
+
+
+ /**
+ *
+ */
+ public void beforeReportInit() throws JRScriptletException
+ {
+ System.out.println("call beforeReportInit");
+ }
+
+
+ /**
+ *
+ */
+ public void afterReportInit() throws JRScriptletException
+ {
+ System.out.println("call afterReportInit");
+ }
+
+
+ /**
+ *
+ */
+ public void beforePageInit() throws JRScriptletException
+ {
+ System.out.println("call beforePageInit : PAGE_NUMBER = " + this.getVariableValue("PAGE_NUMBER"));
+ }
+
+
+ /**
+ *
+ */
+ public void afterPageInit() throws JRScriptletException
+ {
+ System.out.println("call afterPageInit : PAGE_NUMBER = " + this.getVariableValue("PAGE_NUMBER"));
+ }
+
+
+ /**
+ *
+ */
+ public void beforeColumnInit() throws JRScriptletException
+ {
+ System.out.println("call beforeColumnInit");
+ }
+
+
+ /**
+ *
+ */
+ public void afterColumnInit() throws JRScriptletException
+ {
+ System.out.println("call afterColumnInit");
+ }
+
+
+ /**
+ *
+ */
+ public void beforeGroupInit(String groupName) throws JRScriptletException
+ {
+ if (groupName.equals("CityGroup"))
+ {
+ System.out.println("call beforeGroupInit : City = " + this.getFieldValue("City"));
+ }
+ }
+
+
+ /**
+ *
+ */
+ public void afterGroupInit(String groupName) throws JRScriptletException
+ {
+ if (groupName.equals("CityGroup"))
+ {
+ System.out.println("call afterGroupInit : City = " + this.getFieldValue("City"));
+
+ 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 void beforeDetailEval() throws JRScriptletException
+ {
+ System.out.println(" detail");
+ }
+
+
+ /**
+ *
+ */
+ public void afterDetailEval() throws JRScriptletException
+ {
+ }
+
+
+ /**
+ *
+ */
+ public String hello() throws JRScriptletException
+ {
+ return "Hello! I'm the report's scriptlet object.";
+ }
+
+
+}
diff --git a/Chapter17/demo/samples/scriptlet/ScriptletApp.java b/Chapter17/demo/samples/scriptlet/ScriptletApp.java
new file mode 100644
index 0000000..f3304ca
--- /dev/null
+++ b/Chapter17/demo/samples/scriptlet/ScriptletApp.java
@@ -0,0 +1,299 @@
+/*
+ * ============================================================================
+ * 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.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: ScriptletApp.java 1665 2007-03-26 09:53:29Z teodord $
+ */
+public class ScriptletApp
+{
+
+
+ /**
+ *
+ */
+ 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", "Address 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.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
+ exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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.setParameter(JRExporterParameter.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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.PROGRESS_MONITOR, new SimpleExportProgressMonitor());
+
+ 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");
+
+ 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( "ScriptletApp usage:" );
+ System.out.println( "\tjava ScriptletApp -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/scriptlet/ScriptletReport.jrxml b/Chapter17/demo/samples/scriptlet/ScriptletReport.jrxml
new file mode 100644
index 0000000..846b200
--- /dev/null
+++ b/Chapter17/demo/samples/scriptlet/ScriptletReport.jrxml
@@ -0,0 +1,164 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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("
+ 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:
+
+
+
+
+
+ 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.
+
+
+
+
+
+
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
+
+
+
+
+
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+ 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.
+
+
+
+
+
+
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 :
+
+
+
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();
+%>
+
+
+
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter19/demo/samples/webapp/stylesheet.css b/Chapter19/demo/samples/webapp/stylesheet.css
new file mode 100644
index 0000000..1129168
--- /dev/null
+++ b/Chapter19/demo/samples/webapp/stylesheet.css
@@ -0,0 +1,170 @@
+.menu
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#FFFFFF;
+ background:#999999;
+ text-decoration:none
+}
+
+.menu:hover
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+ background:#999999;
+ text-decoration:none
+}
+
+.mnew
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#990000;
+ background:#999999;
+ text-decoration:none
+}
+
+.header
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#FFFFFF;
+ background:#808080;
+}
+
+.doc
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:12pt;
+ font-weight:bold;
+ color:#000000;
+ background:#808080;
+}
+
+.title
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#000000;
+}
+
+.bold
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#000000;
+}
+
+.bnew
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#990000;
+}
+
+.elem
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ color:#000000;
+ background:#EEEEEE;
+}
+
+.attr
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:bold;
+ font-style:italic;
+ color:#000000;
+}
+
+.val
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-style:italic;
+ color:#000000;
+}
+
+.normal
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+}
+
+.justify
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+ text-align:justify;
+}
+
+.desc
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ font-weight:normal;
+ color:#000000;
+}
+
+.notImpl
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:10pt;
+ color:#FF0000;
+}
+
+.note
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:8pt;
+ font-style:italic;
+ color:#000000;
+}
+
+.small
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:8pt;
+ color:#000000;
+}
+
+.version
+{
+ font-decoration:none;
+ font-family:Verdana;
+ font-size:8pt;
+ font-style:italic;
+ color:#FFFFFF;
+}
diff --git a/Chapter19/demo/samples/webapp/viewer.html b/Chapter19/demo/samples/webapp/viewer.html
new file mode 100644
index 0000000..ed90f90
--- /dev/null
+++ b/Chapter19/demo/samples/webapp/viewer.html
@@ -0,0 +1,62 @@
+
+
+
+JasperReports - Web Application Sample
+
+
+
+
+
+Embedded Viewer 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/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..ac26f09
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,27 @@
+Freeware License, some rights reserved
+
+Copyright (c) 2007 Teodor Danciu and Lucian Chirita
+
+Permission is hereby granted, free of charge, to anyone obtaining a copy
+of this software and associated documentation files (the "Software"),
+to work with the Software within the limits of freeware distribution and fair use.
+This includes the rights to use, copy, and modify the Software for personal use.
+Users are also allowed and encouraged to submit corrections and modifications
+to the Software for the benefit of other users.
+
+It is not allowed to reuse, modify, or redistribute the Software for
+commercial use in any way, or for a user’s educational materials such as books
+or blog articles without prior permission from the copyright holder.
+
+The above copyright notice and this permission notice need to be included
+in all copies or substantial portions of the software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b182f72
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+#Apress Source Code
+
+This repository accompanies [*The Definitive Guide to JasperReports*](http://www.apress.com/9781590599273) by Teodor Danciu and Lucian Chirita (Apress, 2007).
+
+![Cover image](9781590599273.jpg)
+
+Download the files as a zip using the green button, or clone the repository to your machine using Git.
+
+##Releases
+
+Release v1.0 corresponds to the code in the published book, without corrections or updates.
+
+##Contributions
+
+See the file Contributing.md for more information on how you can contribute to this repository.
diff --git a/contributing.md b/contributing.md
new file mode 100644
index 0000000..f6005ad
--- /dev/null
+++ b/contributing.md
@@ -0,0 +1,14 @@
+# Contributing to Apress Source Code
+
+Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
+
+## How to Contribute
+
+1. Make sure you have a GitHub account.
+2. Fork the repository for the relevant book.
+3. Create a new branch on which to make your change, e.g.
+`git checkout -b my_code_contribution`
+4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
+5. Submit a pull request.
+
+Thank you for your contribution!
\ No newline at end of file
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..bed9541
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,11 @@
+
+The Definitive Guide to JasperReports - Source Code
+=====================================================
+
+This package contains all the samples mentioned in the book.
+If the same sample is referenced in two different chapters, each of the chapter folders will contain a copy of the sample.
+
+These samples are taken from the public JasperReports source code distribution package, where they can be found under the /demo/samples folder.
+
+We recommend that you test the samples from the project distribution package, which can be downloaded from here:
+http://sourceforge.net/project/showfiles.php?group_id=36382