Java源码示例:org.eclipse.birt.report.engine.api.IReportRunnable
示例1
public void createReportDocument( String reportDesign, String reportDocument )
throws EngineException
{
// open the report runnable to execute.
IReportRunnable report = engine.openReportDesign( reportDesign );
// create an IRunTask
IRunTask task = engine.createRunTask( report );
try
{
// execute the report to create the report document.
task.run( reportDocument );
}
finally
{
// close the task, release the resource.
task.close( );
}
}
示例2
public void testDesignStream( )
{
try
{
IReportRunnable runnable = engine
.openReportDesign( new FileInputStream( new File(
REPORT_DESIGN ) ) );
IRunTask runTask = engine.createRunTask( runnable );
runTask.run( REPORT_DOCUMENT );
IReportDocument rptDoc = engine
.openReportDocument( REPORT_DOCUMENT );
InputStream inputStream = rptDoc.getDesignStream( );
assertTrue( inputStream != null );
int streamLength = ( (RAInputStream) inputStream ).available( );
assertTrue( streamLength > 0 );
rptDoc.close( );
}
catch ( Exception ex )
{
ex.printStackTrace( );
fail( );
}
}
示例3
public void testSortByOnDatasetColumn( ) throws EngineException,
SemanticException
{
IReportRunnable report = engine.openReportDesign( REPORT_DESIGN );
IGetParameterDefinitionTask task = engine
.createGetParameterDefinitionTask( report );
Collection list = task.getSelectionListForCascadingGroup(
"SortBysOfSingleDataSet", new Object[0] );
Object[] content = list.toArray( );
assertEquals( "USA", SelectionChoiceUtil.getValue( content[1] ) );
list = task.getSelectionListForCascadingGroup(
"SortBysOfSingleDataSet", new Object[]{"USA"} );
content = list.toArray( );
assertEquals( "MA", SelectionChoiceUtil.getValue( content[1] ) );
}
示例4
/**
* create the report document.
*
* @return
* @throws Exception
*/
protected String createReportDocument( String reportdesign,
String reportdocument ) throws Exception
{
reportdesign = this.genInputFile( reportdesign );
reportdocument = this.genOutputFile( reportdocument );
// open an report archive, it is a folder archive.
IDocArchiveWriter archive = new FileArchiveWriter( reportdocument );
// open the report runnable to execute.
IReportRunnable report = engine.openReportDesign( reportdesign );
// create an IRunTask
IRunTask runTask = engine.createRunTask( report );
// execute the report to create the report document.
runTask.setAppContext( new HashMap( ) );
runTask.run( archive );
// close the task, release the resource.
runTask.close( );
return reportdocument;
}
示例5
/**
* Run and render a report with certain servlet path
*
* @param request
*
* @param runnable
* @param outputStream
* @param format
* @param locale
* @param rtl
* @param parameters
* @param masterPage
* @param svgFlag
* @param displayTexts
* @param servletPath
* @param reportTitle
* @deprecated
* @throws RemoteException
* @throws IOException
*/
public void runAndRenderReport( HttpServletRequest request,
IReportRunnable runnable, OutputStream outputStream, String format,
Locale locale, boolean rtl, Map parameters, boolean masterPage,
boolean svgFlag, Map displayTexts, String servletPath,
String reportTitle ) throws RemoteException
{
runAndRenderReport( request,
runnable,
outputStream,
format,
locale,
rtl,
parameters,
masterPage,
svgFlag,
null,
null,
null,
displayTexts,
servletPath,
reportTitle,
null );
}
示例6
/**
* create folder-based report document
*
* @param design
* source report design with absolute path
* @param folderDoc
* folderdocument with absolute path like "c:/doc/"
* @throws IOException
* @throws EngineException
*/
private void createFolderDocument( String design, String folderDoc )
throws IOException, EngineException
{
IRunTask runTask;
FolderArchiveWriter writer;
folderArchive = folderDoc;
writer = new FolderArchiveWriter( folderArchive );
IReportRunnable runnable = engine.openReportDesign( design );
runTask = engine.createRunTask( runnable );
runTask.run( writer );
runTask.close( );
writer.finish( );
}
示例7
public DataExtractionTaskV0( ReportEngine engine, IReportDocument reader )
throws EngineException
{
super( engine, IEngineTask.TASK_DATAEXTRACTION );
IReportRunnable runnable = getOnPreparedRunnable( reader );
setReportRunnable( runnable );
IInternalReportDocument internalDoc = (IInternalReportDocument)reader;
Report reportIR = internalDoc.getReportIR( executionContext
.getReportDesign( ) );
executionContext.setReport( reportIR );
this.report = executionContext.getReport( );
// load the report
this.reportDocReader = reader;
executionContext.setReportDocument( reportDocReader );
executionContext.setFactoryMode( false );
executionContext.setPresentationMode( true );
}
示例8
private IReportDocument getReportCache(InputStream reportInputStream) throws EngineException{
IReportEngine engine = getReportEngine();
IReportRunnable design;
design = engine.openReportDesign(reportInputStream);
if (isUseLocalDB()){
updateDBUriToLocal(design);
}
//////////////////////////////////////////////
//design.getDesignInstance().getDataSource("").set
//getting available report parameters
//paramTask = engine.createGetParameterDefinitionTask(design);
updateParametersDefinitions(design);
//paramTask.getParameterDefn("my_parameter_name").getHandle().getElement().getProperty(null, "dataType").toString();
//paramTask.pa
//Create task to run the report - use the task to execute the report and save to disk.
IRunTask runTask = engine.createRunTask(design);
runTask.setParameterValues(config.getParameters());
//HashMap parameters1 = runTask.getParameterValues();
runTask.run(getReportCachePath());
runTask.close();
IReportDocument cache = engine.openReportDocument(getReportCachePath());
return cache;
}
示例9
public void testDynamicFilterParameters( ) throws EngineException
{
copyResource( DYNAMIC_FILTER_DESIGN, REPORT_DESIGN );
IReportRunnable runnable = engine.openReportDesign( REPORT_DESIGN );
IGetParameterDefinitionTask task = engine
.createGetParameterDefinitionTask( runnable );
// get parameter defn
IParameterDefnBase param = task.getParameterDefn( "Param_1" );
if ( param instanceof IDynamicFilterParameterDefn )
{
IDynamicFilterParameterDefn dynParam = (IDynamicFilterParameterDefn) param;
assertNotNull( dynParam.getColumn( ) );
}
else
fail( );
}
示例10
/**
* Build URI
*
* @param action
* @param context
* @return
*/
private String buildHyperlink( IAction action, IReportContext context )
{
IReportRunnable runnable = context.getReportRunnable( );
String actionURL = action.getActionString( );
if ( runnable != null )
{
ModuleHandle moduleHandle = runnable.getDesignHandle( )
.getModuleHandle( );
URL url = moduleHandle.findResource( actionURL, -1 );
if ( url != null )
actionURL = url.toString( );
}
return actionURL;
}
示例11
/**
* Test case for bugzilla bug <a
* href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=157189">157189</a> :
* HTML BR tags cease to work for text element after page break in PDF
*
* @throws EngineException
*/
public void estForeignContent( ) throws EngineException
{
String designFile = "org/eclipse/birt/report/engine/layout/pdf/LineAreaLMTest-157189.xml";
IReportRunnable report = openReportDesign( designFile );
List pageAreas = getPageAreas( report );
assertEquals( 2, pageAreas.size( ) );
PageArea pageArea = (PageArea)pageAreas.get( 1 );
Iterator logicContainers = pageArea.getBody( ).getChildren( );
IContainerArea blockContains = (IContainerArea) logicContainers
.next( );
logicContainers = blockContains.getChildren( );
IContainerArea blockContains1 = (IContainerArea) logicContainers
.next( );
Iterator lineAreas = blockContains1.getChildren( );
lineAreas.next( );
LineArea emptyLine = (LineArea)lineAreas.next( );
assertTrue( "Second line is not an empty line.", isEmpty( emptyLine ) );
LineArea lineArea = (LineArea)lineAreas.next( );
assertEquals( " ", getText( lineArea, 2 ) );
assertEquals( "paragraph 22.", getText( lineArea, 5 ) );
}
示例12
public synchronized IReportRunnable getReportRunnable( )
{
if ( reportRunnable == null )
{
reportRunnable = loadReportRunnable( systemId,
ORIGINAL_DESIGN_STREAM );
if ( reportRunnable != null )
{
reportRunnable.setPrepared( false );
}
else
{
reportRunnable = getOnPreparedRunnable( );
}
}
if ( reportRunnable != null )
{
return reportRunnable.cloneRunnable( );
}
return null;
}
示例13
/**
* createGetParameterDefinitionTask.
*
* @param runnable
* @deprecated
* @return the get parameter definition task
*/
public IGetParameterDefinitionTask createGetParameterDefinitionTask(
IReportRunnable runnable )
{
IGetParameterDefinitionTask task = null;
try
{
task = engine.createGetParameterDefinitionTask( runnable );
}
catch ( Exception e )
{
}
return task;
}
示例14
public boolean validateParameters( )
{
IReportRunnable runnable = executionContext.getRunnable( );
if ( runnable == null )
{
return false;
}
// set the parameter values into the execution context
try
{
return doValidateParameters( );
}
catch(ParameterValidationException ex)
{
log.log( Level.SEVERE, ex.getMessage( ), ex );
}
return false;
}
示例15
/**
* Open report design.
*
* @param report
* @param options
* the config options in the report design
* @return the report runnable
* @throws EngineException
*/
public IReportRunnable openReportDesign( String report, Map options )
throws EngineException
{
File file = new File( report );
if ( !file.exists( ) )
{
throw new EngineException( MessageConstants.DESIGN_FILE_NOT_FOUND_EXCEPTION,
report );
}
try
{
InputStream in = new FileInputStream( file );
String systemId = report;
try
{
systemId = file.toURI( ).toURL( ).toString( );
}
catch ( MalformedURLException ue )
{
systemId = report;
}
return engine.openReportDesign( systemId, in, options );
}
catch ( FileNotFoundException ioe )
{
throw new EngineException( MessageConstants.DESIGN_FILE_NOT_FOUND_EXCEPTION,
report );
}
}
示例16
/**
* createGetParameterDefinitionTask.
*
* @param runnable
* @return the get parameter definition task
*/
public IGetParameterDefinitionTask createGetParameterDefinitionTask(
IReportRunnable runnable, InputOptions options )
{
IGetParameterDefinitionTask task = null;
try
{
HttpServletRequest request = (HttpServletRequest) options.getOption( InputOptions.OPT_REQUEST );
Locale locale = (Locale) options.getOption( InputOptions.OPT_LOCALE );
TimeZone timeZone = (TimeZone) options.getOption( InputOptions.OPT_TIMEZONE );
task = engine.createGetParameterDefinitionTask( runnable );
task.setLocale( locale );
com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone( timeZone );
if ( tz != null )
{
task.setTimeZone( tz );
}
// set app context
Map context = BirtUtility.getAppContext( request );
task.setAppContext( context );
}
catch ( Exception e )
{
}
return task;
}
示例17
/**
* create the report document.
*
* @throws Exception
*/
protected void createReportDocument( ) throws EngineException
{
// open the report runnable to execute.
IReportRunnable report = engine.openReportDesign( REPORT_DESIGN );
// create an IRunTask
IRunTask task = engine.createRunTask( report );
// execute the report to create the report document.
task.run( REPORT_DOCUMENT );
// close the task, release the resource.
task.close( );
}
示例18
/**
* Test methods in RunAndRenderTask class
*/
public void testRunAndRenderTask( ) throws EngineException
{
String input = this.genInputFile( "report_engine.rptdesign" );
try
{
IReportRunnable runnable = engine
.openReportDesign( new FileInputStream( new File( input ) ) );
IRunAndRenderTask task = engine.createRunAndRenderTask( runnable );
// validateParameters
assertTrue( task.validateParameters( ) );
// set/getRenderOption
RenderOptionBase option = new RenderOptionBase( ), optionGet;
task.setRenderOption( option );
optionGet = (RenderOptionBase) task.getRenderOption( );
assertEquals( "set/getRenderOption fail", option, optionGet );
// parameters
HashMap hm = new HashMap( ), hmGet;
task.setParameterValues( hm );
hmGet = task.getParameterValues( );
assertEquals( "set/getParameterValues(hashmap) fail", hm, hmGet );
task.setParameterValue( "p1", "p1value" );
assertEquals( "Set/getParameterValues fail", task
.getParameterValues( )
.get( "p1" ), "p1value" );
}
catch ( FileNotFoundException e )
{
e.printStackTrace( );
}
}
示例19
protected void setUp( ) throws Exception
{
super.setUp( );
removeResource( );
copyResource_INPUT( INPUT, INPUT );
IReportRunnable runnable;
runnable = engine.openReportDesign( report );
paramTask = engine.createGetParameterDefinitionTask( runnable );
}
示例20
protected void setUp( ) throws Exception
{
super.setUp( );
removeResource( );
copyResource_INPUT( INPUT, INPUT );
IReportRunnable reportRunnable = engine.openReportDesign( rptdesign );
task = engine.createGetParameterDefinitionTask( reportRunnable );
assertTrue( task.getErrors( ).size( ) == 0 );
}
示例21
protected void updateRtLFlag( ) throws EngineException
{
//get RtL flag from renderOptions
if ( renderOptions == null )
return;
IReportRunnable runnable = executionContext.getRunnable( );
if ( runnable == null )
return;
ReportDesignHandle handle = (ReportDesignHandle) runnable
.getDesignHandle( );
if ( handle != null )
{
Object bidiFlag = renderOptions.getOption( IRenderOption.RTL_FLAG );
if ( Boolean.TRUE.equals( bidiFlag ) )
{
if ( !handle.isDirectionRTL( ) )
{
updateBidiStyle( true );
}
}
else if ( Boolean.FALSE.equals( bidiFlag ) )
{
if ( handle.isDirectionRTL( ) )
{
updateBidiStyle( false );
}
}
}
}
示例22
/**
* create the report document.
*
* @throws Exception
*/
protected void createReportDocument( String reportdesign,
String reportdocument ) throws Exception
{
// open an report archive, it is a folder archive.
IDocArchiveWriter archive = new FileArchiveWriter( reportdocument );
// open the report runnable to execute.
IReportRunnable report = engine.openReportDesign( reportdesign );
// create an IRunTask
IRunTask runTask = engine.createRunTask( report );
// execute the report to create the report document.
runTask.setAppContext( new HashMap( ) );
runTask.run( archive );
int i = runTask.getErrors( ).size( );
if ( i > 0 )
System.out.println( "error is "
+ runTask.getErrors( ).get( 0 ).toString( ) );
assertEquals(
"Exception when generate document from " + reportdesign,
0,
i );
// close the task, release the resource.
runTask.close( );
}
示例23
/**
* Create run and render result for the design file.
*
* @param designFile
* @return run and render task.
* @throws EngineException
*/
protected IRunAndRenderTask createRunAndRenderTask( String designFile )
throws EngineException
{
useDesignFile( designFile );
IReportRunnable reportDesign = engine.openReportDesign( REPORT_DESIGN );
IRunAndRenderTask runAndRenderTask = engine
.createRunAndRenderTask( reportDesign );
return runAndRenderTask;
}
示例24
/**
* Test createGetParameterDefinitionTask()
*/
public void testCreateGetParameterDefinitionTask( )
{
EngineConfig config = new EngineConfig( );
IReportRunnable reportRunner;
ReportEngine engine = new ReportEngine( config );
/*
* String input =
* PLUGIN_PATH+System.getProperty("file.separator")+RESOURCE_BUNDLE
* .getString("CASE_INPUT"); input +=
* System.getProperty("file.separator") ; String
* designName=input+"parameter.rptdesign";
*/
String designName = this.genInputFile( "parameter.rptdesign" );
try
{
reportRunner = engine.openReportDesign( designName );
IGetParameterDefinitionTask getParamTask = engine
.createGetParameterDefinitionTask( reportRunner );
getParamTask.evaluateDefaults( );
IParameterDefnBase paramDefn = getParamTask.getParameterDefn( "p1" );
System.err.println( paramDefn.getTypeName( ) );
System.err.println( paramDefn instanceof ScalarParameterDefn );
assertEquals(
"creatGetParameterDefinitionTask() fail",
"abc",
getParamTask.getDefaultValue( paramDefn ) );
}
catch ( EngineException ee )
{
ee.printStackTrace( );
}
}
示例25
public void testRender_unfinished_Document( )
{
try
{
String inputFile = this.getFullQualifiedClassName( )
+ "/" + INPUT_FOLDER + "/" + INPUT; //$NON-NLS-1$ //$NON-NLS-2$
String outputDoc = this.genOutputFile( REPORT_DOCUMENT_OUTPUT ); //$NON-NLS-1$
// open the report runnable to execute.
IReportRunnable report;
report = engine.openReportDesign( inputFile );
// create an IRunTask
IRunTask task = engine.createRunTask( report );
task.setAppContext( new HashMap( ) );
// execute the report to create the report document.
task.setPageHandler( new PageHandler( ) );
task.run( outputDoc );
// close the task, release the resource.
task.close( );
File html = new File( outputHtml );
assertTrue( html.exists( ) );
}
catch ( EngineException e )
{
e.printStackTrace( );
}
}
示例26
/**
* Test case for bugzilla bug <a
* href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=168804">168804</a> :
* Text only containing multiple line break are ignored in pdf
*
* @throws EngineException
*/
public void testMutipleLineBreakHeight() throws EngineException
{
String designFile = "org/eclipse/birt/report/engine/layout/pdf/168804.xml";
IReportRunnable report = openReportDesign( designFile );
List pageAreas = getPageAreas( report );
assertEquals( 1, pageAreas.size( ) );
PageArea pageArea = (PageArea)pageAreas.get( 0 );
Iterator logicContainers = pageArea.getBody( ).getChildren( );
IContainerArea blockContainer = (IContainerArea) logicContainers
.next( );
assertTrue("3 lines",blockContainer.getChildrenCount( )==3);
assertTrue("Line height is right", blockContainer.getHeight( )>=27000);
}
示例27
/**
* Run a report, generate a self-contained report document.
*
* @throws EngineException
*/
protected final ArrayList run( String input, String output )
throws EngineException
{
String outputFile = genOutputFile( output );
input = this.genInputFile( input );
IReportRunnable runnable = engine.openReportDesign( input );
IRunTask task = engine.createRunTask( runnable );
task.setAppContext( new HashMap( ) );
task.setLocale( locale );
IDocArchiveWriter archive = null;
try
{
archive = new FileArchiveWriter( outputFile );
}
catch ( IOException e )
{
e.printStackTrace( );
}
task.run( archive );
ArrayList errors = (ArrayList) task.getErrors( );
task.close( );
return errors;
}
示例28
private List runAndRender_WithPagination( String inputFile, String outputFile )
throws EngineException
{
IReportRunnable runnable = engine.openReportDesign( inputFile );
IRunAndRenderTask task = engine.createRunAndRenderTask( runnable );
task.setLocale( Locale.ENGLISH );
IRenderOption options = new HTMLRenderOption( );
options.setOutputFileName( outputFile );
( (HTMLRenderOption) options ).setHtmlPagination( true );
HTMLRenderContext renderContext = new HTMLRenderContext( );
renderContext.setImageDirectory( "image" ); //$NON-NLS-1$
HashMap appContext = new HashMap( );
appContext.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
task.setAppContext( appContext );
options.setOutputFormat( "html" ); //$NON-NLS-1$
options.getOutputSetting( )
.put( HTMLRenderOption.URL_ENCODING, "UTF-8" ); //$NON-NLS-1$
task.setRenderOption( options );
task.run( );
List errors = task.getErrors( );
task.close( );
return errors;
}
示例29
/**
* Run a report, generate a self-contained report document.
*
* @throws EngineException
*/
protected final ArrayList run( String input, String output )
throws EngineException
{
String outputFile = genOutputFile( output );
input = getFullQualifiedClassName( ) + "/" + INPUT_FOLDER + "/" + input;
IReportRunnable runnable = engine.openReportDesign( input );
IRunTask task = engine.createRunTask( runnable );
task.setAppContext( new HashMap( ) );
task.setLocale( locale );
IDocArchiveWriter archive = null;
try
{
archive = new FileArchiveWriter( outputFile );
}
catch ( IOException e )
{
e.printStackTrace( );
}
task.run( archive );
ArrayList errors = (ArrayList) task.getErrors( );
task.close( );
return errors;
}
示例30
/**
* test text wrapping alogrithm.
* @throws EngineException
*/
public void testTextWrap() throws EngineException
{
String designFile = "org/eclipse/birt/report/engine/layout/pdf/textWrap.xml";
IReportRunnable report = openReportDesign( designFile );
List pageAreas = getPageAreas( report );
assertEquals( 1, pageAreas.size( ) );
PageArea pageArea = (PageArea)pageAreas.get( 0 );
ContainerArea body = (ContainerArea)pageArea.getBody( );
Iterator iter = body.getChildren( );
TableArea table = (TableArea) iter.next( );
iter = table.getChildren( );
RowArea row = (RowArea)iter.next( );
iter = row.getChildren( );
CellArea cell = (CellArea)iter.next( );
Iterator it = cell.getChildren( );
ContainerArea container = (ContainerArea)it.next( );
assertTrue(container.getChildrenCount( )==1);
cell = (CellArea)iter.next( );
it = cell.getChildren( );
container = (ContainerArea)it.next( );
assertTrue(container.getChildrenCount( )==2);
cell = (CellArea)iter.next( );
it = cell.getChildren( );
container = (ContainerArea)it.next( );
assertTrue(container.getChildrenCount( )==2);
}