Martin, thank you for your reply. Your suggestion helped. If it can help
others, here's what I did to integrate a BIRT report into a Wicket Panel as
html:
private class ReportPanel extends Panel implements
IMarkupResourceStreamProvider, IMarkupCacheKeyProvider
{
private static final long serialVersionUID = - 8538589085021403531L;
private static final String BIRT_REPORTS_LOCATION = "your location here";
private static final String BIRT_LOGS_LOCATION = "your location here";
private final String reportName;
public ReportPanel(String id, String reportName)
{
super(id);
this.reportName = reportName;
}
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer container,
Class<?> containerClass)
{
StringBuilder buf = new StringBuilder();
buf.append("<wicket:panel wicket:id='reportPanel'>");
try
{
final String reportPath = BIRT_REPORTS_LOCATION + reportName + ".rptdesign";
final EngineConfig config = new EngineConfig();
config.setLogConfig(BIRT_LOGS_LOCATION, Level.FINE);
// No need to optimize this to happen only once, because the Platform will
only initialize itself once.
Platform.startup(config);
final IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
final IReportEngine engine = factory.createReportEngine(config);
final IReportRunnable report = engine.openReportDesign(reportPath);
final IRunAndRenderTask task = engine.createRunAndRenderTask(report);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML);
options.setEmbeddable(true);
options.setOutputStream(out);
task.setRenderOption(options);
task.run();
task.close();
buf.append(new String(out.toByteArray()));
}
catch (final Exception e)
{
buf.append(new String(e.getMessage()));
}
buf.append("</wicket:panel>");
return new StringResourceStream(buf.toString());
}
@Override
public String getCacheKey(MarkupContainer container, Class<?>
containerClass)
{
// Must return null so that the markup isn't cached.
return null;
}
}
Julian
On Fri, Jul 8, 2011 at 1:37 AM, Martin Grigorov <[email protected]>wrote:
> See org.apache.wicket.markup.IMarkupResourceStreamProvider
>
> public class BirtReport extends WebMarkupContainer implements
> IMarkupResourceStreamProvider {
>
> public IResourceStream getMarkupResourceStream(final
> MarkupContainer container, Class<?> containerClass) {
>
> // do your BIRT logic here
> return new AnyIResourceStreamThatFitsYourNeeds(birtResult)
> }
> }
>
> On Fri, Jul 8, 2011 at 4:21 AM, Julian Sinai <[email protected]> wrote:
> > I am using the BIRT Report Engine API. It generates html that I want to
> > display in a Panel or a WebMarkupContainer. The API requires me to hand
> it a
> > java.io.OutputStream, which it then writes to. How do I obtain a stream
> from
> > Wicket in a way that the BIRT output can be inserted in my Panel?
> >
> > Any help is appreciated.
> > Julian
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>