compatibility with JasperReports 3.x in terms of resource management (SPR-7048)

This commit is contained in:
Juergen Hoeller 2010-03-29 23:07:53 +00:00
parent fa719ad4c5
commit fba8bcc7dc
1 changed files with 17 additions and 4 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; package org.springframework.web.servlet.view.jasperreports;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
@ -490,16 +491,28 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Loading pre-compiled Jasper Report from " + resource); 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")) { else if (fileName.endsWith(".jrxml")) {
// Compile report on-the-fly. // Compile report on-the-fly.
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Compiling Jasper Report loaded from " + resource); 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); return JasperCompileManager.compileReport(design);
} }
finally {
is.close();
}
}
else { else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Report filename [" + fileName + "] must end in either .jasper or .jrxml"); "Report filename [" + fileName + "] must end in either .jasper or .jrxml");