Update of /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32337/src/java/wicket/contrib/jasperreports
Modified Files:
JRRtfResource.java JRResource.java JRPdfResource.java
JRTextResource.java JRCsvResource.java JRHtmlResource.java
JRImageResource.java EmbeddedJRReport.java JRXlsResource.java
Removed Files:
JRObject.java
Log Message:
style & doc fixes
removed JRObject and moved that code into EmbeddedJRReport
--- JRObject.java DELETED ---
Index: JRCsvResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRCsvResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JRCsvResource.java 20 Mar 2006 04:35:27 -0000 1.3
--- JRCsvResource.java 20 Mar 2006 07:12:12 -0000 1.4
***************
*** 1,14 ****
/*
! * $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
! * $Id$ $Revision:
! * 1.3 $ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 28,85 ****
/**
* Resource class for jasper reports CSV resources.
! *
* @author Eelco Hillenius
*/
! public final class JRCsvResource extends JRResource {
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRCsvResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRCsvResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRCsvResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRCsvResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter() {
! return new JRCsvExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "text/plain";
}
! public String getExtension() {
! return "csv";
! }
}
--- 27,99 ----
/**
* Resource class for jasper reports CSV resources.
! *
* @author Eelco Hillenius
*/
! public final class JRCsvResource extends JRResource
! {
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRCsvResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRCsvResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRCsvResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRCsvResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter()
! {
! return new JRCsvExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "text/plain";
}
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return "csv";
! }
}
Index: JRPdfResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRPdfResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JRPdfResource.java 20 Mar 2006 04:35:27 -0000 1.3
--- JRPdfResource.java 20 Mar 2006 07:12:12 -0000 1.4
***************
*** 1,14 ****
/*
! * $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
! * $Id$ $Revision:
! * 1.3 $ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 28,85 ****
/**
* Resource class for jasper reports PDF resources.
! *
* @author Eelco Hillenius
*/
! public final class JRPdfResource extends JRResource {
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRPdfResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRPdfResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRPdfResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRPdfResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter() {
! return new JRPdfExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "application/pdf";
}
! public String getExtension() {
! return "pdf";
! }
}
--- 27,99 ----
/**
* Resource class for jasper reports PDF resources.
! *
* @author Eelco Hillenius
*/
! public final class JRPdfResource extends JRResource
! {
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRPdfResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRPdfResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRPdfResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRPdfResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter()
! {
! return new JRPdfExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "application/pdf";
}
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return "pdf";
! }
}
Index: EmbeddedJRReport.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/EmbeddedJRReport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** EmbeddedJRReport.java 20 Mar 2006 04:35:26 -0000 1.3
--- EmbeddedJRReport.java 20 Mar 2006 07:12:12 -0000 1.4
***************
*** 1,14 ****
/*
* $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
* $Id$
! * $Revision$ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 19,23 ****
package wicket.contrib.jasperreports;
- import wicket.Component;
import wicket.IResourceListener;
import wicket.ResourceReference;
--- 18,21 ----
***************
*** 26,71 ****
/**
! * Component for embedding a jasper report in a page. This component must be attached to either a frame- or an iframe
! * tag. If you don't want to embed the report, but have a link to it instead, use {@link ResourceReference}.
! *
! * @author Eelco Hillenius
! * @deprecated use {@link JRObject} instead. Frames and IFrames have plugin issues.
*/
! public final class EmbeddedJRReport extends WebComponent implements
! IResourceListener {
! /**
! * the report resource.
! */
! private final JRResource resource;
! /**
! * Construcxt.
! *
! * @param componentID component componentID
! * @param jrResource the jrResource
! */
! public EmbeddedJRReport(String componentID, JRResource jrResource) {
! super(componentID);
! this.resource = jrResource;
! }
! /**
! * @see Component#onComponentTag(ComponentTag)
! */
! protected void onComponentTag(ComponentTag tag) {
! if((!"frame".equalsIgnoreCase(tag.getName())) && (!"iframe".equalsIgnoreCase(tag.getName()))) {
! findMarkupStream().throwMarkupException("Component " + getId()
! + " must be applied to a tag of type 'frame' or 'iframe', not " + tag.toUserDebugString());
! }
! String url = urlFor(IResourceListener.INTERFACE);
! tag.put("src", getResponse().encodeURL(url));
! super.onComponentTag(tag);
! }
! /**
! * @see IResourceListener#onResourceRequested()
! */
! public void onResourceRequested() {
! resource.onResourceRequested();
}
}
\ No newline at end of file
--- 24,74 ----
/**
! * Component for embedding a jasper report in a page. This component must be
! * attached to an <object> tag. If you don't want to embed the report, but
! * have a link to it instead, use {@link ResourceReference}.
! *
! * @author <a href="mailto:evanchooly@... Lee</a>
*/
! public final class EmbeddedJRReport extends WebComponent implements IResourceListener
! {
! private final JRResource resource;
! /**
! * Construcxt.
! *
! * @param componentID
! * component componentID
! * @param resource
! * the resource
! */
! public EmbeddedJRReport(String componentID, JRResource resource)
! {
! super(componentID);
! this.resource = resource;
! }
! /**
! * @see wicket.IResourceListener#onResourceRequested()
! */
! public void onResourceRequested()
! {
! resource.onResourceRequested();
! }
! /**
! * @see wicket.Component#onComponentTag(wicket.markup.ComponentTag)
! */
! protected void onComponentTag(ComponentTag tag)
! {
! if (!"object".equalsIgnoreCase(tag.getName()))
! {
! findMarkupStream().throwMarkupException(
! "Component "
! + getId() + " must be applied to a tag of type 'object' not "
! + tag.toUserDebugString());
! }
! tag.put("data", getResponse().encodeURL(urlFor(IResourceListener.INTERFACE)));
! tag.put("type", resource.getContentType());
! super.onComponentTag(tag);
}
}
\ No newline at end of file
Index: JRResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRResource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** JRResource.java 20 Mar 2006 04:35:27 -0000 1.4
--- JRResource.java 20 Mar 2006 07:12:12 -0000 1.5
***************
*** 1,14 ****
/*
! * $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
! * $Id$ $Revision:
! * 1.4 $ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 35,40 ****
--- 34,41 ----
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import wicket.WicketRuntimeException;
import wicket.markup.html.WebResource;
***************
*** 44,412 ****
/**
* Base class for jasper reports resources.
! *
* @author Eelco Hillenius
* @author Matej Knopp
*/
! public abstract class JRResource extends DynamicByteArrayResource {
! /**
! * logger.
! */
! private static Log log = LogFactory.getLog(JRResource.class);
! /**
! * Provides JDBC connection.
! */
! public static interface IDatabaseConnectionProvider extends Serializable {
! /**
! * Gets a JDBC connection to use when filling the report.
! *
! * @return a JDBC connection
! */
! Connection get();
! /**
! * Called when the report is generated and the connection can be released again.
! */
! void release();
! }
! /**
! * Factory class for lazy initialization of the jasper report.
! */
! private static interface JasperReportFactory extends Serializable {
! /**
! * Create a jasper report instance.
! *
! * @return the new jasper report instance.
! *
! * @throws JRException
! */
! JasperReport newJasperReport() throws JRException;
! }
! ;
! /**
! * the connection provider if any for filling this report.
! */
! private IDatabaseConnectionProvider connectionProvider;
! /**
! * factory for delayed report creation.
! */
! private JasperReportFactory jasperReportFactory;
! /**
! * The compiled report this resource references. Made transient as we don't want our report to be serialized while we
! * can recreate it at other servers at will using the factory.
! */
! private transient JasperReport jasperReport;
! /**
! * the report parameters.
! */
! private Map reportParameters;
! /**
! * the datasource if any for filling this report.
! */
! private JRDataSource reportDataSource;
! /**
! * When set, a header 'Content-Disposition: attachment; filename="${fileName}"' will be added to the response,
! * resulting in a download dialog. No magical extensions are added, so you should make sure the file has the extension
! * you want yourself.
! */
! private String fileName;
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRResource() {
! super();
! setCacheable(false);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRResource(final InputStream report) {
! this(new JasperReportFactory() {
! public JasperReport newJasperReport() throws JRException {
! return (JasperReport)JRLoader.loadObject(report);
! }
! ;
! });
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRResource(final URL report) {
! this(new JasperReportFactory() {
! public JasperReport newJasperReport() throws JRException {
! return (JasperReport)JRLoader.loadObject(report);
! }
! ;
! });
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRResource(final File report) {
! this(new JasperReportFactory() {
! public JasperReport newJasperReport() throws JRException {
! return (JasperReport)JRLoader.loadObject(report);
! }
! ;
! });
! }
! /**
! * Construct.
! *
! * @param factory report factory for lazy initialization
! */
! private JRResource(JasperReportFactory factory) {
! super();
! setCacheable(false);
! this.jasperReportFactory = factory;
! }
! /**
! * Gets jasperReport. This implementation uses an internal factory to lazily create the report. After creation the
! * report is cached (set as the jasperReport property). Override this method in case you want to provide some
! * alternative creation/ caching scheme.
! *
! * @return jasperReport
! */
! public JasperReport getJasperReport() {
! // if the report has not yet been initialized and can be, initialize it
! if(jasperReport == null && jasperReportFactory != null) {
! try {
! setJasperReport(jasperReportFactory.newJasperReport());
! }
! catch(JRException e) {
! throw new WicketRuntimeException(e);
! }
! }
! return jasperReport;
! }
! /**
! * Sets {bjasperReport.
! *
! * @param report report
! */
! public final void setJasperReport(JasperReport report) {
! this.jasperReport = report;
! }
! /**
! * Gets the report parameters.
! *
! * @return report parameters
! */
! public Map getReportParameters() {
! return reportParameters;
! }
! /**
! * Sets the report parameters.
! *
! * @param params report parameters
! *
! * @return This
! */
! public final JRResource setReportParameters(Map params) {
! this.reportParameters = params;
! return this;
! }
! /**
! * Gets the datasource if any for filling this report.
! *
! * @return the datasource if any for filling this report
! */
! public JRDataSource getReportDataSource() {
! return reportDataSource;
! }
! /**
! * Sets the datasource if any for filling this report.
! *
! * @param dataSource the datasource if any for filling this report
! *
! * @return This
! */
! public JRResource setReportDataSource(JRDataSource dataSource) {
! this.reportDataSource = dataSource;
! return this;
! }
! /**
! * Gets the connection provider if any for filling this report.
! *
! * @return the connection provider if any for filling this report
! */
! public IDatabaseConnectionProvider getConnectionProvider() {
! return connectionProvider;
! }
! /**
! * Sets the connection provider if any for filling this report.
! *
! * @param provider the connection provider if any for filling this report
! *
! * @return This
! */
! public final JRResource setConnectionProvider(IDatabaseConnectionProvider provider) {
! this.connectionProvider = provider;
! return this;
! }
! /**
! * Gets the file name. When set, a header 'Content-Disposition: attachment; filename="${fileName}"' will be added to
! * the response, resulting in a download dialog. No magical extensions are added, so you should make sure the file has
! * the extension you want yourself.
! *
! * @return the file name
! */
! public String getFileName() {
! if(fileName == null) {
! fileName = getJasperReport().getName() + "." + getExtension();
! }
! return fileName;
! }
! /**
! * Returns the extension for the resource's file. This string should not contain the leading "."
! */
! public abstract String getExtension();
! /**
! * Sets the file name. When set, a header 'Content-Disposition: attachment; filename="${name}"' will be added to
! * the response, resulting in a download dialog. No magical extensions are added, so you should make sure the file has
! * the extension you want yourself.
! *
! * @param name the file name
! *
! * @return This
! */
! public final JRResource setFileName(String name) {
! this.fileName = name;
! return this;
! }
! /**
! * Called by getData to obtain an exporter instance.
! *
! * @return an exporter instance
! */
! protected abstract JRAbstractExporter newExporter();
! /**
! * Gets the binary data by getting a new instance of JasperPrint and an exporter for generating the output.
! *
! * @return the binary data
! *
! * @see DynamicByteArrayResource#getResourceState()
! */
! protected ResourceState getResourceState() {
! try {
! long t1 = System.currentTimeMillis();
! // get a print instance for exporting
! JasperPrint print = newJasperPrint();
! // get a fresh instance of an exporter for this report
! JRAbstractExporter exporter = newExporter();
! // prepare a stream to trap the exporter's output
! ByteArrayOutputStream baos = new ByteArrayOutputStream();
! exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
! exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
! // execute the export and return the trapped result
! exporter.exportReport();
! final byte[] data = baos.toByteArray();
! if(log.isDebugEnabled()) {
! long t2 = System.currentTimeMillis();
! log.debug("loaded report data; bytes: "
! + data.length + " in " + (t2 - t1) + " miliseconds");
! }
! return new ResourceState() {
! public int getLength() {
! return data.length;
! }
! public byte[] getData() {
! return data;
! }
! public String getContentType() {
! return JRResource.this.getContentType();
! }
! };
! }
! catch(JRException e) {
! throw new WicketRuntimeException(e);
! }
! }
! /**
! * @return The content type of the reports
! */
! public abstract String getContentType();
! /**
! * Creates a new {@link JasperPrint} instance. This instance is specific for this render, but it not yet designated for
! * one output format only.
! *
! * @return a new {@link JasperPrint} instance.
! *
! * @throws JRException
! */
! protected JasperPrint newJasperPrint() throws JRException {
! final JasperPrint jasperPrint;
! JasperReport report = getJasperReport();
! Map params = getReportParameters();
! JRDataSource dataSource = getReportDataSource();
! if(dataSource != null) {
! jasperPrint = JasperFillManager.fillReport(report, params,
! dataSource);
! } else {
! IDatabaseConnectionProvider provider = null;
! try {
! provider = getConnectionProvider();
! if(provider == null) {
! throw new IllegalStateException("JasperReportsResources must either have a JRDataSource, "
! + "or a JDBC Connection provided");
! }
! jasperPrint = JasperFillManager.fillReport(report,
! params, provider.get());
! }
! finally {
! if(provider != null) {
! provider.release();
! }
! }
! }
! return jasperPrint;
! }
! /**
! * @see WebResource#setHeaders(WebResponse)
! */
! protected void setHeaders(WebResponse response) {
! super.setHeaders(response);
! String name = getFileName();
! if(name != null) {
! response.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\"");
! }
! }
}
\ No newline at end of file
--- 45,486 ----
/**
* Base class for jasper reports resources.
! *
* @author Eelco Hillenius
* @author Matej Knopp
*/
! public abstract class JRResource extends DynamicByteArrayResource
! {
! /**
! * logger.
! */
! private static Log log = LogFactory.getLog(JRResource.class);
! /**
! * Provides JDBC connection.
! */
! public static interface IDatabaseConnectionProvider extends Serializable
! {
! /**
! * Gets a JDBC connection to use when filling the report.
! *
! * @return a JDBC connection
! */
! Connection get();
! /**
! * Called when the report is generated and the connection can be
! * released again.
! */
! void release();
! }
! /**
! * Factory class for lazy initialization of the jasper report.
! */
! private static interface JasperReportFactory extends Serializable
! {
! /**
! * Create a jasper report instance.
! *
! * @return the new jasper report instance.
! *
! * @throws JRException
! */
! JasperReport newJasperReport() throws JRException;
! }
! ;
! /**
! * the connection provider if any for filling this report.
! */
! private IDatabaseConnectionProvider connectionProvider;
! /**
! * factory for delayed report creation.
! */
! private JasperReportFactory jasperReportFactory;
! /**
! * The compiled report this resource references. Made transient as we don't
! * want our report to be serialized while we can recreate it at other
! * servers at will using the factory.
! */
! private transient JasperReport jasperReport;
! /**
! * the report parameters.
! */
! private Map reportParameters;
! /**
! * the datasource if any for filling this report.
! */
! private JRDataSource reportDataSource;
! /**
! * When set, a header 'Content-Disposition: attachment;
! * filename="${fileName}"' will be added to the response, resulting in a
! * download dialog. No magical extensions are added, so you should make sure
! * the file has the extension you want yourself.
! */
! private String fileName;
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRResource()
! {
! super();
! setCacheable(false);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRResource(final InputStream report)
! {
! this(new JasperReportFactory()
! {
! public JasperReport newJasperReport() throws JRException
! {
! return (JasperReport) JRLoader.loadObject(report);
! }
! ;
! });
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRResource(final URL report)
! {
! this(new JasperReportFactory()
! {
! public JasperReport newJasperReport() throws JRException
! {
! return (JasperReport) JRLoader.loadObject(report);
! }
! ;
! });
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRResource(final File report)
! {
! this(new JasperReportFactory()
! {
! public JasperReport newJasperReport() throws JRException
! {
! return (JasperReport) JRLoader.loadObject(report);
! }
! ;
! });
! }
! /**
! * Construct.
! *
! * @param factory
! * report factory for lazy initialization
! */
! private JRResource(JasperReportFactory factory)
! {
! super();
! setCacheable(false);
! this.jasperReportFactory = factory;
! }
! /**
! * Gets jasperReport. This implementation uses an internal factory to lazily
! * create the report. After creation the report is cached (set as the
! * jasperReport property). Override this method in case you want to provide
! * some alternative creation/ caching scheme.
! *
! * @return jasperReport
! */
! public JasperReport getJasperReport()
! {
! // if the report has not yet been initialized and can be, initialize it
! if (jasperReport == null && jasperReportFactory != null)
! {
! try
! {
! setJasperReport(jasperReportFactory.newJasperReport());
! }
! catch (JRException e)
! {
! throw new WicketRuntimeException(e);
! }
! }
! return jasperReport;
! }
! /**
! * Sets {bjasperReport.
! *
! * @param report
! * report
! */
! public final void setJasperReport(JasperReport report)
! {
! this.jasperReport = report;
! }
! /**
! * Gets the report parameters.
! *
! * @return report parameters
! */
! public Map getReportParameters()
! {
! return reportParameters;
! }
! /**
! * Sets the report parameters.
! *
! * @param params
! * report parameters
! *
! * @return This
! */
! public final JRResource setReportParameters(Map params)
! {
! this.reportParameters = params;
! return this;
! }
! /**
! * Gets the datasource if any for filling this report.
! *
! * @return the datasource if any for filling this report
! */
! public JRDataSource getReportDataSource()
! {
! return reportDataSource;
! }
! /**
! * Sets the datasource if any for filling this report.
! *
! * @param dataSource
! * the datasource if any for filling this report
! *
! * @return This
! */
! public JRResource setReportDataSource(JRDataSource dataSource)
! {
! this.reportDataSource = dataSource;
! return this;
! }
! /**
! * Gets the connection provider if any for filling this report.
! *
! * @return the connection provider if any for filling this report
! */
! public IDatabaseConnectionProvider getConnectionProvider()
! {
! return connectionProvider;
! }
! /**
! * Sets the connection provider if any for filling this report.
! *
! * @param provider
! * the connection provider if any for filling this report
! *
! * @return This
! */
! public final JRResource setConnectionProvider(IDatabaseConnectionProvider provider)
! {
! this.connectionProvider = provider;
! return this;
! }
! /**
! * Gets the file name. When set, a header 'Content-Disposition: attachment;
! * filename="${fileName}"' will be added to the response, resulting in a
! * download dialog. No magical extensions are added, so you should make sure
! * the file has the extension you want yourself.
! *
! * @return the file name
! */
! public String getFileName()
! {
! if (fileName == null)
! {
! fileName = getJasperReport().getName() + "." + getExtension();
! }
! return fileName;
! }
! /**
! * Sets the file name. When set, a header 'Content-Disposition: attachment;
! * filename="${name}"' will be added to the response, resulting in a
! * download dialog. No magical extensions are added, so you should make sure
! * the file has the extension you want yourself.
! *
! * @param name
! * the file name
! *
! * @return This
! */
! public final JRResource setFileName(String name)
! {
! this.fileName = name;
! return this;
! }
! /**
! * Called by getData to obtain an exporter instance.
! *
! * @return an exporter instance
! */
! protected abstract JRAbstractExporter newExporter();
! /**
! * Gets the binary data by getting a new instance of JasperPrint and an
! * exporter for generating the output.
! *
! * @return the binary data
! *
! * @see DynamicByteArrayResource#getResourceState()
! */
! protected ResourceState getResourceState()
! {
! try
! {
! long t1 = System.currentTimeMillis();
! // get a print instance for exporting
! JasperPrint print = newJasperPrint();
! // get a fresh instance of an exporter for this report
! JRAbstractExporter exporter = newExporter();
! // prepare a stream to trap the exporter's output
! ByteArrayOutputStream baos = new ByteArrayOutputStream();
! exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
! exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
! // execute the export and return the trapped result
! exporter.exportReport();
! final byte[] data = baos.toByteArray();
! if (log.isDebugEnabled())
! {
! long t2 = System.currentTimeMillis();
! log.debug("loaded report data; bytes: "
! + data.length + " in " + (t2 - t1) + " miliseconds");
! }
! return new ResourceState()
! {
! public int getLength()
! {
! return data.length;
! }
! public byte[] getData()
! {
! return data;
! }
!
! public String getContentType()
! {
! return JRResource.this.getContentType();
! }
! };
! }
! catch (JRException e)
! {
! throw new WicketRuntimeException(e);
! }
! }
!
! /**
! * @return The content type of the reports
! */
! public abstract String getContentType();
!
! /**
! * Returns the extension for the resource's file. This string should not
! * contain the leading "."
! *
! * @return The extension for the resource's file.
! */
! public abstract String getExtension();
!
! /**
! * Creates a new {@link JasperPrint} instance. This instance is specific for
! * this render, but it not yet designated for one output format only.
! *
! * @return a new {@link JasperPrint} instance.
! *
! * @throws JRException
! */
! protected JasperPrint newJasperPrint() throws JRException
! {
! final JasperPrint jasperPrint;
! JasperReport report = getJasperReport();
! Map params = getReportParameters();
! JRDataSource dataSource = getReportDataSource();
! if (dataSource != null)
! {
! jasperPrint = JasperFillManager.fillReport(report, params, dataSource);
! }
! else
! {
! IDatabaseConnectionProvider provider = null;
! try
! {
! provider = getConnectionProvider();
! if (provider == null)
! {
! throw new IllegalStateException(
! "JasperReportsResources must either have a JRDataSource, "
! + "or a JDBC Connection provided");
! }
! jasperPrint = JasperFillManager
! .fillReport(report, params, provider.get());
! }
! finally
! {
! if (provider != null)
! {
! provider.release();
! }
! }
! }
! return jasperPrint;
! }
!
! /**
! * @see WebResource#setHeaders(WebResponse)
! */
! protected void setHeaders(WebResponse response)
! {
! super.setHeaders(response);
! String name = getFileName();
! if (name != null)
! {
! response.setHeader("Content-Disposition", "attachment; filename=\""
! + name + "\"");
!
! }
! }
}
\ No newline at end of file
Index: JRTextResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRTextResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JRTextResource.java 20 Mar 2006 04:35:27 -0000 1.3
--- JRTextResource.java 20 Mar 2006 07:12:12 -0000 1.4
***************
*** 1,14 ****
/*
* $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
* $Id$
! * $Revision$ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 29,134 ****
/**
* Resource class for jasper reports text resources.
! *
* @author Eelco Hillenius
*/
! public final class JRTextResource extends JRResource {
! /**
! * an integer representing the page width in characters.
! */
! private int pageWidth = 100;
! /**
! * an integer representing the page height in characters.
! */
! private int pageHeight = 100;
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRTextResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRTextResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRTextResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRTextResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter() {
! JRTextExporter exporter = new JRTextExporter();
! exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, new Integer(pageWidth));
! exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, new Integer(pageHeight));
! return exporter;
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "text/plain";
! }
! /**
! * Gets page height.
! *
! * @return an integer representing the page height in characters
! */
! public int getPageHeight() {
! return pageHeight;
! }
! /**
! * Sets page height.
! *
! * @param height an integer representing the page height in characters
! */
! public void setPageHeight(int height) {
! this.pageHeight = height;
! }
! /**
! * Gets page width.
! *
! * @return an integer representing the page width in characters
! */
! public int getPageWidth() {
! return pageWidth;
! }
! /**
! * Sets page width.
! *
! * @param width an integer representing the page width in characters
! */
! public void setPageWidth(int width) {
! this.pageWidth = width;
! }
! public String getExtension() {
! return "txt";
! }
}
--- 28,156 ----
/**
* Resource class for jasper reports text resources.
! *
* @author Eelco Hillenius
*/
! public final class JRTextResource extends JRResource
! {
! /**
! * an integer representing the page width in characters.
! */
! private int pageWidth = 100;
! /**
! * an integer representing the page height in characters.
! */
! private int pageHeight = 100;
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRTextResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRTextResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRTextResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRTextResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter()
! {
! JRTextExporter exporter = new JRTextExporter();
! exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, new Integer(pageWidth));
! exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT,
! new Integer(pageHeight));
! return exporter;
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "text/plain";
! }
! /**
! * Gets page height.
! *
! * @return an integer representing the page height in characters
! */
! public int getPageHeight()
! {
! return pageHeight;
! }
! /**
! * Sets page height.
! *
! * @param height
! * an integer representing the page height in characters
! */
! public void setPageHeight(int height)
! {
! this.pageHeight = height;
! }
! /**
! * Gets page width.
! *
! * @return an integer representing the page width in characters
! */
! public int getPageWidth()
! {
! return pageWidth;
! }
! /**
! * Sets page width.
! *
! * @param width
! * an integer representing the page width in characters
! */
! public void setPageWidth(int width)
! {
! this.pageWidth = width;
! }
!
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return "txt";
! }
}
Index: JRHtmlResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRHtmlResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JRHtmlResource.java 20 Mar 2006 04:35:27 -0000 1.3
--- JRHtmlResource.java 20 Mar 2006 07:12:12 -0000 1.4
***************
*** 1,14 ****
/*
* $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
* $Id$
! * $Revision$ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 28,85 ****
/**
* Resource class for jasper reports HTML resources.
! *
* @author Eelco Hillenius
*/
! public final class JRHtmlResource extends JRResource {
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRHtmlResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRHtmlResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRHtmlResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRHtmlResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter() {
! return new JRHtmlExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "text/html";
}
! public String getExtension() {
! return "html";
! }
}
--- 27,99 ----
/**
* Resource class for jasper reports HTML resources.
! *
* @author Eelco Hillenius
*/
! public final class JRHtmlResource extends JRResource
! {
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRHtmlResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRHtmlResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRHtmlResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRHtmlResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter()
! {
! return new JRHtmlExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "text/html";
}
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return "html";
! }
}
Index: JRRtfResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRRtfResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JRRtfResource.java 20 Mar 2006 04:35:27 -0000 1.3
--- JRRtfResource.java 20 Mar 2006 07:12:12 -0000 1.4
***************
*** 1,14 ****
/*
! * $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
! * $Id$ $Revision:
! * 1.3 $ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 28,85 ****
/**
* Resource class for jasper reports RTF resources.
! *
* @author Eelco Hillenius
*/
! public final class JRRtfResource extends JRResource {
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRRtfResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRRtfResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRRtfResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRRtfResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter() {
! return new JRRtfExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "text/rtf";
! }
! public String getExtension() {
! return "rtf";
! }
}
--- 27,99 ----
/**
* Resource class for jasper reports RTF resources.
! *
* @author Eelco Hillenius
*/
! public final class JRRtfResource extends JRResource
! {
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRRtfResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRRtfResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRRtfResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRRtfResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter()
! {
! return new JRRtfExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "text/rtf";
! }
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return "rtf";
! }
}
Index: JRXlsResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRXlsResource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** JRXlsResource.java 20 Mar 2006 04:35:27 -0000 1.1
--- JRXlsResource.java 20 Mar 2006 07:12:12 -0000 1.2
***************
*** 9,67 ****
/**
! * Resource class for jasper reports CSV resources.
! *
* @author Justin Lee
*/
! public final class JRXlsResource extends JRResource {
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRXlsResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRXlsResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRXlsResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRXlsResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter() {
! return new JRXlsExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "application/excel";
! }
! public String getExtension() {
! return "xls";
! }
}
\ No newline at end of file
--- 9,82 ----
/**
! * Resource class for jasper reports Excell resources.
! *
* @author Justin Lee
*/
! public final class JRXlsResource extends JRResource
! {
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRXlsResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRXlsResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRXlsResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRXlsResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public JRAbstractExporter newExporter()
! {
! return new JRXlsExporter();
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "application/excel";
! }
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return "xls";
! }
}
\ No newline at end of file
Index: JRImageResource.java
===================================================================
RCS file: /cvsroot/wicket-stuff/wicket-contrib-jasperreports/src/java/wicket/contrib/jasperreports/JRImageResource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** JRImageResource.java 20 Mar 2006 04:35:27 -0000 1.5
--- JRImageResource.java 20 Mar 2006 07:12:12 -0000 1.6
***************
*** 1,14 ****
/*
* $Id$
! * $Revision$
! * $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
--- 1,13 ----
/*
* $Id$
! * $Revision$ $Date$
! *
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
! *
* http://www.apache.org/licenses/LICENSE-2.0
! *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
***************
*** 25,28 ****
--- 24,28 ----
import java.io.InputStream;
import java.net.URL;
+
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
***************
*** 34,39 ****
--- 34,41 ----
import net.sf.jasperreports.engine.export.JRGraphics2DExporter;
import net.sf.jasperreports.engine.export.JRGraphics2DExporterParameter;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import wicket.WicketRuntimeException;
import wicket.resource.DynamicByteArrayResource;
***************
*** 41,249 ****
/**
* Resource class for jasper reports PDF resources.
! *
* @author Eelco Hillenius
*/
! public final class JRImageResource extends JRResource {
! /**
! * log.
! */
! private static Log log = LogFactory.getLog(JRImageResource.class);
! /**
! * Type of image (one of BufferedImage.TYPE_*).
! */
! private int type = BufferedImage.TYPE_INT_RGB;
! /**
! * The zoom ratio used for the export. The default value is 1.
! */
! private float zoomRatio = 1;
! /**
! * the image type. The default value is 'png'.
! */
! private String format = "png";
! /**
! * Construct without a report. You must provide a report before you can use this resource.
! */
! public JRImageResource() {
! super();
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRImageResource(InputStream report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRImageResource(URL report) {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report the report input stream
! */
! public JRImageResource(File report) {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public final JRAbstractExporter newExporter() {
! throw new UnsupportedOperationException(
! "this method is not used in this implementation");
! }
! /**
! * @see DynamicByteArrayResource#getResourceState()
! */
! protected ResourceState getResourceState() {
! try {
! long t1 = System.currentTimeMillis();
! // get a print instance for exporting
! JasperPrint print = newJasperPrint();
! // get a fresh instance of an exporter for this report
! JRGraphics2DExporter exporter = new JRGraphics2DExporter();
! // prepare a stream to trap the exporter's output
! ByteArrayOutputStream baos = new ByteArrayOutputStream();
! exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
! exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
! // create an image object
! int width = (int)((float)print.getPageWidth() * getZoomRatio());
! int height = (int)((float)print.getPageHeight() * getZoomRatio());
! BufferedImage image = new BufferedImage(width, height, type);
! exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, image.getGraphics());
! exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoomRatio));
! // execute the export and return the trapped result
! exporter.exportReport();
! final byte[] data = toImageData(image);
! // if (log.isDebugEnabled())
! // {
! long t2 = System.currentTimeMillis();
! log.info("loaded report data; bytes: "
! + data.length + " in " + (t2 - t1) + " miliseconds");
! // }
! return new ResourceState() {
! public int getLength() {
! return data.length;
! }
! public byte[] getData() {
! return data;
! }
! public String getContentType() {
! return "image/" + format;
! }
! };
! }
! catch(JRException e) {
! throw new WicketRuntimeException(e);
! }
! }
! /**
! * @param image The image to turn into data
! *
! * @return The image data for this dynamic image
! */
! protected byte[] toImageData(final BufferedImage image) {
! try {
! // Create output stream
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! // Get image writer for format
! final ImageWriter writer = (ImageWriter)ImageIO.getImageWritersByFormatName(
! format).next();
! // Write out image
! writer.setOutput(ImageIO.createImageOutputStream(out));
! writer.write(image);
! // Return the image data
! return out.toByteArray();
! }
! catch(IOException e) {
! throw new WicketRuntimeException("Unable to convert dynamic image to stream",
! e);
! }
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType() {
! return "image/" + format;
! }
! /**
! * Gets the zoom ratio.
! *
! * @return the zoom ratio used for the export. The default value is 1
! */
! public float getZoomRatio() {
! return zoomRatio;
! }
! /**
! * Sets the zoom ratio.
! *
! * @param ratio the zoom ratio used for the export. The default value is 1
! */
! public void setZoomRatio(float ratio) {
! this.zoomRatio = ratio;
! }
! /**
! * Gets the image type.
! *
! * @return the image type. The default value is 'png'
! */
! public String getFormat() {
! return format;
! }
! /**
! * Sets the image type.
! *
! * @param format the image type. The default value is 'png'
! */
! public void setFormat(String format) {
! this.format = format;
! }
! /**
! * Gets type of image (one of BufferedImage.TYPE_*).
! *
! * @return type of image
! */
! public int getType() {
! return type;
! }
! /**
! * Sets type of image (one of BufferedImage.TYPE_*).
! *
! * @param type type of image
! */
! public void setType(int type) {
! this.type = type;
! }
! public String getExtension() {
! return getFormat();
! }
}
\ No newline at end of file
--- 43,291 ----
/**
* Resource class for jasper reports PDF resources.
! *
* @author Eelco Hillenius
*/
! public final class JRImageResource extends JRResource
! {
! /**
! * log.
! */
! private static Log log = LogFactory.getLog(JRImageResource.class);
! /**
! * Type of image (one of BufferedImage.TYPE_*).
! */
! private int type = BufferedImage.TYPE_INT_RGB;
! /**
! * The zoom ratio used for the export. The default value is 1.
! */
! private float zoomRatio = 1;
! /**
! * the image type. The default value is 'png'.
! */
! private String format = "png";
! /**
! * Construct without a report. You must provide a report before you can use
! * this resource.
! */
! public JRImageResource()
! {
! super();
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRImageResource(InputStream report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRImageResource(URL report)
! {
! super(report);
! }
! /**
! * Construct.
! *
! * @param report
! * the report input stream
! */
! public JRImageResource(File report)
! {
! super(report);
! }
! /**
! * @see JRResource#newExporter()
! */
! public final JRAbstractExporter newExporter()
! {
! throw new UnsupportedOperationException(
! "this method is not used in this implementation");
! }
! /**
! * @see DynamicByteArrayResource#getResourceState()
! */
! protected ResourceState getResourceState()
! {
! try
! {
! long t1 = System.currentTimeMillis();
! // get a print instance for exporting
! JasperPrint print = newJasperPrint();
! // get a fresh instance of an exporter for this report
! JRGraphics2DExporter exporter = new JRGraphics2DExporter();
! // prepare a stream to trap the exporter's output
! ByteArrayOutputStream baos = new ByteArrayOutputStream();
! exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
! exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
! // create an image object
! int width = (int) ((float) print.getPageWidth() * getZoomRatio());
! int height = (int) ((float) print.getPageHeight() * getZoomRatio());
! BufferedImage image = new BufferedImage(width, height, type);
! exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, image
! .getGraphics());
! exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(
! zoomRatio));
! // execute the export and return the trapped result
! exporter.exportReport();
! final byte[] data = toImageData(image);
! // if (log.isDebugEnabled())
! // {
! long t2 = System.currentTimeMillis();
! log.info("loaded report data; bytes: "
! + data.length + " in " + (t2 - t1) + " miliseconds");
! // }
! return new ResourceState()
! {
! public int getLength()
! {
! return data.length;
! }
! public byte[] getData()
! {
! return data;
! }
! public String getContentType()
! {
! return "image/" + format;
! }
! };
! }
! catch (JRException e)
! {
! throw new WicketRuntimeException(e);
! }
! }
! /**
! * @param image
! * The image to turn into data
! *
! * @return The image data for this dynamic image
! */
! protected byte[] toImageData(final BufferedImage image)
! {
! try
! {
! // Create output stream
! final ByteArrayOutputStream out = new ByteArrayOutputStream();
! // Get image writer for format
! final ImageWriter writer = (ImageWriter) ImageIO.getImageWritersByFormatName(
! format).next();
! // Write out image
! writer.setOutput(ImageIO.createImageOutputStream(out));
! writer.write(image);
! // Return the image data
! return out.toByteArray();
! }
! catch (IOException e)
! {
! throw new WicketRuntimeException("Unable to convert dynamic image to stream",
! e);
! }
! }
! /**
! * @see JRResource#getContentType()
! */
! public String getContentType()
! {
! return "image/" + format;
! }
! /**
! * Gets the zoom ratio.
! *
! * @return the zoom ratio used for the export. The default value is 1
! */
! public float getZoomRatio()
! {
! return zoomRatio;
! }
! /**
! * Sets the zoom ratio.
! *
! * @param ratio
! * the zoom ratio used for the export. The default value is 1
! */
! public void setZoomRatio(float ratio)
! {
! this.zoomRatio = ratio;
! }
! /**
! * Gets the image type.
! *
! * @return the image type. The default value is 'png'
! */
! public String getFormat()
! {
! return format;
! }
! /**
! * Sets the image type.
! *
! * @param format
! * the image type. The default value is 'png'
! */
! public void setFormat(String format)
! {
! this.format = format;
! }
!
! /**
! * Gets type of image (one of BufferedImage.TYPE_*).
! *
! * @return type of image
! */
! public int getType()
! {
! return type;
! }
!
! /**
! * Sets type of image (one of BufferedImage.TYPE_*).
! *
! * @param type
! * type of image
! */
! public void setType(int type)
! {
! this.type = type;
! }
!
! /**
! * @see wicket.contrib.jasperreports.JRResource#getExtension()
! */
! public String getExtension()
! {
! return getFormat();
! }
}
\ No newline at end of file
|