import java.io.IOException; import java.io.Writer; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Vector; import dori.jasper.engine.JRException; import dori.jasper.engine.JRExporterParameter; import dori.jasper.engine.JasperFillManager; import dori.jasper.engine.JasperPrint; import dori.jasper.engine.export.JRHtmlExporter; import dori.jasper.engine.export.JRHtmlExporterParameter; /* * Created on 5/11/2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ /** * @author bsutton * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class JasperHTMLReport extends JasperReport { JasperPrint m_jasperPrint; Map m_imagesMap = new HashMap(); JasperHTMLReport( String strReportPath, String strTitle, String strImagePath, Map mapParameters) throws JRException, IOException { super(strReportPath, strTitle, strImagePath, mapParameters); } protected void write(Connection conn, Writer out) throws IOException, SQLException, JRException { //validate(); format(conn); output(out); } protected void format(Connection conn) throws SQLException, JRException { m_jasperPrint = JasperFillManager.fillReport(m_report, m_mapParameters, conn); } protected void output(Writer out) throws JRException, IOException { JRHtmlExporter exporter = new JRHtmlExporter(); StringBuffer sbuffer = new StringBuffer(); exporter.setParameter( JRExporterParameter.JASPER_PRINT, m_jasperPrint); exporter.setParameter( JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer); exporter.setParameter( JRHtmlExporterParameter.IMAGES_MAP, m_imagesMap); exporter.setParameter( JRHtmlExporterParameter.IMAGES_URI, getImageURI()); // Export the report to the string buffer sbuffer. exporter.exportReport(); // Write report to browser. out.write(sbuffer.toString()); } /** * Returns a vector containing all images used by the * report as DataSource's. * @return */ public Vector getImageDataSource() { if (m_jasperPrint == null) throw new IllegalStateException("You must call send() before this function."); Vector vImages = new Vector(); Iterator iterKey = m_imagesMap.keySet().iterator(); while (iterKey.hasNext()) { String strSource = (String)iterKey.next(); byte[] imageData = (byte[])m_imagesMap.get(strSource); vImages.add(new ByteArrayDataSource(strSource, imageData, "image/gif")); } return vImages; } protected String getImageURI() { return "cid:"; } }