Skip to main content



      Home
Home » Archived » BIRT » Display CSV in an output Stream
Display CSV in an output Stream [message #169620] Tue, 13 June 2006 05:18 Go to next message
Eclipse UserFriend
Hello,

I would like to know how i can displmay the csv document in the web
browser. So the exemple of the extraction task display the result with
System.out...

So what is the mean as the render option task to have the result in the
web browser as in the viewer extract action, but with the api ?

thank a lot for that nice product.
Re: Display CSV in an output Stream [message #169956 is a reply to message #169620] Tue, 13 June 2006 20:13 Go to previous messageGo to next message
Eclipse UserFriend
You should be able to replace the system.outs with
writes to the response.getOutputStream in a Servlet.

Jason

"Sebastien.marin" <sebastien.marin@hotmail.fr> wrote in message
news:7da1dcb220f96f9515c269ee04c363ad$1@www.eclipse.org...
> Hello,
>
> I would like to know how i can displmay the csv document in the web
> browser. So the exemple of the extraction task display the result with
> System.out...
>
> So what is the mean as the render option task to have the result in the
> web browser as in the viewer extract action, but with the api ?
> thank a lot for that nice product.
>
Re: Display CSV in an output Stream [message #170058 is a reply to message #169956] Wed, 14 June 2006 03:33 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, i try it and it's OK.

I use the api with the extraData method :
"extractData( IReportDocument document, String resultSetName, Collection
columns, Locale locale, OutputStream outputStream )"

So my last question is : what is the "resultSetName" parameter.
When we use the viewer and click to the link to generate CSV, resultset
available are displayed as "ELEMENT_22_0". Where is configure that name of
resultset?


Thank you very much for your help.
Re: Display CSV in an output Stream [message #170268 is a reply to message #170058] Wed, 14 June 2006 12:10 Go to previous messageGo to next message
Eclipse UserFriend
This is automatically generated.
If you put a name on the element it should show up though.
For example if I name my table mytable, it will show up something like
mytable_0.

Jason

"Sebastien.marin" <sebastien.marin@hotmail.fr> wrote in message
news:08552613c1b8c60eeaff66455dff3412$1@www.eclipse.org...
> Thanks, i try it and it's OK.
> I use the api with the extraData method :
> "extractData( IReportDocument document, String resultSetName, Collection
> columns, Locale locale, OutputStream outputStream )"
>
> So my last question is : what is the "resultSetName" parameter.
> When we use the viewer and click to the link to generate CSV, resultset
> available are displayed as "ELEMENT_22_0". Where is configure that name of
> resultset?
>
>
> Thank you very much for your help.
>
Re: Display CSV in an output Stream [message #170546 is a reply to message #170268] Thu, 15 June 2006 05:58 Go to previous messageGo to next message
Eclipse UserFriend
Ok, is there a mean to get the resultSetName when the rptDocument is
generate, just before to make the extractTask ???

Thank you.
Re: Display CSV in an output Stream [message #170711 is a reply to message #170546] Thu, 15 June 2006 12:36 Go to previous messageGo to next message
Eclipse UserFriend
Take a look at this example.

The main part to look at is:



List resultSetList = (List)iDataExtract.getResultSetList( );

Iterator it = resultSetList.iterator();

IResultSetItem resultItem = null;

while( it.hasNext()){

resultItem = (IResultSetItem)it.next();

System.out.println("Result Set Available: " +
resultItem.getResultSetName());

}



Jason






import java.util.Iterator;

import java.util.List;

import java.util.logging.Level;


import org.eclipse.birt.core.framework.Platform;

import org.eclipse.birt.data.engine.api.IResultMetaData;

import org.eclipse.birt.data.engine.core.DataException;

import org.eclipse.birt.report.engine.api.EngineConfig;

import org.eclipse.birt.report.engine.api.EngineException;

import org.eclipse.birt.report.engine.api.IDataExtractionTask;

import org.eclipse.birt.report.engine.api.IDataIterator;

import org.eclipse.birt.report.engine.api.IExtractionResults;

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.IResultSetItem;

import org.eclipse.birt.report.engine.api.IRunTask;


public class DataExtract {


static void readReport() throws EngineException

{

IReportEngine engine=null;

try{

EngineConfig config = new EngineConfig( );

config.setEngineHome(
"C:\\birt-runtime-2.1RC4\\birt-runtime-2_1_0\\ReportEngine" );

Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform

..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );

engine = factory.createReportEngine( config );

engine.changeLogLevel( Level.WARNING );

}catch( Exception ex){

ex.printStackTrace();

}


//Open a report design - use design to modify design, retrieve embedded
images etc.

IReportRunnable design =
engine.openReportDesign("C:/test/2.1/extracttest/csvtest.rptdesign ");


//Create task to run the report - use the task to execute and run the
report,

IRunTask task = engine.createRunTask(design);




//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 );




//run the report and save the report document

task.run("C:/test/2.1/extracttest/csvtest.rptdocument");


IReportDocument ReportDocument =
engine.openReportDocument("C:/test/2.1/extracttest/csvtest.rptdocument ");

//IReportDocument iReportDocument =
engine.openReportDocument("c:/test/DataExtract/ggg.rptdocument ");


//Setup data extraction task

IDataExtractionTask iDataExtract =
engine.createDataExtractionTask(ReportDocument);




/**

* returns the metadata corresponding to the data stored in the report

* document. Could specify a component.

*/


List resultSetList = (List)iDataExtract.getResultSetList( );

Iterator it = resultSetList.iterator();

IResultSetItem resultItem = null;

while( it.hasNext()){

resultItem = (IResultSetItem)it.next();

System.out.println("Result Set Available: " +
resultItem.getResultSetName());

}


//For example just use the last


String dispName = resultItem.getResultSetName( );

iDataExtract.selectResultSet( dispName );


IExtractionResults iExtractResults = iDataExtract.extract();

IDataIterator iData = null;

try{

if ( iExtractResults != null )

{

iData = iExtractResults.nextResultIterator( );


//Get metadata on retrieved results

IResultMetaData irmd = iData.getResultMetaData();

if ( iData != null ){

int colCount = irmd.getColumnCount();

System.out.println("Cloumn Count =" + colCount );

for( int j=0; j< colCount; j++){

System.out.println("Cloumn Name =" + irmd.getColumnName(j) );

System.out.println("Cloumn Type =" + irmd.getColumnTypeName(j) );

}


while ( iData.next( ) )

{

//Just disply the first two columns

Object objColumn1;

Object objColumn2;

try{

objColumn1 = iData.getValue(0);

}catch(DataException e){

objColumn1 = new String("");

}

try{

objColumn2 = iData.getValue(1);

}catch(DataException e){

objColumn2 = new String("");

}

System.out.println( objColumn1 + " , " + objColumn2 );

}

iData.close();

}

}

}

catch( Exception e){

e.printStackTrace();

}


iDataExtract.close();

engine.destroy();

}

/**

* @param args

*/

public static void main(String[] args) {

try

{

readReport( );

}

catch ( Exception e )

{

e.printStackTrace();

}

}


}

"Sebastien.marin" <sebastien.marin@hotmail.fr> wrote in message
news:a9ec43f9751516a2341a2af9f27aab44$1@www.eclipse.org...
> Ok, is there a mean to get the resultSetName when the rptDocument is
> generate, just before to make the extractTask ???
>
> Thank you.
>
Re: Display CSV in an output Stream [message #170876 is a reply to message #170711] Fri, 16 June 2006 03:41 Go to previous message
Eclipse UserFriend
Ok, thank you for your quick answer. It's exactly what i need.


Good luck.
Previous Topic:Manipulate Dataset results with API
Next Topic:Re: BIRT 2.1.0 distribution missing some plugin metadata?
Goto Forum:
  


Current Time: Sat Jul 19 07:42:56 EDT 2025

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

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

Back to the top