=== 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 2013-04-04 18:06:19 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java 2013-04-17 16:01:35 +0000 @@ -40,6 +40,7 @@ import org.apache.batik.transcoder.image.PNGTranscoder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.svg.PDFTranscoder; import org.hisp.dhis.system.util.CodecUtils; import org.hisp.dhis.util.ContextUtils; import org.hisp.dhis.util.StreamActionSupport; @@ -54,34 +55,56 @@ { private static final Log log = LogFactory.getLog( ExportImageAction.class ); + private static final String TYPE_PNG = "png"; + + private static final String TYPE_PDF = "pdf"; + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- + private String title; + + public void setTitle( String title ) + { + this.title = title; + } + private String svg; public void setSvg( String svg ) { this.svg = svg; } - - private String title; - - public void setTitle( String title ) + + private String type; + + public void setType( String type ) { - this.title = title; + this.type = type; } @Override protected String execute( HttpServletResponse response, OutputStream out ) throws Exception { - if ( svg == null ) + if ( svg != null ) { - log.info( "Error: SVG is empty" ); + if ( type == null || TYPE_PNG.equals( type ) ) + { + convertToPNG( new StringBuffer( this.svg ), out ); + } + else if ( TYPE_PDF.equals( type ) ) + { + convertToPDF( new StringBuffer( this.svg ), out ); + } } + else + { + log.info( "svg = " + svg + ", type = " + type ); - convertToPNG( new StringBuffer( this.svg ), out ); + return NONE; + } return SUCCESS; } @@ -95,7 +118,7 @@ @Override protected String getFilename() { - return "dhis2-gis_" + CodecUtils.filenameEncode( this.title ) + ".png"; + return "dhis2_map_" + CodecUtils.filenameEncode( this.title ) + "." + CodecUtils.filenameEncode( type ); } public void convertToPNG( StringBuffer buffer, OutputStream out ) @@ -112,6 +135,18 @@ t.transcode( input, output ); } + public void convertToPDF( StringBuffer buffer, OutputStream out ) + throws TranscoderException + { + PDFTranscoder t = new PDFTranscoder(); + + TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) ); + + TranscoderOutput output = new TranscoderOutput( out ); + + t.transcode( input, output ); + } + @Override protected boolean disallowCache() { === modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html' --- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html 2013-04-16 17:47:28 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html 2013-04-17 16:01:35 +0000 @@ -14,8 +14,9 @@
+ + -