/**
*
*/
public JasperReport compileReport(JasperDesign jasperDesign) throws JRException
{
JasperReport jasperReport = null;
if (!JRReport.LANGUAGE_JAVA.equals(jasperDesign.getLanguage()))
{
throw
new JRException(
"Language \"" + jasperDesign.getLanguage()
+ "\" not supported by this report compiler.\n"
+ "Expecting \"java\" instead."
);
}
Collection brokenRules = JRVerifier.verifyDesign(jasperDesign);
if (brokenRules != null && brokenRules.size() > 0)
{
StringBuffer sbuffer = new StringBuffer();
sbuffer.append("Report design not valid : ");
int i = 1;
for(Iterator it = brokenRules.iterator(); it.hasNext(); i++)
{
sbuffer.append("\n\t " + i + ". " + (String)it.next());
}
throw new JRException(sbuffer.toString());
}
else
{
//Report design OK
//Generating BeanShell script for report expressions
String bshScript = JRBshGenerator.generateScript(jasperDesign);
boolean isKeepJavaFile =
Boolean.valueOf(
System.getProperty("jasper.reports.compile.keep.java.file")
).booleanValue();
if (isKeepJavaFile)
{
String tempDirStr = System.getProperty("jasper.reports.compile.temp");
if (tempDirStr == null || tempDirStr.length() == 0)
{
tempDirStr = System.getProperty("user.dir");
}
File tempDirFile = new File(tempDirStr);
if (!tempDirFile.exists() || !tempDirFile.isDirectory())
{
throw new JRException("Temporary directory not found : " + tempDirStr);
}
File javaFile = new File(tempDirFile, jasperDesign.getName() + ".bsh");
JRSaver.saveClassSource(bshScript, javaFile);
}
jasperReport =
new JasperReport(
jasperDesign,
getClass().getName(),
bshScript
);