Home » Archived » BIRT » How to modify, run and render a Report?
How to modify, run and render a Report? [message #157065] |
Fri, 28 April 2006 07:07  |
Eclipse User |
|
|
|
I would like to modify a report prior to sending it the the
report engine to be rendered.
I therefore combined the example to use the DE API and the code
from ReportRunner to solve the task.
The problem i now face is that i cannot include the model.jar in
the classpath since this creates an error when using the report engine.
As i understand it an initalization of the plugin is neccessary for
the engine to be able to run (which is done by the framework).
How can I use the DesignEngine without putting it in the classpath -
or put it another way, how must I load the model plugin correctly?
Thanks for your help
Peter
|
|
|
Re: How to modify, run and render a Report? [message #157201 is a reply to message #157065] |
Fri, 28 April 2006 11:39   |
Eclipse User |
|
|
|
Peter,
What version of BIRT are you using?
I did an example with 2.0.1.
I combined the two as well and all I had to do was add the Jars in the
Report Engine folder to my classpath. Attached is the code. Note that I
did not save to a file. I used Buffered Streams, which isn't memory
efficient. Pipes are probably better.
Jason
import java.util.HashMap;
import java.io.*;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.GridHandle;
import org.eclipse.birt.report.model.api.ImageHandle;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.TableHandle;
import java.util.logging.Level;
public class ExecuteReportDEAPI {
static void executeReport() throws EngineException {
HashMap parameters = new HashMap();
EngineConfig config = new EngineConfig();
config
.setEngineHome("C:/birt-runtime-2_0_1/birt-runtime-2_0_1/Report
Engine");
try {
// Create a session handle. Use Default Locale
SessionHandle session = DesignEngine.newSession(null);
// Create a new report design.
ReportDesignHandle design = session.createDesign();
// The element factory creates instances of the various BIRT elements.
ElementFactory factory = design.getElementFactory();
// Create a simple master page
DesignElementHandle element = factory
.newSimpleMasterPage("Page Master");
design.getMasterPages().add(element);
// Create a grid and add it to the "body" slot of the report
// design.
GridHandle grid = factory
.newGridItem(null, 2 /* cols */, 1 /* row */);
design.getBody().add(grid);
TableHandle th = factory.newTableItem("test", 2);
design.getBody().add(th);
th.setWidth("100%");
grid.setWidth("100%");
// Get the first row of grid.
RowHandle row = (RowHandle) grid.getRows().get(0);
// Create an image and add it to the first cell.
ImageHandle image = factory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);
cell.getContent().add(image);
image.setURI("\"c:/test/CreateReport/images/eclipseconlogo.jpg\ "");
// Create a label and add it to the second cell.
LabelHandle label = factory.newLabel(null);
cell = (CellHandle) row.getCells().get(1);
cell.getContent().add(label);
label.setText("Welcome to EclipseCon!");
// Save the design and close it.
//design.saveAs( "c:/test/CreateReport/EclipseCon.rptdesign" );
ByteArrayOutputStream rout = new ByteArrayOutputStream();
design.serialize(rout);
ByteArrayInputStream rin = new ByteArrayInputStream(rout
.toByteArray());
design.close();
session.closeAll(true);
System.out.println("Finished Report Design!");
//Create the report engine
ReportEngine engine = new ReportEngine(config);
IReportRunnable rptdesign = null;
rptdesign = engine.openReportDesign(rin);
IRunAndRenderTask task = engine.createRunAndRenderTask(rptdesign);
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");
HashMap contextMap = new HashMap();
contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEX T,
renderContext);
task.setAppContext(contextMap);
//task.setParameterValues(parameters);
task.setParameterValue("Top Count", new Integer(12));
task.validateParameters();
//ProcessFilter pf = new ProcessFilter();
//task.addScriptableJavaObject("pFilter", pf);
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setEmbeddable(true);
options.setOutputFileName("c:\\test\\ExecuteReport\\ERDEAPI.html ");
options.setOutputFormat("html");
//options.setHtmlPagination(true);
task.setRenderOption(options);
//run the report and destroy the engine
task.run();
task.close();
engine.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
try {
executeReport();
} catch (Exception e) {
e.printStackTrace();
}
}
}
"Peter Fopma" <peter.fopma@ifb-group.com> wrote in message
news:20a44560e300ac6f1a6cd981bd478132$1@www.eclipse.org...
>I would like to modify a report prior to sending it the the
> report engine to be rendered.
>
> I therefore combined the example to use the DE API and the code
> from ReportRunner to solve the task.
> The problem i now face is that i cannot include the model.jar in
> the classpath since this creates an error when using the report engine.
> As i understand it an initalization of the plugin is neccessary for
> the engine to be able to run (which is done by the framework).
>
> How can I use the DesignEngine without putting it in the classpath -
> or put it another way, how must I load the model plugin correctly?
>
> Thanks for your help
> Peter
>
|
|
| | |
Re: How to modify, run and render a Report? [message #157395 is a reply to message #157361] |
Mon, 01 May 2006 10:37   |
Eclipse User |
|
|
|
Peter,
The example I posted will not work it RC1a. It should work in RC2 when it
is available.
I am attaching an example of the executing a report that should work with
RC1a, but the DEAPI code is not in it.
Jason
import java.util.HashMap;
import java.io.*;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.EngineConstants;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.PlatformFileContext;
import org.eclipse.birt.core.framework.IPlatformContext;
public class ExecuteReport {
static void executeReport() throws EngineException
{
IReportEngine engine;
HashMap parameters = new HashMap();
//Engine Configuration - set and get temp dir, BIRT home, Servlet context
EngineConfig config = new EngineConfig();
//config.setLogConfig("c:/test/ExecuteReport", Level.OFF);
//config.setLogConfig("", Level.OFF);
config.setEngineHome(
"C:/birt-runtime-2.1RC0/birt-runtime-2_1_0/ReportEngine" );
//Create the report engine
//ReportEngine engine = new ReportEngine( config );
IReportRunnable design = null;
try{
IPlatformContext context = new PlatformFileContext( );
Platform.startup( context );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
// JRE default level is INFO, which may reveal too much internal
// logging
// information.
engine.changeLogLevel( Level.FINEST );
//Open a report design - use design to modify design, retrieve embedded
images etc.
FileInputStream fs = new
FileInputStream("C:/test/2.1/ExecuteReport/SimpleListing.rptdesign ");
design = engine.openReportDesign(fs);
//IReportRunnable design =
engine.openReportDesign("C:/test/ExecuteReport/TopNPercent.rptdesign ");
//Create task to run the report - use the task to execute and run the
report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//config.setTempDir("c:/work/test/tmp");
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
task.setAppContext( contextMap );
//task.setParameterValues(parameters);
task.setParameterValue("Top Count", new Integer(12));
task.validateParameters();
//ProcessFilter pf = new ProcessFilter();
//task.addScriptableJavaObject("pFilter", pf);
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setEmbeddable(true);
options.setOutputFileName("C:/test/2.1/ExecuteReport/SimpleListing.html ");
options.setOutputFormat("html");
//options.setHtmlPagination(true);
task.setRenderOption(options);
//run the report and destroy the engine
task.run();
task.close();
engine.destroy();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
"Peter Fopma" <peter.fopma@ifb-group.com> wrote in message
news:bba2d9aa9c638fa4804beae41b0951d5$1@www.eclipse.org...
> Dear Jason,
>
> I tried to run your sample code under version 2.1 RC1a and the same
> problem appears as with my own code. It fails with the exception:
>
> java.lang.NoClassDefFoundError: org/eclipse/birt/core/script/BirtHashMap
> at
> org.eclipse.birt.report.engine.executor.ExecutionContext.<init >(ExecutionContext.java:146)
> at
> org.eclipse.birt.report.engine.api.impl.EngineTask.<init>(EngineTask.java:119)
> at
> org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.<init >(RunAndRenderTask.java:53)
> at
> org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.c reateRunAndRenderTask(ReportEngineHelper.java:216)
> at
> org.eclipse.birt.report.engine.api.impl.ReportEngine.createR unAndRenderTask(ReportEngine.java:257)
> at
> org.eclipse.birt.report.engine.api.ReportEngine.createRunAnd RenderTask(ReportEngine.java:148)
> at ExecuteReportDEAPI.executeReport(ExecuteReportDEAPI.java:98)
> at ExecuteReportDEAPI.main(ExecuteReportDEAPI.java:138)
> Exception in thread "main"
>
> When adding the org.eclipse.birt.core.jar to the classpath the following
> happens: the class Platform in org.eclipse.birt.core has a function
> startup()
> which starts the OSGI Framework. launcher.startup(context) should
> load the core plugin and afterwards the platform variable should be
> set. This is not the case and the code later fails with a NULL-Pointer
> exception.
>
> Any idea how this can be resolved?
>
> Thanks
> Peter
>
|
|
| |
Re: How to modify, run and render a Report? [message #157589 is a reply to message #157558] |
Mon, 01 May 2006 16:49   |
Eclipse User |
|
|
|
Peter,
I am not certain this is the same problem. Your app if it is an ODA should
have a runtime reliance on ODA anyways. I just tried executing a report
using the REAPI with a flatfile datasource and didnt have to include
anything related to ODA at design time, just the libs in the RE lib
directory. All I had to do is make sure OSGI loaded up my plugins, by using
the factory to create the engine.
IPlatformContext context = new PlatformFileContext( );
Platform.startup( context );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
Try this with your example. Note this is 2.1 rc1a and make sure your ODA is
in the plugins directory. Let me know how it goes.
Jason
Here is the code I used
import java.util.HashMap;
import java.io.*;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.EngineConstants;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.PlatformFileContext;
import org.eclipse.birt.core.framework.IPlatformContext;
public class ExecuteReport {
static void executeReport() throws EngineException
{
IReportEngine engine;
HashMap parameters = new HashMap();
//Engine Configuration - set and get temp dir, BIRT home, Servlet context
EngineConfig config = new EngineConfig();
//config.setLogConfig("c:/test/ExecuteReport", Level.OFF);
//config.setLogConfig("", Level.OFF);
config.setEngineHome(
"C:/birt-runtime-2.1RC0/birt-runtime-2_1_0/ReportEngine" );
//Create the report engine
//ReportEngine engine = new ReportEngine( config );
IReportRunnable design = null;
try{
IPlatformContext context = new PlatformFileContext( );
Platform.startup( context );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
// JRE default level is INFO, which may reveal too much internal
// logging
// information.
engine.changeLogLevel( Level.FINEST );
//Open a report design - use design to modify design, retrieve embedded
images etc.
FileInputStream fs = new
FileInputStream("C:/test/2.1/ExecuteReport/flatfile.rptdesign ");
design = engine.openReportDesign(fs);
//IReportRunnable design =
engine.openReportDesign("C:/test/ExecuteReport/TopNPercent.rptdesign ");
//Create task to run the report - use the task to execute and run the
report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//config.setTempDir("c:/work/test/tmp");
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
task.setAppContext( contextMap );
//task.setParameterValues(parameters);
task.setParameterValue("Top Count", new Integer(12));
task.validateParameters();
//ProcessFilter pf = new ProcessFilter();
//task.addScriptableJavaObject("pFilter", pf);
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setEmbeddable(true);
options.setOutputFileName("C:/test/2.1/ExecuteReport/flatfile.html ");
options.setOutputFormat("html");
//options.setHtmlPagination(true);
task.setRenderOption(options);
//run the report and destroy the engine
task.run();
task.close();
engine.destroy();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
"Peter Fopma" <peter.fopma@ifb-group.com> wrote in message
news:37ab3ac909777a89a8296bf9a33c57eb$1@www.eclipse.org...
> Jason, thanks for your answer.
> Another problem I face, might be related to this... I have a
> ODA-Datasource
> which provides BIRT with data. Part of the plugin code is in the
> application
> project.
> This makes it neccessary that the oda.jar is in the classpath and this
> results
> in the same problem as we discussed with the model.jar. Try to
> use a flatfile datasource, include the oda.jar file in the classpath
> and execute the ReportRunner class.
> Will this problem also be fixed in the new version RC2? Or will the
> problem
> only be resolved for the design engine.
>
> Thanks
> Peter
>
>
|
|
| | |
Re: How to modify, run and render a Report? [message #158796 is a reply to message #157815] |
Fri, 05 May 2006 11:55  |
Eclipse User |
|
|
|
Jason, I tried the new version (RC2) and using the flatfile plugin now
works
when using the design engine and the report engine.
But my own plugin can no longer be found. When trying to run a report with
my own datasource it fails with the exception below.
java.lang.IllegalArgumentException: The extension with ID
'org.eclipse.birt.report.data.oda.ifbbirtplugin' is not found!
at
org.eclipse.birt.report.model.plugin.ODAManifestUtil.getData SourceExtension(ODAManifestUtil.java:50)
at
org.eclipse.birt.report.model.plugin.OdaExtensibilityProvide r.isValidODADataSourceExtensionID(OdaExtensibilityProvider.j ava:201)
at
org.eclipse.birt.report.model.parser.OdaDataSourceState.pars eODADataSourceExtensionID(OdaDataSourceState.java:125)
at
org.eclipse.birt.report.model.parser.OdaDataSourceState.pars eAttrs(OdaDataSourceState.java:65)
at
org.eclipse.birt.report.model.parser.ModuleParserHandler.sta rtElement(ModuleParserHandler.java:159)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unk nown
Source)
at
org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyEle ment(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanSt artElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Fragme ntContentDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDo cument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at
org.eclipse.birt.report.model.parser.ModuleReader.readModule (ModuleReader.java:89)
at
org.eclipse.birt.report.model.parser.ModuleReader.readModule (ModuleReader.java:171)
at
org.eclipse.birt.report.model.parser.DesignReader.read(Desig nReader.java:135)
at
org.eclipse.birt.report.model.core.DesignSession.openDesign( DesignSession.java:208)
at
org.eclipse.birt.report.model.api.SessionHandle.openDesign(S essionHandle.java:174)
at
com.ifbag.okular.base.reportgen.CReportGenerator.getReportGe nerator(CReportGenerator.java:115)
at com.ifbag.okular.base.reportgen.CReportTest.main(CReportTest .java:49)
From the OSGI-framework I first got the error that the MANIFEST.MF file for
the plugin could not be found. I then created the file with the following
content listed below.
Could you give me a hint on what the problem could be?
Thanks
Peter
Bundle-SymbolicName: org.eclipse.birt.report.data.oda.ifbbirtplugin;
singleton=true
Bundle-Version: 1.0.0
Bundle-Name: ifb BIRT Plugin
Bundle-Vendor: ifb AG
Require-Bundle: org.eclipse.datatools.connectivity.oda,
org.eclipse.birt.core,
org.eclipse.jdt.core,
org.eclipse.core.resources
Bundle-ClassPath:
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/commons-collections-3.1.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/commons-dbcp-1.2.1.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/commons-pool-1.2.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/db2java.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/eigenbase-properties.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/eigenbase-resgen.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/eigenbase-xom.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/ifbfagbase.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/javacup.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/log4j-1.2.8.jar,
lib/birt/plugins/org.eclipse.birt.report.data.oda.ifbbirtplu gin/lib/mondrian.jar
Bundle-Activator:
org.eclipse.birt.report.data.oda.ifbbirtplugin.plugin.IfbBir tPlugin
|
|
|
Goto Forum:
Current Time: Tue May 06 16:47:06 EDT 2025
Powered by FUDForum. Page generated in 0.07408 seconds
|