Java Examples for org.eclipse.birt.report.engine.api.IRenderOption
The following java examples will help you to understand the usage of org.eclipse.birt.report.engine.api.IRenderOption. These source code samples are taken from different open source projects.
Example 1
| Project: spring-birt-master File: HtmlSingleFormatBirtView.java View source code |
@Override
protected RenderOption renderReport(Map<String, Object> modelData, HttpServletRequest request, HttpServletResponse response, BirtViewResourcePathCallback resourcePathCallback, Map<String, Object> appContextValuesMap, String reportName, String format, IRenderOption options) throws Throwable {
ServletContext sc = request.getServletContext();
HTMLRenderOption htmlOptions = new HTMLRenderOption(options);
htmlOptions.setOutputFormat("html");
htmlOptions.setOutputStream(response.getOutputStream());
htmlOptions.setImageHandler(new HTMLServerImageHandler());
htmlOptions.setBaseImageURL(birtViewResourcePathCallback.baseImageUrl(sc, request, reportName));
htmlOptions.setImageDirectory(birtViewResourcePathCallback.imageDirectory(sc, request, reportName));
htmlOptions.setBaseURL(birtViewResourcePathCallback.baseUrl(sc, request, reportName));
return htmlOptions;
}Example 2
| Project: org.eclipse.birt.report.engine-master File: ExecutionContext.java View source code |
public String getOutputFormat() {
String outputFormat = null;
if (renderOption != null) {
outputFormat = renderOption.getOutputFormat();
}
if (outputFormat == null) {
if (isFixedLayout()) {
outputFormat = IRenderOption.OUTPUT_FORMAT_PDF;
} else {
outputFormat = IRenderOption.OUTPUT_FORMAT_HTML;
}
}
return outputFormat;
}Example 3
| Project: report-cockpit-birt-web-master File: BirtReportServiceBean.java View source code |
@Override
public void renderHtmlReport(final String reportName, Map<String, Object> parameters, OutputStream out) throws BirtReportException {
try {
IRunAndRenderTask runAndRenderTask = createRunAndRenderTask(reportName);
injectParameters(parameters, runAndRenderTask);
injectLocale(runAndRenderTask);
HTMLRenderOption htmlOptions = new HTMLRenderOption();
htmlOptions.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML);
htmlOptions.setOutputStream(out);
htmlOptions.setImageHandler(new HTMLServerImageHandler());
htmlOptions.setEmbeddable(true);
htmlOptions.setBaseImageURL(baseImageURL);
htmlOptions.setImageDirectory(imageDirectory);
htmlOptions.setHtmlPagination(true);
htmlOptions.setMasterPageContent(true);
htmlOptions.setPageFooterFloatFlag(true);
runAndRenderTask.setPageHandler(new IPageHandler() {
@Override
public void onPage(int pageNumber, boolean checkpoint, IReportDocumentInfo doc) {
logger.info("Number: {} ({})", pageNumber, checkpoint);
try {
if (doc != null) {
IReportDocument reportDocument = doc.openReportDocument();
logger.info(reportDocument.toString());
}
} catch (BirtException e) {
logger.error("Error while trying to render html report of {}", reportName);
logger.error(e.getMessage(), e);
}
}
});
runAndRenderTask(runAndRenderTask, htmlOptions);
} catch (EngineExceptionIOException | e) {
throw new RenderReportException("html", reportName, e);
}
}Example 4
| Project: bi-platform-v2-master File: BirtSystemListener.java View source code |
/*
* Create an instance of the EngineConfig class for the BIRT report engine.
*/
private IReportEngine createBIRTEngine() {
try {
// Get the global settings for the BIRT engine from our system settings
//$NON-NLS-1$
String birtHome = PentahoSystem.getApplicationContext().getSolutionPath("system/BIRT");
//$NON-NLS-1$ //$NON-NLS-2$
birtHome = birtHome.replaceAll("\\\\.\\\\", "\\\\");
//$NON-NLS-1$
String birtResourcePath = PentahoSystem.getApplicationContext().getSolutionPath("system/BIRT/resources");
//$NON-NLS-1$//$NON-NLS-2$
birtResourcePath = birtResourcePath.replaceAll("\\\\.\\\\", "\\\\");
if (PentahoSystem.debug) {
//$NON-NLS-1$
Logger.debug(BirtSystemListener.class.getName(), Messages.getInstance().getString("BIRT.DEBUG_BIRT_HOME", birtHome));
}
// Create an appropriate Config object
EngineConfig config = new EngineConfig();
// Configuring where BIRT engine is installed
config.setEngineHome(birtHome);
config.setResourcePath(birtResourcePath);
// Set the directory where the BIRT log files will go
//$NON-NLS-1$
String logDest = PentahoSystem.getApplicationContext().getFileOutputPath("system/logs/BIRT");
//$NON-NLS-1$
logDest = "";
// Set the logging level
int loggingLevel = Logger.getLogLevel();
if (loggingLevel == ILogger.TRACE) {
config.setLogConfig(logDest, Level.ALL);
} else if (loggingLevel == ILogger.DEBUG) {
config.setLogConfig(logDest, Level.FINE);
} else if (loggingLevel == ILogger.INFO) {
config.setLogConfig(logDest, Level.INFO);
} else if (loggingLevel == ILogger.WARN) {
config.setLogConfig(logDest, Level.WARNING);
} else if (loggingLevel == ILogger.ERROR) {
config.setLogConfig(logDest, Level.SEVERE);
} else if (loggingLevel == ILogger.FATAL) {
config.setLogConfig(logDest, Level.SEVERE);
}
// Register new image handler
// Bart Maertens, 14/11/2007: Replace HTMLEmitterConfig with HTMLRenderOption.
// HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig();
// emitterConfig.setActionHandler(new HTMLActionHandler());
// emitterConfig.setImageHandler(new HTMLServerImageHandler());
// config.getEmitterConfigs().put(RenderOptionBase.OUTPUT_FORMAT_HTML, emitterConfig);
IRenderOption option = new RenderOption();
//$NON-NLS-1$
option.setOutputFormat("html");
HTMLRenderOption renderOption = new HTMLRenderOption(option);
renderOption.setImageDirectory(imageDirectory);
config.getEmitterConfigs().put(IRenderOption.OUTPUT_FORMAT_HTML, renderOption);
// Workaround for Eclipse bug 156877
//$NON-NLS-1$
String protocolHandler = System.getProperty("java.protocol.handler.pkgs");
if ((protocolHandler != null) && (protocolHandler.indexOf("org.jboss.net.protocol") != -1)) {
//$NON-NLS-1$
//$NON-NLS-1$
StringTokenizer tok = new StringTokenizer(protocolHandler, "|");
StringBuffer newProtocolHandler = new StringBuffer();
String name;
while (tok.hasMoreElements()) {
name = tok.nextToken();
if (!name.equals("org.jboss.net.protocol")) {
//$NON-NLS-1$
newProtocolHandler.append(name).append('|');
}
}
// chop the last '|'
newProtocolHandler.setLength(Math.max(0, newProtocolHandler.length() - 1));
BirtSystemListener.workaroundProtocolHandler = System.setProperty("java.protocol.handler.pkgs", //$NON-NLS-1$
newProtocolHandler.toString());
}
// End Workaround
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
IReportEngine engine = factory.createReportEngine(config);
return engine;
} catch (BirtException be) {
BirtSystemListener.logger.error(null, be);
Logger.error(BirtSystemListener.class.getName(), Messages.getInstance().getErrorString("BIRT.ERROR_0008_INVALID_CONFIGURATION"));
}
return null;
}Example 5
| Project: kraken-master File: ReportPrintMachineBIRT.java View source code |
@Override
public boolean print(InputStream istream, Map<String, Object> reportParameters, BirtReportOutputType outputType, OutputStream outputStream, IResourceLocator resourceLocator) {
IRenderOption option;
switch(outputType) {
case DOC:
option = new PDFRenderOption();
option.setOutputFormat("doc");
break;
case PDF:
option = new PDFRenderOption();
option.setOutputFormat("pdf");
break;
default:
System.err.println("Not supported output type.");
return false;
}
option.setOutputStream(outputStream);
option.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
System.setProperty("java.awt.headless", "true");
boolean result;
try {
synchronized (this) {
IReportRunnable report;
if (resourceLocator != null) {
report = engine.openReportDesign(null, istream, resourceLocator);
} else
report = engine.openReportDesign(istream);
IRunAndRenderTask task = engine.createRunAndRenderTask(report);
if (task == null)
throw new IllegalStateException("task is null. check if engine libraries are installed in data/kraken-birt/engine");
task.setRenderOption(option);
task.setParameterValues(reportParameters);
if (task.getParameterValue(DATA_SRC_NAME) == null) {
task.setParameterValue(DATA_SRC_NAME, new File(homeDir, DATA_SRC).getAbsolutePath());
}
task.run();
task.close();
result = true;
}
} catch (EngineException e) {
e.printStackTrace();
result = false;
} finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}Example 6
| Project: Orienteer-master File: AbstractBirtReportPanel.java View source code |
private void updateReportOut() throws EngineException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
IReportDocument cache = getReportCache();
IRenderTask renderTask = getReportEngine().createRenderTask(cache);
IRenderOption options = makeRenderOption();
renderTask.setRenderOption(options);
//renderTask.setPageRange("1-5");
renderTask.setPageNumber(currentPage + 1);
options.setOutputStream(buf);
//run the report
renderTask.render();
cache.close();
Object out;
try {
out = buf.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
out = buf.toString();
}
get(REPORT_COMPONENT_NAME).setDefaultModelObject(out);
}Example 7
| Project: OpenReports-master File: BirtReportEngine.java View source code |
/**
* Generates a report from a BIRT report design.
*/
@SuppressWarnings("unchecked")
@Override
public ReportEngineOutput generateReport(ReportEngineInput input) throws ProviderException {
Report report = input.getReport();
Map<String, Object> parameters = input.getParameters();
ReportEngineOutput output = new ReportEngineOutput();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IReportEngine engine = BirtProvider.getBirtEngine(directoryProvider.getReportDirectory() + "platform");
// Set options for task
HTMLRenderOption renderOption = new HTMLRenderOption();
renderOption.setOutputStream(out);
renderOption.setImageDirectory(directoryProvider.getTempDirectory());
renderOption.setBaseImageURL("report-images");
try {
String designFile = directoryProvider.getReportDirectory() + report.getFile();
log.info("Loading BIRT report design: " + report.getFile());
IReportRunnable design = engine.openReportDesign(designFile);
handleDataSourceOverrides(design);
if (input.getExportType() == ExportType.PDF) {
output.setContentType(ReportEngineOutput.CONTENT_TYPE_PDF);
renderOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_PDF);
} else if (input.getExportType() == ExportType.HTML || input.getExportType() == ExportType.HTML_EMBEDDED) {
output.setContentType(ReportEngineOutput.CONTENT_TYPE_HTML);
renderOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML);
if (input.getExportType() == ExportType.HTML_EMBEDDED) {
renderOption.setEmbeddable(true);
}
} else if (input.getExportType() == ExportType.XLS) {
output.setContentType(ReportEngineOutput.CONTENT_TYPE_XLS);
renderOption.setOutputFormat("xls");
} else {
log.error("Export type not yet implemented: " + input.getExportType());
}
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setRenderOption(renderOption);
task.setParameterValues(parameters);
task.validateParameters();
if (input.getLocale() != null) {
task.setLocale(input.getLocale());
}
if (input.getXmlInput() != null) {
ByteArrayInputStream stream = new ByteArrayInputStream(input.getXmlInput().getBytes());
task.getAppContext().put("org.eclipse.datatools.enablement.oda.xml.inputStream", stream);
}
log.info("Generating BIRT report: " + report.getName());
task.run();
task.close();
log.info("Finished Generating BIRT report: " + report.getName());
output.setContent(out.toByteArray());
} catch (Throwable e) {
log.error("generateReport Exception", e);
throw new ProviderException(e.toString());
}
return output;
}Example 8
| Project: online-whatif-master File: BirtController.java View source code |
/**
* Generates suitability scenario csv report
*
* @param response
* @param id
* @return
* @throws WifInvalidInputException
* @throws WifInvalidConfigException
* @throws ParsingException
* @throws IOException
*/
@RequestMapping(method = RequestMethod.GET, value = "/{projectId}/suitabilityScenarios/{id}/csv")
@ResponseBody
public byte[] getCSV(final HttpServletResponse response, @PathVariable("id") final String id) throws WifInvalidInputException, WifInvalidConfigException, ParsingException, IOException {
byte[] bytem = null;
LOGGER.info("*******>> getBirt Report csv for Suitability Scenario id ={}", id);
final SuitabilityScenario suitabilityScenario = suitabilityScenarioService.getSuitabilityScenario(id);
List<suitabilityFactorReport> listOut = new ArrayList<suitabilityFactorReport>();
listOut = reportService.getSuitabilityCSVAnalysisReport(suitabilityScenario);
BirtReport = new BirtReport();
if (listOut.size() > 0) {
BirtReport.setProjectName(listOut.get(0).getProjectName());
BirtReport.setScenarioName(listOut.get(0).getScenarioLabel());
}
StringBuilder str = new StringBuilder("<property name='data'><list>");
for (final suitabilityFactorReport sr : listOut) {
String lname = sr.getLUName();
lname = lname.replaceAll(",", "");
//lname = lname.replaceAll("/", "");
lname = lname.replaceAll(">", "'Greater");
lname = lname.replaceAll("<", "'Lower");
String lfname = sr.getFactorName();
lfname = lfname.replaceAll(",", "");
//lfname = lfname.replaceAll("/", "");
lfname = lfname.replaceAll(">", "'Greater ");
lfname = lfname.replaceAll("<", "'Lower ");
str.append("<list>");
str.append("<value>");
str.append(lname);
str.append("</value>");
str.append("<value>");
str.append(lfname);
str.append("</value>");
str.append("<value>");
str.append(sr.getFatorValue());
str.append("</value>");
str = str.append("</list>");
}
str = str.append("</list>");
str = str.append("</property>");
// ///////////////
final String tempDir = System.getProperty("java.io.tmpdir");
final File filexml = new File(tempDir + "/xfact.xml");
if (!filexml.exists()) {
filexml.createNewFile();
}
final FileWriter fwxml = new FileWriter(tempDir + "/xfact.xml");
// FileWriter fwxml = new FileWriter("/Users/ashamakhy/Documents/ali.xml");
final BufferedWriter bufferWritterxml = new BufferedWriter(fwxml);
String strxml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<beans xmlns='http://www.springframework.org/schema/beans'\n" + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:tx='http://www.springframework.org/schema/tx'\n" + "xmlns:context='http://www.springframework.org/schema/context'\n" + "xmlns:task='http://www.springframework.org/schema/task'\n" + "xsi:schemaLocation='\n" + "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd\n" + "http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd\n" + "http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd\n" + "http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd'>\n";
// + "<context:component-scan base-package='au.org.aurin.wif' />\n";
bufferWritterxml.write(strxml);
strxml = "<bean id='BirtReport' class='au.org.aurin.wif.model.reports.BirtReport'>" + "<property name='scenarioName' value='" + BirtReport.getScenarioName() + "' />" + "<property name='projectName' value='" + BirtReport.getProjectName() + "' />" + str + "</bean>\n</beans>";
bufferWritterxml.write(strxml);
bufferWritterxml.close();
fwxml.close();
final ApplicationContext context = new FileSystemXmlApplicationContext("/" + filexml.getPath());
// ///////////////birt
// String mystr = "";
IReportEngine birtEngine = null;
try {
final EngineConfig config = new EngineConfig();
// System.out.println(servletContext.getBean("BirtReport").toString());
final BirtReport cc = (au.org.aurin.wif.model.reports.BirtReport) context.getBean("BirtReport");
// ArrayList<String[]> data = cc.getData();
config.getAppContext().put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, context);
Platform.startup(config);
final IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtEngine = factory.createReportEngine(config);
final URL peopleresource = getClass().getResource(// SpringSampleBIRTViewer.rptdesign
"/suitabilityfactor.rptdesign");
IReportRunnable runnable = null;
runnable = birtEngine.openReportDesign(peopleresource.getFile());
final IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(runnable);
final File file = new File(tempDir + "/xfact.xls");
if (!file.exists()) {
file.createNewFile();
}
final EXCELRenderOption xlsOptions = new EXCELRenderOption();
xlsOptions.setOutputFormat("xls");
xlsOptions.setOutputFileName(tempDir + "/xfact.xls");
xlsOptions.setOption(IExcelRenderOption.OFFICE_VERSION, "office2007");
//xlsOptions.setOption(IExcelRenderOption.EMITTER_ID, "org.eclipse.birt.report.engine.emitter.prototype.excel");
xlsOptions.setOption(IRenderOption.EMITTER_ID, "org.eclipse.birt.report.engine.emitter.prototype.excel");
//xlsOptions.setOption(IRenderOption.EMITTER_ID, "org.uguess.birt.report.engine.emitter.xls");
// xlsOptions.setOption(IRenderOption.EMITTER_ID,"org.eclipse.birt.report.engine.emitter.nativexls");
xlsOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, IPDFRenderOption.FIT_TO_PAGE_SIZE);
// pdfOptions.setOutputStream(response.getOutputStream());
runAndRenderTask.setRenderOption(xlsOptions);
runAndRenderTask.run();
runAndRenderTask.close();
filexml.delete();
bytem = org.springframework.util.FileCopyUtils.copyToByteArray(file);
response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
response.setContentLength(bytem.length);
response.setContentType("application/xls");
file.delete();
LOGGER.info("*******>> Completed Birt Report csv for Suitability Scenario id ={}", id);
} catch (final Exception e) {
LOGGER.debug("getBirt factor csv Report error : ={}", e.toString());
} finally {
birtEngine.destroy();
}
return bytem;
}Example 9
| Project: tourismwork-master File: BirtReportEngine.java View source code |
/**
* Generates a report from a BIRT report design.
*/
@SuppressWarnings("unchecked")
@Override
public ReportEngineOutput generateReport(ReportEngineInput input) throws ProviderException {
Report report = input.getReport();
Map<String, Object> parameters = input.getParameters();
ReportEngineOutput output = new ReportEngineOutput();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IReportEngine engine = BirtProvider.getBirtEngine(directoryProvider.getReportDirectory() + "platform");
// Set options for task
HTMLRenderOption renderOption = new HTMLRenderOption();
renderOption.setOutputStream(out);
renderOption.setImageDirectory(directoryProvider.getTempDirectory());
renderOption.setBaseImageURL("report-images");
try {
String designFile = directoryProvider.getReportDirectory() + report.getFile();
log.info("Loading BIRT report design: " + report.getFile());
IReportRunnable design = engine.openReportDesign(designFile);
handleDataSourceOverrides(design);
if (input.getExportType() == ExportType.PDF) {
output.setContentType(ReportEngineOutput.CONTENT_TYPE_PDF);
renderOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_PDF);
} else if (input.getExportType() == ExportType.HTML || input.getExportType() == ExportType.HTML_EMBEDDED) {
output.setContentType(ReportEngineOutput.CONTENT_TYPE_HTML);
renderOption.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML);
if (input.getExportType() == ExportType.HTML_EMBEDDED) {
renderOption.setEmbeddable(true);
}
} else if (input.getExportType() == ExportType.XLS) {
output.setContentType(ReportEngineOutput.CONTENT_TYPE_XLS);
renderOption.setOutputFormat("xls");
} else {
log.error("Export type not yet implemented: " + input.getExportType());
}
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setRenderOption(renderOption);
task.setParameterValues(parameters);
task.validateParameters();
if (input.getLocale() != null) {
task.setLocale(input.getLocale());
}
if (input.getXmlInput() != null) {
ByteArrayInputStream stream = new ByteArrayInputStream(input.getXmlInput().getBytes());
task.getAppContext().put("org.eclipse.datatools.enablement.oda.xml.inputStream", stream);
}
log.info("Generating BIRT report: " + report.getName());
task.run();
task.close();
log.info("Finished Generating BIRT report: " + report.getName());
output.setContent(out.toByteArray());
} catch (Throwable e) {
log.error("generateReport Exception", e);
throw new ProviderException(e.toString());
}
return output;
}