← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5182: Export cleanup. SVGDocument and SVGUtils removed.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 5182 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-11-17 16:16:18 +0000
message:
  Export cleanup. SVGDocument and SVGUtils removed.
removed:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGDocument.java
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java
modified:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html


--
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-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java	2011-11-17 14:53:18 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java	2011-11-17 16:13:19 +0000
@@ -31,15 +31,22 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.visualizer.export.SVGDocument;
-import org.hisp.dhis.visualizer.export.SVGUtils;
 import org.hisp.dhis.system.util.CodecUtils;
 import org.hisp.dhis.util.ContextUtils;
-import org.hisp.dhis.util.SessionUtils;
 import org.hisp.dhis.util.StreamActionSupport;
 
 import javax.servlet.http.HttpServletResponse;
 
+import java.awt.Color;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.apache.batik.transcoder.TranscoderException;
+import org.apache.batik.transcoder.TranscoderInput;
+import org.apache.batik.transcoder.TranscoderOutput;
+import org.apache.batik.transcoder.image.PNGTranscoder;
+import org.apache.fop.svg.PDFTranscoder;
+
 /**
  * @author Jan Henrik Overland
  * @version $Id$
@@ -50,16 +57,18 @@
 {
     private static final Log log = LogFactory.getLog( ExportImageAction.class );
 
-    private static final String SVGDOCUMENT = "SVGDOCUMENT";
-    
     private static final String TYPE_PNG = "png";
-    
+
     private static final String TYPE_PDF = "pdf";
 
+    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>]>";
+
     // -------------------------------------------------------------------------
     // Output & input
     // -------------------------------------------------------------------------
-    
+
     private String title;
 
     public void setTitle( String title )
@@ -74,20 +83,6 @@
         this.svg = svg;
     }
 
-    private Integer width;
-
-    public void setWidth( Integer width )
-    {
-        this.width = width;
-    }
-
-    private Integer height;
-
-    public void setHeight( Integer height )
-    {
-        this.height = height;
-    }
-    
     private String type;
 
     public void setType( String type )
@@ -95,41 +90,57 @@
         this.type = type;
     }
 
-    private SVGDocument svgDocument;
-
     @Override
     protected String execute( HttpServletResponse response, OutputStream out )
         throws Exception
     {
-        if ( title == null || svg == null || width == null || height == null || type == null )
+        if ( svg != null && type != null )
         {
-            log.info( "Invalid parameter -> Export map from session" );
-
-            svgDocument = (SVGDocument) SessionUtils.getSessionVar( SVGDOCUMENT );
+            if ( type.equals( TYPE_PNG ) )
+            {
+                convertToPNG( new StringBuffer( doctype + svg ), out );
+            }
+
+            else if ( type.equals( TYPE_PDF ) )
+            {
+                convertToPDF( new StringBuffer( doctype + svg ), out );
+            }
+
+            return SUCCESS;
         }
+
         else
         {
-            svgDocument = new SVGDocument();
-            
-            svgDocument.setTitle( title );
-            svgDocument.setSvg( svg );
-            svgDocument.setWidth( width );
-            svgDocument.setHeight( height );
-            
-            SessionUtils.setSessionVar( SVGDOCUMENT, svgDocument );
-        }
-        
-        if ( type.equals( TYPE_PNG ) )
-        {
-            SVGUtils.convertToPNG( svgDocument.getSVGForImage(), out, width, height );
-        }
-        
-        else if ( type.equals( TYPE_PDF ))
-        {
-            SVGUtils.convertToPDF( svgDocument.getSVGForImage(), out );
-        }
-
-        return SUCCESS;
+            log.info( "svg = " + svg + ", type = " + type );
+
+            return NONE;
+        }
+    }
+
+    public void convertToPNG( StringBuffer buffer, OutputStream out )
+        throws TranscoderException, IOException
+    {
+        PNGTranscoder t = new PNGTranscoder();
+
+        t.addTranscodingHint( PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE );
+
+        TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
+
+        TranscoderOutput output = new TranscoderOutput( out );
+
+        t.transcode( input, output );
+    }
+
+    public void convertToPDF( StringBuffer buffer, OutputStream out )
+        throws TranscoderException, IOException
+    {
+        PDFTranscoder t = new PDFTranscoder();
+
+        TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
+
+        TranscoderOutput output = new TranscoderOutput( out );
+
+        t.transcode( input, output );
     }
 
     @Override
@@ -141,9 +152,11 @@
     @Override
     protected String getFilename()
     {
-        return "dhis2_dv_" + CodecUtils.filenameEncode( title ) + "." + CodecUtils.filenameEncode( type );
+        String t = title != null ? CodecUtils.filenameEncode( title ) : "";
+
+        return "dhis2_dv_" + t + "." + CodecUtils.filenameEncode( type );
     }
-    
+
     @Override
     protected boolean disallowCache()
     {

=== removed directory 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export'
=== removed file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGDocument.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGDocument.java	2011-11-16 19:23:27 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGDocument.java	1970-01-01 00:00:00 +0000
@@ -1,106 +0,0 @@
-package org.hisp.dhis.visualizer.export;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * @author Jan Henrik Overland
- * @version $Id$
- */
-public class SVGDocument
-{
-    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>]>";
-
-    private String title;
-    
-    private String svg;
-
-    private int width;
-
-    private int height;
-
-    public SVGDocument()
-    {
-    }
-
-    public StringBuffer getSVGForImage()
-    {
-        String svg_ = doctype + this.svg;
-
-        return new StringBuffer( svg_ );
-    }
-
-    @Override
-    public String toString()
-    {
-        return svg;
-    }
-
-    public String getTitle()
-    {
-        return title;
-    }
-
-    public void setTitle( String title )
-    {
-        this.title = title;
-
-    }
-
-    public String getSvg()
-    {
-        return svg;
-    }
-
-    public void setSvg( String svg )
-    {
-        this.svg = svg;
-
-    }
-
-    public int getWidth()
-    {
-        return width;
-    }
-
-    public void setWidth( int width )
-    {
-        this.width = width;
-    }
-
-    public int getHeight()
-    {
-        return height;
-    }
-
-    public void setHeight( int height )
-    {
-        this.height = height;
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java	2011-11-17 14:53:18 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/export/SVGUtils.java	1970-01-01 00:00:00 +0000
@@ -1,84 +0,0 @@
-package org.hisp.dhis.visualizer.export;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * 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;
-
-import org.apache.batik.transcoder.TranscoderException;
-import org.apache.batik.transcoder.TranscoderInput;
-import org.apache.batik.transcoder.TranscoderOutput;
-import org.apache.batik.transcoder.image.PNGTranscoder;
-import org.apache.fop.svg.PDFTranscoder;
-
-/**
- * @author Jan Henrik Overland
- */
-public class SVGUtils
-{
-    public static void convertToPNG( StringBuffer buffer, OutputStream out, Integer width, Integer height )
-        throws TranscoderException, IOException
-    {
-        if ( width == null || width < 10 )
-        {
-            width = 1190;
-        }
-
-        if ( height == null || height < 10 )
-        {
-            height = 880;
-        }
-
-        PNGTranscoder t = new PNGTranscoder();
-/*
-        t.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( height ) );
-        t.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ) );
-*/        
-        t.addTranscodingHint( PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE );
-
-        TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
-
-        TranscoderOutput output = new TranscoderOutput( out );
-
-        t.transcode( input, output );
-    }
-    
-    public static void convertToPDF( StringBuffer buffer, OutputStream out )
-        throws TranscoderException, IOException
-    {
-        PDFTranscoder t = new PDFTranscoder();
-
-        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-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js	2011-11-17 14:53:18 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js	2011-11-17 16:13:19 +0000
@@ -1839,13 +1839,17 @@
                                 
                                 document.getElementById('titleField').value = DV.state.filter.data[0];
                                 document.getElementById('svgField').value = svg[0].parentNode.innerHTML;
-                                document.getElementById('widthField').value = DV.util.viewport.getSize().x - 100;
-                                document.getElementById('heightField').value = DV.util.viewport.getSize().y - 100;
                                 document.getElementById('typeField').value = type;
                                 
                                 var exportForm = document.getElementById('exportForm');
                                 exportForm.action = '../exportImage.action';
-                                exportForm.submit();
+                                
+                                if (svg[0].parentNode.innerHTML && type) {
+                                    exportForm.submit();
+                                }
+                                else {
+                                    alert("No svg/format");
+                                }
                             },
                             listeners: {
                                 afterrender: function(b) {

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html	2011-11-17 14:53:18 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/index.html	2011-11-17 16:13:19 +0000
@@ -11,8 +11,6 @@
     <form id="exportForm" method="post">
         <input type="hidden" id="titleField" name="title"/>
         <input type="hidden" id="svgField" name="svg"/>
-        <input type="hidden" id="widthField" name="width"/>
-        <input type="hidden" id="heightField" name="height"/>
         <input type="hidden" id="typeField" name="type"/>
     </form>