POJO passing params to BIRT [message #93464] |
Mon, 21 November 2005 12:59  |
Eclipse User |
|
|
|
Originally posted by: mlorenz.nc.rr.com
I want to pass some parameters to a BIRT report via POJO at launch time
and/or via scripting. I see lots of examples to use SQL params and some
skeleton code to pass via scripting (but does not compile).
Is there an example to do this that works?
Thx, Mark
|
|
|
Re: POJO passing params to BIRT [message #93512 is a reply to message #93464] |
Mon, 21 November 2005 15:30  |
Eclipse User |
|
|
|
If I understand your question - here is a test method I used to pass
parameters to a report from a java class. It creates a HTML file based on a
report design name and a hash map of parameters. The HashMap key values are
the parameter names that you defined when create your report design.
(to create the report)
HashMap params = new HashMap();
params.put( "parmName", <object> );
File htmlFile = ReportWriterHTML().createReport( "test.rptdesign",
params );
public class ReportWriterHTML {
// The static logger
static protected Logger logger = Logger.getLogger(
ReportRunner.class.getName() );
private static ReportWriterHTML rw = new ReportWriterHTML();
protected String encoding = null;
ReportEngine engine;
/**
* Constructor of ReportRunner
*
* @param args - application arguments
*/
private ReportWriterHTML() {
EngineConfig config = new EngineConfig();
IPlatformContext context = new PlatformFileContext();
config.setEngineContext( context );
config.setEngineHome( "c:\\test\\birt-runtime-1_0_1\\Report Engine");
engine = new ReportEngine( config );
engine.changeLogLevel( Level.WARNING );
}
public static File createReport( String designName ) {
return createReport( designName, (HashMap) null );
}
public static File createReport( String designName, HashMap parms ) {
File fl = null;
try {
fl = File.createTempFile( null, "htmlrpt", null );
rw.createHTML( designName, parms, fl );
} catch ( IOException ex ) {
logger.log( Level.SEVERE, "Unable to create temporary file "
+ ex.getMessage(), ex );
}
return fl;
}
public static File createReport( String designName, String
outputFileName ) {
return createReport( designName, (HashMap) null, outputFileName );
}
public static File createReport( String designName, HashMap parms,
String outputFileName ) {
File fl = new File( outputFileName );
rw.createHTML( designName, parms, fl );
return fl;
}
/**
* Check if the arguments are valid. If yes, continue to execuate the
report.
* If no, simply return.
*/
protected void createHTML( String designName, HashMap parms, File
outputFile ) {
IReportRunnable design;
try {
design = engine.openReportDesign( designName );
} catch ( EngineException e ) {
logger.log( Level.SEVERE,
"There are errors generating the report in design file.", e );
return;
}
// Generate the output content
executeHTML( design, parms, outputFile );
}
/**
*/
protected void executeHTML( IReportRunnable design, HashMap params,
File outputFile ) {
try {
IRunAndRenderTask task = engine.createRunAndRenderTask( design );
if ( params != null ) {
task.setParameterValues( params );
}
// set report render options
IRenderOption options;
options = new HTMLRenderOption();
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory( "image" );
task.setContext( renderContext );
options.setOutputFileName( outputFile.getName() );
options.setOutputFormat( "html" );
( (HTMLRenderOption) options ).setEmbeddable( true );
task.setRenderOption( options );
task.run();
} catch ( org.eclipse.birt.report.engine.api.EngineException e ) {
logger.log( Level.SEVERE, e.getMessage(), e );
}
}
}
(NOTE: I hard coded the report engine home)
I have since moved on to a much different implementation but I hope this
helps.
"Mark Lorenz" <mlorenz@nc.rr.com> wrote in message
news:d23779b13c3f9c775869a3c413950662$1@www.eclipse.org...
> I want to pass some parameters to a BIRT report via POJO at launch time
> and/or via scripting. I see lots of examples to use SQL params and some
> skeleton code to pass via scripting (but does not compile).
>
> Is there an example to do this that works?
>
> Thx, Mark
>
|
|
|
Powered by
FUDForum. Page generated in 0.05903 seconds