compatibility with JasperReports 3.x in terms of resource management (SPR-7048)
This commit is contained in:
parent
fa719ad4c5
commit
fba8bcc7dc
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.web.servlet.view.jasperreports;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -490,16 +491,28 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
|
|||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Loading pre-compiled Jasper Report from " + resource);
|
||||
}
|
||||
return (JasperReport) JRLoader.loadObject(resource.getInputStream());
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
return (JasperReport) JRLoader.loadObject(is);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
else if (fileName.endsWith(".jrxml")) {
|
||||
// Compile report on-the-fly.
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Compiling Jasper Report loaded from " + resource);
|
||||
}
|
||||
JasperDesign design = JRXmlLoader.load(resource.getInputStream());
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
JasperDesign design = JRXmlLoader.load(is);
|
||||
return JasperCompileManager.compileReport(design);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Report filename [" + fileName + "] must end in either .jasper or .jrxml");
|
||||
|
|
|
|||
Loading…
Reference in New Issue