public final class JasperCompileManager extends Object
This class exposes all the library's report compilation functionality. It has
various methods that allow the users to compile JRXML report templates found in files
on disk or that come from input streams. It also lets people compile in-memory report
templates by directly passing a
JasperDesign
object and receiving the
corresponding JasperReport
object.
Other utility methods include report template verification and JRXML report template
generation for in-memory constructed
JasperDesign
class instances. These
instances are especially useful in GUI tools that simplify report design work.
The facade class relies on the report template language to determine an appropriate report compiler.
The report compilation facade first reads a configuration property called
net.sf.jasperreports.compiler.<language>
to determine whether a compiler
implementation has been configured for the specific report language. If such a property
is found, its value is used as compiler implementation class name and the facade
instantiates a compiler object and delegates the report compilation to it. By default,
JasperReports includes configuration properties that map the Groovy and JavaScript
report compilers to the groovy
and javascript
report languages, respectively.
If the report uses Java as language and no specific compiler has been set for this language, the report compilation facade employs a built-in fall back mechanism that picks the best Java-based report compiler available in the environment in which the report compilation process takes place.
The facade first reads the
configuration property called net.sf.jasperreports.compiler.class
to allow
users to override its built-in compiler-detection logic by providing the name of the report
compiler implementation to use directly.
If the property is not provided, the facade first tries to see if the JDT compiler from the
Eclipse Foundation is available in the application's classpath. If it is, the
JRJdtCompiler
implementation is used.
If the JDT compiler is not available, the compilation facade then tries to locate the JDK
1.3-compatible Java compiler from Sun Microsystems. This is normally found in the
tools.jar
file that comes with the JDK installation.
If all these fail, the last thing the fall back mechanism does is to try to launch the
javac.exe
program from the command line in order to compile the temporarily
generated Java source file on the fly.
net.sf.jasperreports.compiler.<language>
JRCompiler
interface to be instantiated by
the engine for a specific report language
when the default compilation is used through this facade class. The
value for such a configuration property can be the name of one of the built-in
implementations of this interface shipped with the library as listed previously, or the
name of a custom-made implementing class.
net.sf.jasperreports.compiler.<language>
to the desired compiler
implementation class names. In particular, the mechanism that automatically chooses a
Java report compiler can be superseded by explicitly setting the
net.sf.jasperreports.compiler.java
property to the name of one of the built-in
Java compiler classes or of a custom compiler implementation class.
JRCompiler
interface can also be used directly in
the programs without having to call them through this facade class.net.sf.jasperreports.compiler.xml.validation
net.sf.jasperreports.compiler.classpath
net.sf.jasperreports.compiler.temp.dir
net.sf.jasperreports.compiler.keep.java.file
*.java
file or
generated script in order to fix compilation problems related to report expressions. By
default, the engine deletes this file after report compilation, along with its corresponding
*.class
file. To keep it, however, set this configuration property to true.org.eclipse.jdt.core.
prefix
and passes them to the JDT Java compiler when compiling the generated Java class to
evaluate report expressions.
One of the uses of this mechanism is to instruct the JDT compiler to observe Java 1.5 code compatibility. To do so, the following properties should be set:
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.TargetPlatform=1.5
JasperReport
,
JasperDesign
,
JRCompiler
,
JRJdtCompiler
,
JRVerifier
,
JRXmlLoader
,
JRXmlWriter
,
JRLoader
,
JRSaver
Modifier and Type | Field and Description |
---|---|
static String |
EXCEPTION_MESSAGE_KEY_INSTANTIATE_REPORT_COMPILER_FAILURE |
static String |
EXCEPTION_MESSAGE_KEY_REPORT_COMPILER_CLASS_NOT_FOUND |
static String |
EXCEPTION_MESSAGE_KEY_REPORT_COMPILER_NOT_SET |
Modifier and Type | Method and Description |
---|---|
JasperReport |
compile(InputStream inputStream)
Compiles the serialized report design object read from the supplied input stream and
returns the generated compiled report design object.
|
JasperReport |
compile(JasperDesign jasperDesign)
Compiles the report design object received as parameter and
returns the generated compiled report design object.
|
JasperReport |
compile(String sourceFileName)
Compiles the XML report design file received as parameter, and returns
the compiled report design object.
|
static JasperReport |
compileReport(InputStream inputStream) |
static JasperReport |
compileReport(JasperDesign jasperDesign) |
static JasperReport |
compileReport(String sourceFileName) |
static void |
compileReportToFile(JasperDesign jasperDesign,
String destFileName) |
static String |
compileReportToFile(String sourceFileName) |
static void |
compileReportToFile(String sourceFileName,
String destFileName) |
static void |
compileReportToStream(InputStream inputStream,
OutputStream outputStream) |
static void |
compileReportToStream(JasperDesign jasperDesign,
OutputStream outputStream) |
void |
compileToFile(JasperDesign jasperDesign,
String destFileName)
Compiles the report design object received as the first parameter, placing the result
in the file specified by the second parameter.
|
String |
compileToFile(String sourceFileName)
Compiles the XML report design file specified by the parameter.
|
void |
compileToFile(String sourceFileName,
String destFileName)
Compiles the XML report design file received as the first parameter, placing the result
in the file specified by the second parameter.
|
void |
compileToStream(InputStream inputStream,
OutputStream outputStream)
Compiles the XML representation of the report design read from the supplied input stream and
writes the generated compiled report design object to the output stream specified
by the second parameter.
|
void |
compileToStream(JasperDesign jasperDesign,
OutputStream outputStream)
Compiles the report design object represented by the first parameter and
writes the generated compiled report design object to the output stream specified
by the second parameter.
|
JREvaluator |
getEvaluator(JasperReport jasperReport) |
JREvaluator |
getEvaluator(JasperReport jasperReport,
JRCrosstab crosstab) |
JREvaluator |
getEvaluator(JasperReport jasperReport,
JRDataset dataset) |
static JasperCompileManager |
getInstance(JasperReportsContext jasperReportsContext) |
protected void |
initialize(JREvaluator evaluator) |
static JREvaluator |
loadEvaluator(JasperReport jasperReport) |
static JREvaluator |
loadEvaluator(JasperReport jasperReport,
JRCrosstab crosstab) |
static JREvaluator |
loadEvaluator(JasperReport jasperReport,
JRDataset dataset) |
Collection<JRValidationFault> |
verify(JasperDesign jasperDesign)
Verifies the validity and consistency of the report design object.
|
static Collection<JRValidationFault> |
verifyDesign(JasperDesign jasperDesign) |
static String |
writeReportToXml(JRReport report) |
static void |
writeReportToXmlFile(JRReport report,
String destFileName) |
static String |
writeReportToXmlFile(String sourceFileName) |
static void |
writeReportToXmlFile(String sourceFileName,
String destFileName) |
static void |
writeReportToXmlStream(InputStream inputStream,
OutputStream outputStream) |
static void |
writeReportToXmlStream(JRReport report,
OutputStream outputStream) |
String |
writeToXml(JRReport report)
Generates the XML representation of the report design object supplied as parameter
using the "UTF-8" enconding.
|
void |
writeToXmlFile(JRReport report,
String destFileName)
Generates the XML representation of the report design supplied as the first parameter
and place it in the file specified by the second parameter.
|
String |
writeToXmlFile(String sourceFileName)
Generates the XML representation of the report design loaded from the specified filename.
|
void |
writeToXmlFile(String sourceFileName,
String destFileName)
Generates the XML representation of the report design loaded from the first file parameter
and place it in the file specified by the second parameter.
|
void |
writeToXmlStream(InputStream inputStream,
OutputStream outputStream)
Generates the XML representation of the serialized report design object read from the supplied
input stream abd writes it to the specified output stream, using the "UTF-8" encoding.
|
void |
writeToXmlStream(JRReport report,
OutputStream outputStream)
Generates the XML representation of the report design object supplied as parameter
and writes it to the specified output stream, using the "UTF-8" encoding.
|
public static final String EXCEPTION_MESSAGE_KEY_INSTANTIATE_REPORT_COMPILER_FAILURE
public static final String EXCEPTION_MESSAGE_KEY_REPORT_COMPILER_CLASS_NOT_FOUND
public static final String EXCEPTION_MESSAGE_KEY_REPORT_COMPILER_NOT_SET
public static JasperCompileManager getInstance(JasperReportsContext jasperReportsContext)
public String compileToFile(String sourceFileName) throws JRException
JasperReport
object representing the compiled report design,
having the same name as the report design as declared in the XML plus the *.jasper
extension,
located in the same directory as the XML source file.sourceFileName
- XML source file nameJasperReport
objectJRException
public void compileToFile(String sourceFileName, String destFileName) throws JRException
JasperReport
object representing
the compiled report design.sourceFileName
- XML source file namedestFileName
- file name to place the result intoJRException
public void compileToFile(JasperDesign jasperDesign, String destFileName) throws JRException
JasperReport
object representing the compiled report design.jasperDesign
- source report design objectdestFileName
- file name to place the compiled report design intoJRException
public JasperReport compile(String sourceFileName) throws JRException
sourceFileName
- XML source file nameJRException
public void compileToStream(InputStream inputStream, OutputStream outputStream) throws JRException
inputStream
- XML source input streamoutputStream
- output stream to write the compiled report design toJRException
public void compileToStream(JasperDesign jasperDesign, OutputStream outputStream) throws JRException
jasperDesign
- source report design objectoutputStream
- output stream to write the compiled report design toJRException
public JasperReport compile(InputStream inputStream) throws JRException
inputStream
- XML source input streamJRException
public JasperReport compile(JasperDesign jasperDesign) throws JRException
jasperDesign
- source report design objectJRException
JRCompiler
public Collection<JRValidationFault> verify(JasperDesign jasperDesign)
errors
, if problems are found in the report design.jasperDesign
- report design object to verifyJRValidationFault
if problems are foundJRVerifier
public JREvaluator getEvaluator(JasperReport jasperReport, JRDataset dataset) throws JRException
JRException
public JREvaluator getEvaluator(JasperReport jasperReport, JRCrosstab crosstab) throws JRException
JRException
public JREvaluator getEvaluator(JasperReport jasperReport) throws JRException
JRException
protected void initialize(JREvaluator evaluator)
public String writeToXmlFile(String sourceFileName) throws JRException
*.jasper.jrxml
extension, located in the same directory as
the source file.sourceFileName
- source file name containing the report design objectJRException
public void writeToXmlFile(String sourceFileName, String destFileName) throws JRException
sourceFileName
- source file name containing the report design objectdestFileName
- output file name to write the XML report design representation toJRException
public void writeToXmlFile(JRReport report, String destFileName) throws JRException
report
- source report design objectdestFileName
- output file name to write the XML report design representation toJRException
JRXmlWriter
public void writeToXmlStream(InputStream inputStream, OutputStream outputStream) throws JRException
inputStream
- source input stream to read the report design object fromoutputStream
- output stream to write the XML report design representation toJRException
public void writeToXmlStream(JRReport report, OutputStream outputStream) throws JRException
report
- source report design objectoutputStream
- output stream to write the XML report design representation toJRException
JRXmlWriter
public String writeToXml(JRReport report)
report
- source report design objectJRXmlWriter
public static String compileReportToFile(String sourceFileName) throws JRException
JRException
compileToFile(String)
public static void compileReportToFile(String sourceFileName, String destFileName) throws JRException
JRException
compileToFile(String, String)
public static void compileReportToFile(JasperDesign jasperDesign, String destFileName) throws JRException
JRException
compileToFile(JasperDesign, String)
public static JasperReport compileReport(String sourceFileName) throws JRException
JRException
compile(String)
public static void compileReportToStream(InputStream inputStream, OutputStream outputStream) throws JRException
JRException
compileToStream(InputStream, OutputStream)
public static void compileReportToStream(JasperDesign jasperDesign, OutputStream outputStream) throws JRException
JRException
compileToStream(JasperDesign, OutputStream)
public static JasperReport compileReport(InputStream inputStream) throws JRException
JRException
compile(InputStream)
public static JasperReport compileReport(JasperDesign jasperDesign) throws JRException
JRException
compile(JasperDesign)
public static Collection<JRValidationFault> verifyDesign(JasperDesign jasperDesign)
verify(JasperDesign)
public static JREvaluator loadEvaluator(JasperReport jasperReport, JRDataset dataset) throws JRException
JRException
getEvaluator(JasperReport, JRDataset)
public static JREvaluator loadEvaluator(JasperReport jasperReport, JRCrosstab crosstab) throws JRException
JRException
getEvaluator(JasperReport, JRCrosstab)
public static JREvaluator loadEvaluator(JasperReport jasperReport) throws JRException
JRException
getEvaluator(JasperReport)
public static String writeReportToXmlFile(String sourceFileName) throws JRException
JRException
writeToXmlFile(String)
public static void writeReportToXmlFile(String sourceFileName, String destFileName) throws JRException
JRException
writeToXmlFile(String, String)
public static void writeReportToXmlFile(JRReport report, String destFileName) throws JRException
JRException
writeToXmlFile(JRReport, String)
public static void writeReportToXmlStream(InputStream inputStream, OutputStream outputStream) throws JRException
JRException
writeToXmlStream(InputStream, OutputStream)
public static void writeReportToXmlStream(JRReport report, OutputStream outputStream) throws JRException
JRException
writeToXmlStream(JRReport, OutputStream)
public static String writeReportToXml(JRReport report)
writeToXml(JRReport)
Copyright © 2019 TIBCO Software Inc.. All rights reserved.