Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to access image generated via velocity template? (Confluence)

diego diego July 13, 2011

Hi,

I have in macro class this code:

ChartUtilities.saveChartAsPNG(new File("myChart.png"), chart, 1000, 500, null, true, 0);
String chartImageName = chart.createChart();
context.put("chartImageName", chartImageName);

return VelocityUtils.getRenderedTemplate("template/chart_report_show.vm", context);

I dont know how I can access in Velocity Template to generated image show on web page.

Thanks for answers.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
diego diego July 26, 2011

Only second mentioned solution is available in my project, but how I get image file from memory in created servlet? I dont find any possible way how i can get it from request...

0 votes
Micha Kops
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2011

Depending on your user's target browser I could imagine the following two solutions:

1) Embed the image Base64 encoded in your HTML

e.g. <img alt="Your Chart" src="data:image/png;base64,sdafdsff23f..." />

Supported browsers - Wikipedia says:

Data URIs are currently supported by the following web browsers:

  • Gecko-based, such as Firefox, SeaMonkey, XeroBank, Camino, Fennec and K-Meleon
  • Konqueror, via KDE's KIO slaves input/output system
  • Opera (including devices such as the Nintendo DSi or Wii)
  • WebKit-based, such as Safari (including on iOS), Android's browser, Epiphany and Midori (WebKit is a derivative of Konqueror's KHTML engine, but Mac OS X does not share the KIO architecture so the implementations are different), and Webkit/Chromium-based, such as Chrome
  • Trident
  • Internet Explorer 8: Microsoft has limited its support to certain "non-navigable" content for security reasons, including concerns that JavaScript embedded in a data URI may not be interpretable by script filters such as those used by web-based email clients. Data URIs must be smaller than 32 KiB in Version 8.[3] Data URIs are supported only for the following elements and/or attributes
  • [..]

2) Create a parameterized servlet plugin to deliver your image

How to achieve this is documented in Atlassian's documentation: http://confluence.atlassian.com/display/CONFDEV/Servlet+Module

TAGS
AUG Leaders

Atlassian Community Events