Community
Participate
Working Groups
I need to generate quite complex reports in XML format, therefore I wrote my own XML emitter. The XML tags are produced by a various range of elements, like Label, Data, Grid, Grid row, List, etc. Each XML tag must have a name and some other properties which the emitter needs to extract from the defined element in order to build the tag. In this scope I used the "User Properties" which I define in report at design time. In emmiter, the function which extracts the user properties (which have always String values) is quite simple: private String getUserProperties(IContent content) { StringBuffer result = new StringBuffer(); if (content.getUserProperties()!=null) { for (String key : content.getUserProperties().keySet()) { result.append(" "+key+"=\""+content.getUserProperties().get(key)+"\""); } } return result.toString(); } By executing the report in eclipse everything runs perfectly (the XML emitter runs as a plug-in). By executing the same report under BIRT Viewer (provided with the BIRT runtime) the content.getUserProperties() is always null. The same is happening in my own stand-alone application where I generate reports (on solaris). I tried to read the user properties also in some other ways, like: // get the object represented by IContent parameter Object myObject = report.getDesign().getReportDesign().getElementByID(content.getInstanceID().getComponentID()); --> this works fine if( myObject instanceof ReportItemHandle ) { ReportItemHandle myItemHandle = (ReportItemHandle)myObject; List<UserPropertyDefn> userProperties = myItemHandle.getUserProperties(); if (userProperties != null) { for (UserPropertyDefn property : userProperties) { .. and everything I try to do with the UserPropertyDefn object I get none of the defined user properties. So I repeat the important detail: The function above and other variations I tried run fine as long the report is executed under eclipse. I tried it under BIRT 4.3.1 and 4.4.2 with the same results.
I managed to find a way to solve my problem. However, the reported bug still exists and would be great to be solved. If you need to read User Properties at runtime, in my case inside an Emitter extending the ContentEmitterAdapter, here is the code which do the job: private String getUserProperty(IContent content, String propName) { DesignElementHandle myElementHandle = report.getDesign().getReportDesign() .getElementByID(content.getInstanceID().getComponentID()); DesignElement myElement = myElementHandle.getElement(); return myElement.getDisplayProperty(myElementHandle.getModule(), propName); } And if you don't know the property name and just want a list of them: List<UserPropertyDefn> userProperties = myElement.getLocalUserProperties(); if (userProperties != null) { for (UserPropertyDefn property : userProperties) { String propName = property.toString(); ... } } Maybe this is obvious for some experienced BIRT developers, but as long the IContent provides the getUserProperties() method, it was the obvious way for me, and as I explained before, it works, but only under certain circumstances. Possible that the myElementHandle can be extracted in a less complicated manner.