Hi there,<br />
I've written a small java application to take a report, populate the parameters and render it into a PDF application.<br />
<br />
The same report works fine when ran through the eclipse preview and BIRT-Viewer applications, but when I run it through this custom application I get the error mentioned in the title.<br />
<br />
"DOMParser" is not defined.<br />
<br />
I am using the DOMParser within a computedColumn in my dataset, following this example:<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/devshare/designing-birt-reports/197-parse-xml-from-database-field-in-birt-report/#description'>Parse XML from Database Field in BIRT Report - Designs & Code - BIRT Exchange</a><br />
<br />
<br />
Please find included the source code, I'm not able to upload the report design yet, but if it is required I'll try and replicate the report using ClassicModels or something<br />
<br />
Any ideas on what simple step I am likely missing?<br />
<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Calendar;
import java.util.logging.Level;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
public class BirtCompile {
private static final String REPORT_DIR = "C:/eclipse-birt/workspace/BIRT/";
/**
*
@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
EngineConfig ec = new EngineConfig();
ec.setEngineHome("D:/Apps/birt-runtime-2_5_1/ReportEngine");
ec.setLogConfig("D:/temp", Level.FINE);
// ec.setEngineHome("D:/Apps/birt-runtime-2_5_1");
System.out.println(ec.getBIRTHome());
try {
Platform.startup(ec);
IReportEngineFactory factory = (IReportEngineFactory) Platform.
createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
IReportEngine engine = factory.createReportEngine(ec);
engine.changeLogLevel(Level.WARNING);
IReportRunnable irr = engine.openReportDesign(REPORT_DIR + "EMAIL_Exception.rptdesign");
IRunTask runme = engine.createRunTask(irr);
// runme.setParameterValue("Application", "APP_A");
// IRunAndRenderTask runAndRender = re.createRunAndRenderTask(irr);
System.out.println("Setting Parameters");
runme.setParameterValue("Application", "APP_A");
Calendar newDate = Calendar.getInstance();
newDate.set(2009, 9, 25, 0, 0, 0);
runme.setParameterValue("pStartDate", "2009-09-25 00:00:00.000");
newDate.set(2009, 9, 26, 0, 0, 0);
runme.setParameterValue("pEndDate", "2009-10-03 00:00:00.000");
runme.setParameterValue("pDateInterval", "H");
System.out.println("parameter validation: " + runme.validateParameters());
System.out.println(runme.getParameterValue("Application"));
System.out.println(runme.getParameterValue("pStartDate"));
System.out.println(runme.getParameterValue("pEndDate"));
System.out.println("Running");
runme.run(REPORT_DIR + "pdf/reports/EMAIL_Exception.rptdocument");
System.out.println("Document Opened");
IReportDocument rptdoc = engine.openReportDocument(REPORT_DIR + "pdf/reports/EMAIL_Exception.rptdocument");
IRenderTask rtask = engine.createRenderTask(rptdoc);
System.out.println("Preparing PDF output");
PDFRenderOption options = new PDFRenderOption();
// HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName(REPORT_DIR + "pdf/EMAIL_Exception.pdf");
options.setOutputFormat("pdf");
rtask.setRenderOption(options);
System.out.println("Rendering :" + Calendar.getInstance().getTime().toString() );
rtask.render();
System.out.println("Finished");
engine.destroy();
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BirtException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
</pre>
<br />
Here is the script I am running for two of the computed columns<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.org.apache.xerces.parsers);
importPackage(Packages.org.xml.sax);
importPackage(Packages.java.io);
var parser = new DOMParser();
//var parser = new Parser();
parser.parse(new InputSource(new StringReader(row.Exception_Parsed)));
var errorCodes = parser.getDocument().getElementsByTagName('NS1:ReturnCode');
var errorCodeValue = errorCodes.item(0).getFirstChild().getNodeValue();
var errorCode = errorCodeValue.substr(8,4);
errorCode;
</pre>
<br />
and here is a partial stack dump<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
6/10/2009 16:52:37 org.eclipse.birt.report.engine.api.impl.RunTask doRun
SEVERE: An error happened while running the report. Cause:
org.mozilla.javascript.EcmaError: ReferenceError: "DOMParser" is not defined. (unnamed script#4)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620)
at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1718)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1657)
at org.mozilla.javascript.gen.c16._c0(unnamed script:4)
at org.mozilla.javascript.gen.c16.call(unnamed script)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
at org.mozilla.javascript.gen.c16.call(unnamed script)
at org.mozilla.javascript.gen.c16.exec(unnamed script)
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:256)
at org.eclipse.birt.core.script.ScriptContext.evaluate(ScriptContext.java:152)
at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evalExpr(ScriptEvalUtil.java:678)
at org.eclipse.birt.data.engine.impl.ComputedColumnHelperInstance.process(ComputedColumnHelper.java:412)
at org.eclipse.birt.data.engine.impl.ComputedColumnHelper.process(ComputedColumnHelper.java:119)
at org.eclipse.birt.data.engine.executor.cache.RowResultSet.processFetchEvent(RowResultSet.java:145)
at org.eclipse.birt.data.engine.executor.cache.RowResultSet.next(RowResultSet.java:109)
at org.eclipse.birt.data.engine.executor.cache.ExpandableRowResultSet.next(ExpandableRowResultSet.java:63)
at org.eclipse.birt.data.engine.executor.cache.SmartCacheHelper.populateData(SmartCacheHelper.java:308)
at org.eclipse.birt.data.engine.executor.cache.SmartCacheHelper.initInstance(SmartCacheHelper.java:280)
at org.eclipse.birt.data.engine.executor.cache.SmartCacheHelper.getResultSetCache(SmartCacheHelper.java:241)
at org.eclipse.birt.data.engine.executor.cache.SmartCache.<init>(SmartCache.java:69)
at
</pre>