Home
Analytics
Stylesheet in library and Report Engine API
cypherdj
Hi there,
I have setup various reports to use a library where I reference our web app stylesheet. Using the BIRT viewer, these are rendered appropriately, applying the relevant styles to the reports.
However, I've recently implemented my own servlet using the report engine API and although the library is referenced in the libraries list-property, it doesn't seem to apply the styles directly.
<list-property name="libraries">
<structure>
<property name="fileName">WEB-INF/config/envs/fineosenv/reports/showcaseDS.rptlibrary</property>
<property name="namespace">showcaseDS</property>
</structure>
<structure>
<property name="fileName">WEB-INF/config/envs/fineosenv/reports/showcaseStyles.rptlibrary</property>
<property name="namespace">showcaseStyles</property>
</structure>
</list-property>
Strangely, the other library, which declares the data sources required for all reports is being picked up correctly,
I found some code to get the library handle, and am able to get the theme object from the library handle, so I should be in a position to apply the styles at runtime, but I'm just wondering why this needs to be re-applied (considering the rptdesign file knows about the stylesheet),
Similarly, although the rptdesign file contains a chart, for which the output format is set to SVG, I also need to specify this at runtime using a call to HTMLRenderOption.setSupportedImageFormats("SVG"). Should this not be picked up directly from the rptdesign file?
Can someone shed some light on this please?
Kind regards,
Cedric Picard
Find more posts tagged with
Comments
cypherdj
Just to add some more info on this issue, the report is being displayed in an iframe. The source of this iframe is pointing to a servlet which runs and renders the report as follows:
String reportDesignName=context.getRequest().getParameter(REPORT_PARAM);
IReportRunnable reportDesign=reportEngine.openReportDesign(config.getServletContext().getRealPath("/WEB-INF/config/envs/fineosenv/reports") + "/" + reportDesignName);
//Create task to run and render the report,
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(reportDesign);
//Set parent classloader for engine
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ReportRenderer.class.getClassLoader());
//TODO Set parameter values and validate
//Setup rendering to HTML
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputStream(context.getResponse().getOutputStream());
options.setOutputFormat("html");
options.setEmbeddable(false);
options.setImageHandler(new HTMLServerImageHandler());
options.setSupportedImageFormats("SVG");
options.setImageDirectory(config.getServletContext().getRealPath("/images"));
options.setBaseImageURL(context.getRequest().getContextPath()+"/images");
task.setRenderOption(options);
//run and render report
task.run();
task.close();
cypherdj
I've carried on digging through this issue without success, but here's the latest on my findings, maybe this will give someone a better idea about what's going on and ultimately, fingers crossed, how to fix it! ;-)
I've now added the following code after opening the report design:
ReportDesignHandle designHandle = (ReportDesignHandle) reportDesign.getDesignHandle();
List<LibraryHandle> libList = designHandle.getAllLibraries();
if (!libList.isEmpty()){
Iterator<LibraryHandle> libItr = libList.iterator();
while (libItr.hasNext()){
LibraryHandle curLib = (LibraryHandle) libItr.next();
Iterator<IncludedCssStyleSheetHandle> cssItr = curLib.includeLibrariesIterator();
while (cssItr.hasNext()){
IncludedCssStyleSheetHandle curCss = (IncludedCssStyleSheetHandle) cssItr.next();
System.out.println("tStylesheet: " + curCss.getFileName());
}
SlotHandle theme = curLib.getThemes();
if (theme != null){
Iterator slotItr = theme.iterator();
while (slotItr.hasNext()){
DesignElementHandle curElement = (DesignElementHandle) slotItr.next();
System.out.println("tElement: " + curElement.getName());
}
}
}
}
I can see the relevant library, but this has an hasStyle attribute which is set to false, which might make sense since the stylesheet is actually in the theme. I then get the theme ok, but this has no elements whatsoever!
I'm at a complete loss on this one.
cypherdj
Ok, I eventually got this working, so here's how I got it done:
SessionHandle session = designEngine.newSessionHandle(ULocale.ENGLISH);
LibraryHandle styleLib = session.openLibrary(config.getServletContext().getRealPath("/WEB-INF/config/envs/fineosenv/reports") + "/showcaseStyles.rptlibrary");
ThemeHandle theme = styleLib.findTheme("defaultTheme");
Iterator<IncludedCssStyleSheetHandle> cssItr = theme.includeCssesIterator();
while (cssItr.hasNext()){
IncludedCssStyleSheetHandle curCss = (IncludedCssStyleSheetHandle) cssItr.next();
designHandle.addCss(config.getServletContext().getRealPath(curCss.getFileName()));
}
However, I still do not understand why I need to "manually" do this, since the report design uses the library, which in turns references the stylesheet. Is this a bug with the IRunAndRenderTask?
cjmaloof
After several hours of thrashing similar to the above, I found the right way to get my servlet to find a library:
engineConfig.setResourcePath("C:/mylibraries");
Not sure if this is actually the same problem, but there you go.