Java源码示例:org.eclipse.birt.report.engine.api.HTMLRenderOption
示例1
private HTMLRenderOption prepareFrontEndHtmlRenderOption() {
logger.debug("IN");
String tmpDir = System.getProperty("java.io.tmpdir");
String imageDirectory = tmpDir.endsWith(File.separator) ? tmpDir + "birt" : tmpDir + File.separator + "birt";
String imageBaseUrl = "BirtImageServlet?imageID=";
// Register new image handler
HTMLRenderOption renderOption = new HTMLRenderOption();
renderOption.setActionHandler(new HTMLActionHandler());
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
renderOption.setImageHandler(imageHandler);
renderOption.setImageDirectory(imageDirectory);
renderOption.setBaseImageURL(imageBaseUrl);
renderOption.setEmbeddable(false);
logger.debug("OUT");
return renderOption;
}
示例2
private HTMLRenderOption prerareBackEndHtmlRenderOption() {
logger.debug("IN");
HTMLRenderOption renderOption = new HTMLRenderOption();
renderOption.setOutputFormat(HTMLRenderOption.HTML);
renderOption.setSupportedImageFormats("PNG;GIF;JPG;BMP");
renderOption.setEmbeddable(false);
renderOption.setImageHandler(new HTMLServerImageHandler() {
@Override
protected String handleImage(IImage image, Object context, String prefix, boolean needMap) {
byte[] encodedBytes = Base64.encodeBase64(image.getImageData());
String embeddedImage = new String(encodedBytes);
String extension = image.getExtension().substring(1).toLowerCase(); // it starts with "."
return "data:image/" + extension + ";base64," + embeddedImage;
}
});
logger.debug("OUT");
return renderOption;
}
示例3
/**
* Test setRenderOption(IRenderOption) method Test getRenderOption() method
*/
public void testGetRenderOption( )
{
RenderOptionBase rendop = new RenderOptionBase( );
rendop.setOutputFormat( "fo" );
rendop.setOutputFileName( "outputfile" );
HTMLRenderContext context = new HTMLRenderContext( );
context.setRenderOption( rendop );
RenderOptionBase ropb = (RenderOptionBase) ( context.getRenderOption( ) );
assertEquals( "fo", ropb.getOutputFormat( ) );
Map outsetting = new HashMap( );
outsetting = ropb.getOutputSetting( );
assertFalse( outsetting.isEmpty( ) );
assertEquals( 2, outsetting.size( ) );
ropb.getOutputSetting( ).put( HTMLRenderOption.URL_ENCODING, "UTF-8" );
assertEquals( 3, outsetting.size( ) );
}
示例4
/**
* @param format
* render format
* @param pagination
* For html output only, decide whether generate report with page
* break or not.
* @throws EngineException
*/
protected ArrayList runandrender_emitter( String format, boolean pagination )
throws EngineException
{
IReportRunnable reportRunnable = engine.openReportDesign( inPath
+ getReportName( ) );
IRunAndRenderTask task = engine.createRunAndRenderTask( reportRunnable );
RenderOption options = new HTMLRenderOption( );
options.setOutputFormat( format );
if ( format.equals( EMITTER_HTML ) )
{
( (HTMLRenderOption) options ).setHtmlPagination( pagination );
}
HashMap appContext = new HashMap( );
appContext.put( "emitter_class", this );
task.setAppContext( appContext );
task.setRenderOption( options );
task.run( );
ArrayList errors = (ArrayList) task.getErrors( );
task.close( );
return errors;
}
示例5
public void testVisionOptimize( ) throws EngineException, IOException
{
HTMLRenderOption options = new HTMLRenderOption( );
options.setOutputMasterPageMargins( true );
options.setEmbeddable( false );
ByteArrayOutputStream output = new ByteArrayOutputStream( );
List instanceIDs = new ArrayList( );
options.setInstanceIDs( instanceIDs );
options.setOutputStream( output );
options.setEnableMetadata( true );
IRenderTask task = createRenderTask( designFile );
task.setRenderOption( options );
task.render( );
task.close( );
String content = new String( output.toByteArray( ) );
output.close( );
String regex = "<col style=\"width: 1.25in;\">";
Matcher matcher = Pattern.compile( regex ).matcher( content );
assertEquals( true, matcher.find( ) );
}
示例6
public void testInlineStyle( ) throws EngineException, IOException
{
HTMLRenderOption options = new HTMLRenderOption( );
options.setEmbeddable( true );
options.setEnableInlineStyle( true );
ByteArrayOutputStream output = new ByteArrayOutputStream( );
List instanceIDs = new ArrayList( );
options.setInstanceIDs( instanceIDs );
options.setOutputStream( output );
IRenderTask task = createRenderTask( designFile );
task.setRenderOption( options );
task.render( );
task.close( );
String content = new String( output.toByteArray( ) );
output.close( );
String regex = "<style type=\"text/css\">";
Matcher matcher = Pattern.compile( regex ).matcher( content );
assertEquals( false, matcher.find( ) );
regex = "<div[^<>]*style=\"[^<>]*color: rgb(255, 0, 0)[^<>]*>aaaa</div>";
matcher = Pattern.compile( regex ).matcher( content );
assertEquals( false, matcher.find( ) );
}
示例7
/**
*
* @throws EngineException
* @throws IOException
*/
public void testTableColumnWidth( ) throws EngineException, IOException
{
//the default cell to place the group icon is the first cell.
String designFile = "org/eclipse/birt/report/engine/emitter/html/TableColumnWidth.xml";
HTMLRenderOption options = new HTMLRenderOption( );
options.setLayoutPreference( "fixed" );
ByteArrayOutputStream output = new ByteArrayOutputStream( );
List instanceIDs = new ArrayList( );
options.setInstanceIDs( instanceIDs );
options.setOutputStream( output );
options.setEnableMetadata( true );
IRenderTask task = createRenderTask( designFile );
task.setRenderOption( options );
task.render( );
task.close( );
String content = new String( output.toByteArray( ) );
output.close( );
content = content.replaceAll( "\n", "\"\n\"+\\\\n" );
String regex = "table-layout:fixed";
Matcher matcher = Pattern.compile( regex ).matcher( content );
assertEquals( true, matcher.find( ) );
}
示例8
/**
* Test group icon will be displayed with group key even when the key is in a grid without query.
* @throws EngineException
* @throws IOException
*/
public void testDisplayGroupIconWithGroupKey( ) throws EngineException, IOException
{
String designFile = "org/eclipse/birt/report/engine/emitter/html/displayGroupIcon_Test1.xml";
//a. Test run and render task.
HTMLRenderOption options = new HTMLRenderOption( );
options.setDisplayGroupIcon( true );
String[] iconKeys = {"group key1 in data item",
"group key2 in grid without query", "group key3 in data item",
"group key4 with same expression"};
String content = getRenderResult( designFile, false, options ).content;
checkAllGroupIconDisplayed( options, content, iconKeys );
content = getRenderResult( designFile, true, options ).content;
checkAllGroupIconDisplayed( options, content, iconKeys );
}
示例9
public void testPerformanceOptimize( ) throws EngineException, IOException
{
HTMLRenderOption options = new HTMLRenderOption( );
options.setEnableAgentStyleEngine( true );
options.setEmbeddable( true );
ByteArrayOutputStream output = new ByteArrayOutputStream( );
List instanceIDs = new ArrayList( );
options.setInstanceIDs( instanceIDs );
options.setOutputStream( output );
//options.setEnableMetadata( true );
IRenderTask task = createRenderTask( designFile );
task.setRenderOption( options );
task.render( );
task.close( );
String content = new String( output.toByteArray( ) );
output.close( );
String regex = "text-decoration: underline;";
Matcher matcher = Pattern.compile( regex ).matcher( content );
assertEquals( true, matcher.find( ) );
regex = "<div style=\" text-decoration: underline;\">";
matcher = Pattern.compile( regex ).matcher( content );
assertEquals( false, matcher.find( ) );
}
示例10
public void testVisionOptimize( ) throws EngineException, IOException
{
HTMLRenderOption options = new HTMLRenderOption( );
options.setEnableAgentStyleEngine( false );
options.setEmbeddable( true );
ByteArrayOutputStream output = new ByteArrayOutputStream( );
List instanceIDs = new ArrayList( );
options.setInstanceIDs( instanceIDs );
options.setOutputStream( output );
//options.setEnableMetadata( true );
IRenderTask task = createRenderTask( designFile );
task.setRenderOption( options );
task.render( );
task.close( );
String content = new String( output.toByteArray( ) );
output.close( );
String regex = "<div style=\" text-decoration: underline;";
Matcher matcher = Pattern.compile( regex ).matcher( content );
assertEquals( true, matcher.find( ) );
}
示例11
protected String getReportTitle( IReportContent report )
{
// write the title of the report in HTML.
String title = null;
if ( report != null )
{
title = report.getTitle( );
}
if ( title == null )
{
// set the default title
if ( renderOption != null )
{
HTMLRenderOption htmlOption = new HTMLRenderOption( renderOption );
title = htmlOption.getHtmlTitle( );
}
}
return title;
}
示例12
/**
* Figures out the RTL rendering option.
*
* @param htmlOption
* @author bidi_hcg
*/
protected void retrieveRtLFlag( )
{
// If htmlOption has RTL_FLAG option set (likely adopted from an URL
// parameter), honor this option, otherwise obtain direction from
// the report design.
HTMLRenderOption htmlOption = new HTMLRenderOption( renderOption );
Object bidiFlag = htmlOption.getOption( IRenderOption.RTL_FLAG );
if ( Boolean.TRUE.equals( bidiFlag ) )
{
htmlRtLFlag = true;
}
else if ( bidiFlag == null && report != null)
{
ReportDesignHandle handle = report.getDesign( ).getReportDesign( );
if ( handle != null )
{
htmlRtLFlag = handle.isDirectionRTL( );
htmlOption.setHtmlRtLFlag( htmlRtLFlag ); // not necessary though
}
}
}
示例13
/**
* Run and render the report, and return the render result.
*
* @param designFile
* @return render result.
* @throws EngineException
* @throws IOException
*/
protected String runAndRender( String designFile ) throws EngineException,
IOException
{
IRunAndRenderTask runAndRenderTask = createRunAndRenderTask( designFile );
HTMLRenderOption options = new HTMLRenderOption( );
ByteArrayOutputStream out = new ByteArrayOutputStream( );
options.setOutputStream( out );
options.setOutputFormat( "html" );
options.setHtmlPagination( true );
runAndRenderTask.setRenderOption( options );
runAndRenderTask.run( );
runAndRenderTask.close( );
String result = new String( out.toByteArray( ) );
out.close( );
return result;
}
示例14
public void run( ) throws Exception
{
// render the generated report document
IReportDocument doc = engine.openReportDocument( fileName );
long pageCount = doc.getPageCount( );
for ( int i = 1; i <= pageCount; i++ )
{
IRenderTask renderTask = engine.createRenderTask( doc );
HTMLRenderOption option = new HTMLRenderOption( );
option.setOutputFormat( "html" );
option.setOutputStream( new ByteArrayOutputStream( ) );
renderTask.setRenderOption( option );
renderTask.setPageNumber( i );
renderTask.render( );
List errors = renderTask.getErrors( );
assertEquals( 0, errors.size( ) );
renderTask.close( );
}
doc.close( );
}
示例15
private void configEngine( )
{
HTMLRenderOption emitterConfig = new HTMLRenderOption( );
emitterConfig.setActionHandler( new HTMLActionHandler( ) {
public String getURL( IAction actionDefn, Object context )
{
if ( actionDefn.getType( ) == IAction.ACTION_DRILLTHROUGH )
return "birt://" //$NON-NLS-1$
+ URLEncoder.encode( super.getURL( actionDefn,
context ) );
return super.getURL( actionDefn, context );
}
} );
engineConfig.getEmitterConfigs( ).put( RenderOption.OUTPUT_FORMAT_HTML,
emitterConfig );
}
示例16
void doRenderAll( ) throws Exception
{
IReportDocument document = engine.openReportDocument( REPORT_DOCUMENT );
ByteArrayOutputStream out = new ByteArrayOutputStream( );
IRenderTask renderTask = engine.createRenderTask( document );
renderTask.getReportRunnable( ).setDesignHandle( reportHandle );
IRenderOption option = new HTMLRenderOption( );
option.setOutputFormat( HTMLRenderOption.OUTPUT_FORMAT_HTML );
option.setOutputStream( out );
renderTask.setRenderOption( option );
renderTask.render( );
assertTrue( renderTask.getErrors( ).isEmpty( ) );
renderTask.close( );
String pageContent = out.toString( "UTF-8" );
assertTrue( pageContent.indexOf( "reportlet_table" ) != -1 );
assertTrue( pageContent.indexOf( "SECOND-PAGE" ) != -1 );
document.close( );
}
示例17
void doRenderAll( ) throws Exception
{
IReportDocument document = engine.openReportDocument( REPORT_DOCUMENT );
ByteArrayOutputStream out = new ByteArrayOutputStream( );
IRenderTask renderTask = engine.createRenderTask( document );
IRenderOption option = new HTMLRenderOption( );
option.setOutputFormat( HTMLRenderOption.OUTPUT_FORMAT_HTML );
option.setOutputStream( out );
renderTask.setRenderOption( option );
renderTask.render( );
assertTrue( renderTask.getErrors( ).isEmpty( ) );
renderTask.close( );
String pageContent = out.toString( "UTF-8" );
assertTrue( pageContent.indexOf( "reportlet_table" ) != -1 );
assertTrue( pageContent.indexOf( "SECOND-PAGE" ) != -1 );
document.close( );
}
示例18
public void test90378( ) throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream( );
IRenderOption option = new HTMLRenderOption( );
option.setOutputFormat( "html" );
option.setOutputStream( out );
render( "org/eclipse/birt/report/engine/regression/90378.rptdesign",
option );
String report = out.toString( );
Pattern pattern = Pattern.compile( "<div>b1</div>" );
Matcher matcher = pattern.matcher( report );
int matches = 0;
while ( matcher.find( ) )
{
matches++;
}
assertEquals( 2, matches );
}
示例19
protected HTMLRenderOption prepareHtmlRenderOption(HttpServletRequest servletRequest) throws Exception {
boolean isBackEndRequest = isBackEndRequest(servletRequest);
if (isBackEndRequest) {
return prerareBackEndHtmlRenderOption();
} else {
return prepareFrontEndHtmlRenderOption();
}
}
示例20
/**
* Test IEmitterServices methods.
*
* @throws BirtException
*/
public void testIEmitterServices( ) throws BirtException
{
EngineConfig config = new EngineConfig( );
emitterConfig = new HTMLEmitterConfig( );
config.setEmitterConfiguration( EMITTER_HTML, emitterConfig );
emitterConfig = config.getEmitterConfigs( ).get( EMITTER_HTML );
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
IReportEngine reportEngine = factory.createReportEngine( config );
IReportRunnable reportRunnable = engine.openReportDesign( this
.genInputFile( report ) );
IRenderOption options = new HTMLRenderOption( );
options.setOutputFormat( EMITTER_HTML );
options.setOutputFileName( this.genOutputFile( "myService.html" ) );
HTMLRenderContext renderContext = new HTMLRenderContext( );
renderContext.setImageDirectory( "myImage" ); //$NON-NLS-1$
HashMap appContext = new HashMap( );
appContext.put(
EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
appContext.put( "emitter_class", this );
IRunAndRenderTask rrTask = reportEngine
.createRunAndRenderTask( reportRunnable );
rrTask.setRenderOption( options );
rrTask.setAppContext( appContext );
rrTask.run( );
rrTask.close( );
}
示例21
/**
* Test setEmbeddable(boolean embeddable) method Test getEmbeddable() method
*/
public void testGetEmbeddable( ) throws Exception
{
HTMLRenderOption option = new HTMLRenderOption( );
boolean bEmbed = true, bEmbedGet;
option.setEmbeddable( bEmbed );
bEmbedGet = option.getEmbeddable( );
assertEquals( "set/getEmbeddable() fail", bEmbed, bEmbedGet );
}
示例22
/**
* Test setUserAgent(java.lang.String userAgent) method Test getUserAgent()
* method
*/
public void testGetUserAgent( )
{
String agent = "agent", agentGet;
HTMLRenderOption option = new HTMLRenderOption( );
option.setUserAgent( agent );
agentGet = option.getUserAgent( );
assertEquals( "set/getUserAgent() fail", agent, agentGet );
}
示例23
/**
* Test setActionHandle(IHTMLActionHandler) method Test getActionHandle()
* method
*/
public void testGetActionHandle( )
{
HTMLActionHandler htmlAction = new HTMLActionHandler( );
HTMLRenderOption option = new HTMLRenderOption( );
option.setActionHandle( htmlAction );
assertNotNull( option.getActionHandle( ) );
}
示例24
/**
* Test setDisplayFilterIcon(boolean displayFilterIcon) method Test
* getDisplayFilterIcon() method
*/
public void testGetDisplayFilterIcon( )
{
HTMLRenderOption option = new HTMLRenderOption( );
option.setDisplayFilterIcon( true );
assertTrue( option.getDisplayFilterIcon( ) );
}
示例25
@Override
protected IRenderOption makeRenderOption() {
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat("html");
options.setHtmlPagination(true);
options.setEmbeddable(true);
options.setEnableInlineStyle(true);
return options;
}
示例26
/**
* Test setEnableMetadata(boolean enableMetadata) getEnableMetadata()
*/
public void testGetEnableMetadata( )
{
HTMLRenderOption option = new HTMLRenderOption( );
option.setEnableMetadata( false );
assertFalse( option.getEnableMetadata( ) );
}
示例27
/**
* Test setHtmlPagination(boolean pagination) getHtmlPagination()
*/
public void testGetHtmlPagination( )
{
HTMLRenderOption option = new HTMLRenderOption( );
option.setHtmlPagination( true );
assertTrue( option.getHtmlPagination( ) );
}
示例28
@Override
protected IRenderOption getRenderOptions(OutputStream output) {
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat("html");
options.setEmbeddable(false);
options.setHtmlPagination(false);
options.setOutputStream(output);
options.setImageHandler(getReportData().getIHTMLImageHandler());
return options;
}
示例29
private void createReportOutput( String reportDocumentFile,
String outputFolder ) throws EngineException, IOException
{
IReportDocument document = engine.openReportDocument( reportDocumentFile );
renderTask = engine.createRenderTask( document );
String outputFile = getOutputFileName( outputFolder,
new File( reportDesignFile ).getName( ),
targetFormat );
IRenderOption renderOption = new HTMLRenderOption( );
renderOption.setOutputFileName( outputFile );
renderOption.setOutputFormat( targetFormat );
try
{
renderTask.setRenderOption( renderOption );
configTask( renderTask );
renderTask.render( );
}
catch ( EngineException e )
{
throw e;
}
finally
{
renderTask.close( );
renderTask = null;
document.close( );
document = null;
}
}
示例30
/**
* Test setInstanceIDs (java.util.List instanceIDs) getInstanceIDs()
*/
public void testGetInstanceIDs( )
{
ArrayList ins = new ArrayList( );
HTMLRenderOption option = new HTMLRenderOption( );
option.setInstanceIDs( ins );
assertNotNull( option.getInstanceIDs( ) );
}