Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Adding Theme from library into a (DE) design file
b2tech
Hello:
I am having a problem with Themes. (2.3.1)
I open a pre-existing *.rptdesign with the DE: (no problem here)
[design = session.openDesign(xxxxTemplate[0]);]
I open my library file: (no problem here)
[LibraryHandle libhan = session.openLibrary("c:/xxxx.rptlibrary");]
I try to get a Theme from the now open library called "company_xyz" and apply it to the work-in-process design.
design.setProperty("theme", "company_xyz"); ???? (my problem is here)
The program will compile OK ( a .class file created) generating no errors but when I actually try to run it in my app I get the following:
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/css/sac/CSSException
at org.eclipse.birt.report.model.core.Module.loadCss(Module.java:2852)
at org.eclipse.birt.report.model.parser.IncludedCssStyleSheetListState$IncludedCssStructureState.end(IncludedCssStyleSheetListState.java:112)
at org.eclipse.birt.report.model.util.XMLParserHandler.endElement(XMLParserHandler.java:176)
... and many more
Any thoughts? Am I missing a class file?
What I am tying to accomplish is to have 10 Themes located in a library that are each hooked to a unique *.css file. A parameter coming into the java program is the name of the Theme with the linked CSS file evaluated at runtime. I am able to thus change the CSS file(s) at any time, re-run the report and pick up a new look and feel.
So basically what is the DE code that will generate this?:
<property name="theme">[library_name].company_xyz</property>
and
<list-property name="cssStyleSheets">
<structure>
<property name="fileName">c:/company_xyz.css</property>
</structure>
</list-property>
in my *.rptdesign file.
-- Bill
Find more posts tagged with
Comments
JasonW
Does the library that is used change? Or just the Theme used by the report? If only the theme changes, once you get the handle to the report design you should be able to just setProperty("theme",library.ThemeName);
Jason
JasonW
You should be able to add a library to the report design like:
PropertyHandle propHandle = designHandle
.getPropertyHandle( ReportDesign.LIBRARIES_PROP );
IncludedLibrary structure = StructureFactory.createIncludeLibrary( );
structure.setFileName( "a.xml" ); //$NON-NLS-1$
structure.setNamespace( "a" ); //$NON-NLS-1$
propHandle.addItem( structure );
b2tech
"If only the theme changes, once you get the handle to the report design you should be able to just setProperty("theme",library.ThemeName);"
Actually that is -exactly- what I tried doing and what -first appeared- to be generating the above java errors. After digging further, I noticed that when ANY library has a theme, and this theme HAS a css file attached, the CSS attachment causes the problem. The attaching of a css file to the theme and THEN using DE/java to create the report design seems to cause the problem. Take away any CSS links from themes in the library and all errors go away
Is working with themes unavailable in the DE (design engine) but only available in the report engine? Or is it possible that the DE is missing class files for dealing with linked css files. (which is not the case when I use the reporting engine)
The code below in the initialize step of a DE-created report design would allow me to change to a user supplied library theme using a passed in parameter:
var t;
theTheme = params["theme_name"].value;
t = reportContext.getReportRunnable().designHandle.getModuleHandle().findTheme(theTheme);
reportContext.getReportRunnable().designHandle.getModuleHandle().theme=t;
My problem is I can't get this far. I'm stuck at the creation of the design template that uses a library theme and the DE is throwing errors related to using CSS files.
-- Bill
JasonW
Bill,
You should be able to do anything in the API that the designer does. I could not reproduce the issue. I ran the program below and it worked correctly. My theme uses a css file in the resource folder and I do not have the view time check box checked.
package DEAPI;
import java.util.HashMap;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.ThemeHandle;
import org.eclipse.birt.report.model.api.elements.structures.IncludedLibrary;
import org.eclipse.birt.report.model.elements.ReportDesign;
import com.ibm.icu.util.ULocale;
public class ThemeFromLib {
public void runReport() throws EngineException
{
IReportEngine engine=null;
IDesignEngine dengine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_5_1\\birt-runtime-2_5_1\\ReportEngine");
config.setLogConfig(null, Level.FINE);
config.setResourcePath("C:\\work\\workspaces\\2.5.1workspaces\\BIRT -DE RE API Samples\\APIs\\resources\\");
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
DesignConfig dconfig = new DesignConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine");
IDesignEngineFactory dfactory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
dengine = dfactory.createDesignEngine( dconfig );
IReportRunnable design = null;
//Open the report design
SessionHandle session = dengine.newSessionHandle( ULocale.ENGLISH );
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle( );
report.includeLibrary("test.rptlibrary", "test");
report.setThemeName("test.NewTheme");
report.saveAs("reports/modifiedtopn.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", new Integer(3));
task.setParameterValue("Top Count", new Integer(5));
task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/desample/ModifiedTopNPercent.html");
options.setOutputFormat("html");
options.setImageDirectory("resample/images");
//options.setBaseImageURL(baseImageURL)
task.setRenderOption(options);
task.run();
task.close();
session.closeAll(false);
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
ThemeFromLib ex = new ThemeFromLib( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Jason
b2tech
Jason:
Thank you very much for your assistance but there is still something I am not clear on...
You open an existing report design with the Report Engine API ???
"engine = factory.createReportEngine( config );"
"design = engine.openReportDesign("Reports/TopNPercent.rptdesign");"
In my program I used the Design Engine API...
ie.
engine = factory.createDesignEngine( config );
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
design = session.openDesign("..\\templates\\portrait.rptdesign");
Is it correct that you have to use the Report Engine API when dealing with themes/CSS but use the Design Engine API for everything else (design related)?
In my case, I opened an (existing) report design with the Design Engine (DE) API. There was already a library in this file. I create grids etc. in this file with the DE (all fine up to this point). When I get to dealing with adding a library/theme from the Design Engine (DE) perspective, errors get generated.
In your scenario you opened an (existing) report design with the RE. I am not sure if your library was already contained within your existing report design file but I will assume it was not not. You then included an existing library, set your theme to newTheme, and then wrote out the modified report design with the modified theme.
report.includeLibrary("test.rptlibrary", "test");
report.setThemeName("test.NewTheme");
report.saveAs("reports/modifiedtopn.rptdesign");
Is that correct? Also you used 2.5.1 and I use 2.3.1. Was this supposed to work in 2.3.1?
-- Bill
sschafer2
FYI, CSSException is defined in org.w3c.css.sac_xxxx.jar in the BIRT runtime. I only have the runtime for 2.5.2 on my system but I think it's the same for 2.3.2.