=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java 2009-08-20 08:17:49 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java 2009-12-08 20:23:35 +0000 @@ -35,11 +35,15 @@ public class ChartResult implements Result { + private static final String DEFAULT_CONTENT_TYPE = "image/png"; + private JFreeChart chart = null; private Integer height; private Integer width; + + private String contentType; /** * Sets the JFreeChart to use. @@ -70,6 +74,16 @@ { this.width = width; } + + /** + * Sets the content type. + * + * @param contentType the content type. + */ + public void setContentType( String contentType ) + { + this.contentType = contentType; + } /** * Executes the result. Writes the given chart as a PNG to the servlet @@ -94,6 +108,10 @@ width = stackWidth != null && stackWidth > 0 ? stackWidth : width; + String stackContentType = invocation.getStack().findString( "contentType" ); + + contentType = stackContentType != null && !stackContentType.trim().isEmpty() ? stackContentType : contentType; + if ( chart == null ) { throw new NullPointerException( "No chart found" ); @@ -109,7 +127,13 @@ throw new IllegalArgumentException( "Width not set" ); } + if ( contentType == null ) + { + contentType = DEFAULT_CONTENT_TYPE; + } + HttpServletResponse response = ServletActionContext.getResponse(); + response.setContentType( contentType ); OutputStream os = response.getOutputStream(); ChartUtilities.writeChartAsPNG( os, chart, width, height ); os.flush();