dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03536
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1180: Made the ChartResult contentType configurable and have a default value image/png.
------------------------------------------------------------
revno: 1180
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-12-08 21:23:35 +0100
message:
Made the ChartResult contentType configurable and have a default value image/png.
modified:
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/ChartResult.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== 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();