[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.birt] Problem with report engine api - plese help
|
- From: albrogor@xxxxxxxxxxxxxxx (Alberto Rogora)
- Date: Tue, 14 Oct 2008 21:13:49 +0000 (UTC)
- Newsgroups: eclipse.birt
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
Hi to all,
i have a problem with the report engine API.
I am working to a
web application deployed with tomcat and i wrote this method to start the
production of a report from a .rptdesign file.
public void startEngine()
throws ExceptionLTBL, BirtException {
config = new EngineConfig();
config.setBIRTHome("");
config.setLogConfig("C:/test", Level.FINEST);
Platform.startup(config);
IReportEngineFactory factory =
(IReportEngineFactory)Platform.createFactoryObject
(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.
createReportEngine(config); // line that generate the error
}
When i call
this class the first time tomcat is started, it works fine and i obtain the
report, but when i try to start
a new report i get this error:
java.lang.
NoClassDefFoundError: Could not initialize class
org.eclipse.birt.report.engine.
api.impl.ReportEngine.
i don't understand why the first time run and the
second not.
Obviously if i restart tomcat the program works.
Below the class:
package it.sg.base.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.
Locale;
import java.util.ResourceBundle;
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.IRenderOption;
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.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.
birt.report.engine.api.RenderOption;
import org.ltblfw.exception.ExceptionLTBL;
import org.ltblfw.export.FileLTBL;
public class BirtFileLTBL extends FileLTBL
{
/** Directory temp */
private static final String TEMP_DIR =
ResourceBundle.getBundle("config.docBase",
Locale.
getDefault()).getString("DOC_BASE") +
ResourceBundle.
getBundle("config.docBase",
Locale.getDefault()).getString
("TEMP_DIRECTORY");
/** Dir del pdf temp */
private String url = null;
private String enginePath = ResourceBundle.getBundle("config.birt",
Locale.
getDefault()).getString("engine_path");
/** Configurazione dell'engine */
EngineConfig config = null;
IReportEngine engine = null;
/** documento
report */
IReportRunnable design = null;
/** Handle al documento */
IRunAndRenderTask task = null;
/**
* Costruttore per BirtFileLTBL
*/
public BirtFileLTBL() {
}
/**
* Inizializza l'engine BIRT
*
*
@throws ExceptionLTBL
* @throws BirtException
*/
public void
startEngine() throws ExceptionLTBL, BirtException {
config = new
EngineConfig();
config.setBIRTHome(enginePath);
config.setLogConfig("C:
/test", Level.FINEST);
Platform.startup(config);
IReportEngineFactory
factory = (IReportEngineFactory)Platform.createFactoryObject
(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.
createReportEngine(config);
//engine.changeLogLevel(Level.WARNING);
}
/**
* Apre un documento .rptdesign
*
* @param template String
*
@param reportName String
* @throws ExceptionLTBL
* @throws
EngineException
* @throws BirtException
*/
public void loadDesignFile
(String fileName) throws ExceptionLTBL, EngineException {
design = engine.
openReportDesign(fileName);
task = engine.createRunAndRenderTask(design);
//task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
BirtFileLTBL.class.getClassLoader());
}
/**
* Formato di output
*
* @param template String
* @param reportName String
* @throws
ExceptionLTBL
* @throws EngineException
* @throws BirtException
*/
public void setOutputFormat(String fileName, String fileType) throws
ExceptionLTBL, EngineException {
// Output format
IRenderOption options
= new RenderOption();
if (fileType.equalsIgnoreCase("PDF")) {
setUrl(TEMP_DIR + "/" + fileName + ".pdf");
options.setOutputFormat
(fileType);
options.setOutputFileName(url);
PDFRenderOption pdfOptions
= new PDFRenderOption(options);
//pdfOptions.setOption(IPDFRenderOption.
FIT_TO_PAGE, new Boolean(true));
//pdfOptions.setOption(IPDFRenderOption.
PAGEBREAK_PAGINATION_ONLY, new Boolean(true));
}
if (fileType.
equalsIgnoreCase("HTML")) {
}
task.setRenderOption(options);
}
/**
* Setta un parametro del file
*
* @param param String
* @param
value String
* @throws ExceptionLTBL
* @throws EngineException
*
@throws BirtException
*/
public void setParameterValue(String param,
String value) throws ExceptionLTBL, EngineException {
task.setParameterValue
(param, value);
}
/**
* Avvia la generazione del report
*
*
@throws ExceptionLTBL
* @throws EngineException
*/
public void
runReport () throws ExceptionLTBL, EngineException {
task.run();
task.
close();
}
/**
* Distrugge l'engine
*
* @throws ExceptionLTBL
* @throws EngineException
*/
public void stopEngine () throws
ExceptionLTBL, EngineException {
engine.destroy();
Platform.shutdown();
}
/**
* set di url
* @param value String
*/
public void setUrl
(String value) {
url = value;
}
/**
* get di url
* Directory di
memorizzazione temporanea del file
* @return String
*/
public String
getUrl() {
return url;
}
/**
* Ritorna la dimensione dell'input
stream
*
* @return long
* @throws ExceptionLTBL
*/
public long
getSize() throws ExceptionLTBL {
File pdf = new File(url);
return pdf.
length();
}
/**
* Trasforma il documento in un byte[] per essere
messo in un blob
*
* @return InputStream
* @throws ExceptionLTBL
*/
public InputStream getInputStream() throws ExceptionLTBL {
try {
//
creo inputStream
InputStream iStream = new FileInputStream(url);
return iStream;
} catch (IOException io) {
throw new ExceptionLTBL
(io, "IOException - (PDFCreator.getInputStream())");
}
}
}
This method
(that i called from a servlet) start the production of a report:
private
String buildReport(String cod, Job job) throws ExceptionLTBL {
BirtFileLTBL engine = new BirtFileLTBL();
try {
engine.
startEngine();
engine.loadDesignFile(REACH);
engine.
setOutputFormat("LETTERA_REACH_" + cod, "PDF");
engine.setParameterValue
("Cod_Fornitore", cod);
engine.runReport();
createReport(job, engine,
"LETTERA_REACH_" + cod);
String retValue = engine.getUrl();
engine.stopEngine();
return retValue;
} catch (BirtException
e) {
throw new ExceptionLTBL(e.getMessage());
}
}
I will appreciate any
help.
Thank's in advance.