final Resource resource = resourceManager.createDirectly(reportUrl, MasterReport.class);
final MasterReport report = (MasterReport) resource.getResource();
report.setReportEnvironment(new SessionReportEnvironment(report.getReportEnvironment(), request.getSession()));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ZipRepository zipRepository = new ZipRepository(out);
final ContentLocation root = zipRepository.getRoot();
final ContentLocation data = RepositoryUtilities.createLocation
(zipRepository, RepositoryUtilities.splitPath("data", "/"));
final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor();
final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
printer.setContentWriter(root, new DefaultNameGenerator(root, "report.html"));
printer.setDataWriter(data, new DefaultNameGenerator(data, "content"));
String urlPattern = getInitParameter("url-pattern");
if (urlPattern == null)
{
final String requestURL = String.valueOf(request.getRequestURL());
final int parameterStart = requestURL.indexOf('?');
final String params = String.format("?report.name=%s&filename={0}",
URLEncoder.encode(report.getTitle(), request.getCharacterEncoding()));
if (parameterStart == -1)
{
urlPattern = requestURL + params;
}
else
{
urlPattern = requestURL.substring(0, parameterStart) + params;
}
}
printer.setUrlRewriter(new WebAppURLRewriter(urlPattern, request.getCharacterEncoding()));
outputProcessor.setPrinter(printer);
final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
sp.processReport();
sp.close();
zipRepository.close();
request.getSession().setAttribute("report:" + report.getTitle(), out.toByteArray());
return report.getTitle();
}