← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2044: Work in progress on GIS export to image

 

------------------------------------------------------------
revno: 2044
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Fri 2010-09-03 11:19:46 +0200
message:
  Work in progress on GIS export to image
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java
  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/export/SVGDocument.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.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-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java	2010-05-07 08:12:24 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java	2010-09-03 09:19:46 +0000
@@ -355,6 +355,6 @@
     @Override
     protected String getFilename()
     {
-        return "dhis2-gis-workbook.xls";
+        return "dhis2_gis.xls";
     }
 }

=== 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-05-07 08:12:24 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java	2010-09-03 09:19:46 +0000
@@ -139,90 +139,60 @@
         this.height = height;
     }
 
-    private String imageFormat;
-
-    public void setImageFormat( String imageFormat )
-    {
-        this.imageFormat = imageFormat;
-    }
-
     private SVGDocument svgDocument;
 
     @Override
     protected String execute( HttpServletResponse response, OutputStream out )
         throws Exception
     {
-
-        log.info( "Exporting image, width: " + svgDocument.getWidth() + ", height: " + svgDocument.getHeight()
-            + ", format: " + svgDocument.getImageFormat() );
-
-        if ( svgDocument.getImageFormat().equalsIgnoreCase( "image/png" ) )
-        {
-            SVGUtils.convertToPNG( svgDocument.getSVGForImage(), out, width, height );
-        }
-        else
-        {
-            SVGUtils.convertToJPEG( svgDocument.getSVGForImage(), out, width, height );
-        }
-
-        return SUCCESS;
-    }
-
-    @Override
-    protected String getContentType()
-    {
-        this.createSVGDocument();
-
-        return svgDocument.getImageFormat();
-    }
-
-    @Override
-    protected String getFilename()
-    {
-        this.createSVGDocument();
-
-        if ( svgDocument.getImageFormat().equalsIgnoreCase( "image/png" ) )
-            return "dhis2-gis-image.png";
-        return "dhis2-gis-image.jpg";
-    }
-
-    private void createSVGDocument()
-    {
-        if ( svg == null || title == null || imageFormat == null || indicator == null || period == null
-            || width == null || height == null )
+        log.info( "Exporting image, title: " + title + ", indicator: " + indicator + ", period" + period + ", width: " + width + ", height: " + height );
+        
+        log.info( "Legends: " + legends );
+        
+        if ( svg == null || title == null || indicator == null || period == null || width == null || height == null )
         {
             log.info( "Export map form session" );
 
             svgDocument = (SVGDocument) SessionUtils.getSessionVar( SVGDOCUMENT );
-
         }
         else
         {
-
             log.info( "Export map form request" );
 
-            Period p = periodService.getPeriod( period );
-
-            p.setName( format.formatPeriod( p ) );
-
-            Indicator i = indicatorService.getIndicator( indicator );
+            Period _period = periodService.getPeriod( period );
+
+            _period.setName( format.formatPeriod( _period ) );
+
+            Indicator _indicator = indicatorService.getIndicator( indicator );
 
             svgDocument = new SVGDocument();
 
-            svgDocument.setTitle( this.title );
-            svgDocument.setSvg( this.svg );
-            svgDocument.setIndicator( i );
-            svgDocument.setPeriod( p );
+            svgDocument.setTitle( title );
+            svgDocument.setSvg( svg );
+            svgDocument.setIndicator( _indicator );
+            svgDocument.setPeriod( _period );
             svgDocument.setLegends( legends );
             svgDocument.setIncludeLegends( includeLegends );
             svgDocument.setWidth( width );
             svgDocument.setHeight( height );
-            svgDocument.setImageFormat( imageFormat );
 
             SessionUtils.setSessionVar( SVGDOCUMENT, svgDocument );
-
         }
-
-    }
-
+        
+        SVGUtils.convertToPNG( svgDocument.getSVGForImage(), out, width, height );
+
+        return SUCCESS;
+    }
+
+    @Override
+    protected String getContentType()
+    {
+        return "image/png";
+    }
+
+    @Override
+    protected String getFilename()
+    {
+        return "dhis2_gis.png";
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java	2010-05-07 08:12:24 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java	2010-09-03 09:19:46 +0000
@@ -39,11 +39,11 @@
  */
 public class SVGDocument
 {
-    static final String doctype = "<?xml version='1.0' encoding='UTF-8'?>"
+    private static final String doctype = "<?xml version='1.0' encoding='UTF-8'?>"
         + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"; ["
         + "<!ATTLIST svg   xmlns:attrib CDATA #IMPLIED> <!ATTLIST path attrib:divname CDATA #IMPLIED>]>";
 
-    static final String namespace = "xmlns=\"http://www.w3.org/2000/svg\"; xmlns:xlink=\"http://www.w3.org/1999/xlink\"; xmlns:attrib=\"http://www.carto.net/attrib/\";  ";
+    private static final String namespace = "xmlns=\"http://www.w3.org/2000/svg\"; xmlns:xlink=\"http://www.w3.org/1999/xlink\"; xmlns:attrib=\"http://www.carto.net/attrib/\";  ";
 
     private String title;
 
@@ -61,8 +61,6 @@
 
     private int height;
 
-    private String imageFormat;
-
     public SVGDocument()
     {
     }
@@ -134,6 +132,9 @@
 
             String color = legend.getString( "color" );
 
+            System.out.println( "1 l " + label + " c " + color );
+            System.out.println( legend );
+            
             result += "<rect x='" + x + "' y='" + (y + 1) + "' height='1' width='1' fill='" + color
                 + "' stroke='#000000' stroke-width='0.001'/>";
 
@@ -168,6 +169,9 @@
 
             String color = legend.getString( "color" );
 
+            System.out.println( "1 l " + label + " c " + color );
+            System.out.println( legend );
+            
             result += "<rect x='" + x + "' y='" + (y + 15) + "' height='15' width='30' fill='" + color
                 + "' stroke='#000000' stroke-width='1'/>";
 
@@ -182,6 +186,12 @@
         return result;
     }
 
+    @Override
+    public String toString()
+    {
+        return svg;
+    }
+    
     public boolean isIncludeLegends()
     {
         return includeLegends;
@@ -262,20 +272,4 @@
     {
         this.height = height;
     }
-
-    public String getImageFormat()
-    {
-        return imageFormat;
-    }
-
-    public void setImageFormat( String imageFormat )
-    {
-        this.imageFormat = imageFormat;
-    }
-
-    @Override
-    public String toString()
-    {
-        return this.svg;
-    }
 }

=== 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-27 05:35:16 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGUtils.java	2010-09-03 09:19:46 +0000
@@ -59,7 +59,8 @@
         PNGTranscoder t = new PNGTranscoder();
 
         t.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( height ) );
-        t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) );        
+        t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) );
+        t.addTranscodingHint( JPEGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE );
 
         TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
 
@@ -86,7 +87,6 @@
         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() ) );