Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Passing xml file dynamically to birt
Passing xml file dynamically to birt [message #1308787] Tue, 22 April 2014 09:11
Naveen Kumar is currently offline Naveen KumarFriend
Messages: 4
Registered: April 2014
Junior Member
Hi,

My requirement is to generate birt report by passing XML files. I tried the below code, but the final reportis blank..Please help me on this..

import java.util.logging.Level;
import java.util.HashMap;
import java.io.*;
import java.net.URL;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
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.data.oda.xml.util.XMLDataInputStream;
import org.eclipse.birt.report.data.oda.xml.util.XMLDataInputStreamCreator;
import org.eclipse.birt.report.data.oda.xml.Constants;


public class testDrive
{
private static HashMap inputStreamCache = new HashMap();
public static void main(String[] args)
{
try
{

IReportEngine engine= null;
EngineConfig config = null;
IReportRunnable design = null;
IRunAndRenderTask task = null;
HTMLRenderContext renderContext = null;
HashMap contextMap = null;
HTMLRenderOption options = null;

try
{
config = new EngineConfig( );
config.setEngineHome("D:\\BIRT\\birt-runtime-4_3_2\\ReportEngine");
//config.setLogConfig("D:\\D\\logs", Level.FINE);
System.out.println("Parameters set");

Platform.startup( config );
System.out.println("Engine started");
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
engine.changeLogLevel( Level.WARNING );
System.out.println("Log level changed");

try
{
design = engine.openReportDesign("D:\\BIRT\\birtTemplate.rptDesign");
System.out.println("File opened!!!");
}
catch (Exception e)
{
System.err.println("An error occured during the opening of the report file!");
e.printStackTrace();
System.exit(-1);
}

task = engine.createRunAndRenderTask(design);

StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\nkj\\Downloads\\scorecard.xml"));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
reader.close();
String xmlFile = fileData.toString();
String DataLine = "";

ByteArrayInputStream bis = new ByteArrayInputStream(xmlFile.getBytes("UTF8"));

BufferedReader br = new BufferedReader(new InputStreamReader(bis));
while ((DataLine = br.readLine()) != null)
{
System.out.println(DataLine);
}
br.close();

renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");
contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );


XMLDataInputStream xmlStream = new XMLDataInputStream(bis); ;

contextMap.put("org.eclipse.datatools.enablement.oda.xml.inputStream", xmlStream);
contextMap.put("org.eclipse.datatools.enablement.oda.xml.closeInputStream", new Boolean(true));


task.setAppContext( contextMap );

options = new HTMLRenderOption();
options.setOutputFileName("D:\\BIRT\\xmlds_output.pdf");
options.setOutputFormat("pdf");
task.setRenderOption(options);

try
{
task.run();
}
catch (Exception e)
{
System.err.println("An error occured while running the report!");
e.printStackTrace();
System.exit(-1);
}

System.out.println("All went well. Closing program!");
engine.destroy();
engine.shutdown();
Platform.shutdown();
System.out.println("Finished");

}
catch( Exception ex)
{
ex.printStackTrace();
}
} catch( Exception ex)
{
ex.printStackTrace();
}
}

}


Previous Topic:BIRT reports as a product and copyrights question
Next Topic:Strange behaviour in creating PDF output
Goto Forum:
  


Current Time: Thu Apr 25 03:30:53 GMT 2024

Powered by FUDForum. Page generated in 0.02900 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top