Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to Modify HTML Before Rendering
PKofon
I've built a custom viewer for BIRT and it's looking and working okay. However, there are instances in which I might want to modify the generated HTML before it gets written to disk. I use RunTask to run the report designs and then RenderTask for the rendering. For instance, I might want to embed additional info like a report's Author and Title as variables in a <script> tag in the generated HTML so I can display that information in a side-bar that's not part of the report using Javascript once the report loads. The only option I've thought of is to build a DOM of the generated HTML and then insert the <script> tag in body before writing it to disk. Not a good approach, especially as the report may be quite large.
Is there a simpler and cleaner way to do something like this using BIRT's API? Thanks.
Find more posts tagged with
Comments
johnw
<blockquote class='ipsBlockquote' data-author="'PKofon'" data-cid="69275" data-time="1286933983" data-date="12 October 2010 - 06:39 PM"><p>
I've built a custom viewer for BIRT and it's looking and working okay. However, there are instances in which I might want to modify the generated HTML before it gets written to disk. I use RunTask to run the report designs and then RenderTask for the rendering. For instance, I might want to embed additional info like a report's Author and Title as variables in a <script> tag in the generated HTML so I can display that information in a side-bar that's not part of the report using Javascript once the report loads. The only option I've thought of is to build a DOM of the generated HTML and then insert the <script> tag in body before writing it to disk. Not a good approach, especially as the report may be quite large.<br />
<br />
Is there a simpler and cleaner way to do something like this using BIRT's API? Thanks.<br /></p></blockquote>
<br />
There are a few options. Probably the most straightforward, especially since your using a custom viewer, is to extend or modify the HTML emitter to include that information. That will give you the most flexibility. You would just call it by a different extension (HTML2 or something), and set that to be your output format in the RenderTask.<br />
<br />
You could also do something similar where you write a script tag using a Text element set to HTML.<br />
<br />
John
PKofon
Hi John,
I'll attempt extending the HTML emitter as you've suggested. It should provide the most flexibility going forward. I figured something like that was required, although I was hoping for a less intrusive approach.
Anyway, I don't understand what you mean by "You could also do something similar where you write a script tag using a Text element set to HTML". Could you possibly explain this a little bit.
Thanks.
johnw
Basically, if you do something like in the beforeFactory or initialize event of the report, you could dynamically create a Text element, set the type to HTML, and include any HTML you wanted, including scripting. I do this often when I need to add interactivity to reports, such as row highlights on mouse overs. <br />
<br />
The draw back to this approach is that it will always add to the BODY section of the rendered HTML file, so you wont be able to add things like META tags. This would be a problem if you needed those tags to do things like index the result documents in a doc management system or search engine. Plus you would need to add that to every report.<br />
<br />
<blockquote class='ipsBlockquote' data-author="'PKofon'" data-cid="69312" data-time="1286987479" data-date="13 October 2010 - 09:31 AM"><p>
Hi John,<br />
I'll attempt extending the HTML emitter as you've suggested. It should provide the most flexibility going forward. I figured something like that was required, although I was hoping for a less intrusive approach.<br />
Anyway, I don't understand what you mean by "You could also do something similar where you write a script tag using a Text element set to HTML". Could you possibly explain this a little bit.<br />
Thanks.<br /></p></blockquote>
PKofon
Makes sense now. And I've got two solutions. Thanks.
PKofon
Makes sense now. You've given me two good solutions. Thanks.
PKofon
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="69328" data-time="1286996256" data-date="13 October 2010 - 11:57 AM"><p>
Basically, if you do something like in the beforeFactory or initialize event of the report, you could dynamically create a Text element, set the type to HTML, and include any HTML you wanted, including scripting. I do this often when I need to add interactivity to reports, such as row highlights on mouse overs. <br />
<br />
The draw back to this approach is that it will always add to the BODY section of the rendered HTML file, so you wont be able to add things like META tags. This would be a problem if you needed those tags to do things like index the result documents in a doc management system or search engine. Plus you would need to add that to every report.<br /></p></blockquote>
<br />
I couldn't figure out a way to extend the HTMLEmitter class and specify it as my preferred emitter. Maybe I have to look in BIRT's source code some more. Anyway, I found a quick solution to my problem. I set the output HTML as embeddable and before I render it, I write out my own HTML block consisting of a <script> tag. Nice and easy. Thanks for your help.