=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java 2010-04-27 05:35:16 +0000
@@ -45,11 +45,12 @@
* @author Tran Thanh Tri
* @version $Id$
*/
+@SuppressWarnings( "serial" )
public class ExportImageAction
extends StreamActionSupport
{
private static final Log log = LogFactory.getLog( ExportImageAction.class );
-
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -134,32 +135,49 @@
{
this.height = height;
}
-
+
+ private String imageFormat;
+
+ public void setImageFormat( String imageFormat )
+ {
+ this.imageFormat = imageFormat;
+ }
+
@Override
protected String execute( HttpServletResponse response, OutputStream out )
throws Exception
{
- log.info( "Exporting image, width: " + width + ", height: " + height );
-
- SVGUtils.convertToPNG( getSvg(), out, width, height );
-
+ log.info( "Exporting image, width: " + width + ", height: " + height + ", format: " + this.format );
+
+ if ( imageFormat.equalsIgnoreCase( "image/png" ) )
+ {
+
+ SVGUtils.convertToPNG( getSvg(), out, width, height );
+ }
+ else
+ {
+ SVGUtils.convertToJPEG( getSvg(), out, width, height );
+ }
+
return SUCCESS;
}
@Override
protected String getContentType()
{
- return "image/png";
+ return this.imageFormat;
}
@Override
protected String getFilename()
{
- return "dhis2-gis-image.png";
+ if ( imageFormat.equalsIgnoreCase( "image/png" ) )
+ return "dhis2-gis-image.png";
+ return "dhis2-gis-image.jpg";
}
private StringBuffer getSvg()
- {
+ {
Period p = periodService.getPeriod( period );
p.setName( format.formatPeriod( p ) );
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java 2010-04-27 05:35:16 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
@@ -34,13 +35,14 @@
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
+import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.image.PNGTranscoder;
/**
* @author Tran Thanh Tri
*/
public class SVGUtils
-{
+{
public static void convertToPNG( StringBuffer buffer, OutputStream out, Integer width, Integer height )
throws TranscoderException, IOException
{
@@ -48,21 +50,48 @@
{
width = 500;
}
-
+
if ( height == null || height < 10 )
{
height = 500;
}
-
+
PNGTranscoder t = new PNGTranscoder();
-
+
t.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( height ) );
- t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) );
-
- TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
-
- TranscoderOutput output = new TranscoderOutput( out );
-
+ t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) );
+
+ TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
+
+ TranscoderOutput output = new TranscoderOutput( out );
+
+ t.transcode( input, output );
+ }
+
+ public static void convertToJPEG( StringBuffer buffer, OutputStream out, Integer width, Integer height )
+ throws TranscoderException, IOException
+ {
+ if ( width == null || width < 10 )
+ {
+ width = 500;
+ }
+
+ if ( height == null || height < 10 )
+ {
+ height = 500;
+ }
+
+ JPEGTranscoder t = new JPEGTranscoder();
+
+ t.addTranscodingHint( JPEGTranscoder.KEY_HEIGHT, new Float( height ) );
+ t.addTranscodingHint( JPEGTranscoder.KEY_WIDTH, new Float( width ) );
+ t.addTranscodingHint( JPEGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE );
+ t.addTranscodingHint( JPEGTranscoder.KEY_QUALITY, new Float( .8 ) );
+
+ TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
+
+ TranscoderOutput output = new TranscoderOutput( out );
+
t.transcode( input, output );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html 2010-04-12 17:07:09 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html 2010-04-27 05:35:16 +0000
@@ -81,6 +81,7 @@
+