← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15797: SVG conversion controller, removing font in text elements, made the EV download fail.

 

------------------------------------------------------------
revno: 15797
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-06-21 18:59:46 +0200
message:
  SVG conversion controller, removing font in text elements, made the EV download fail.
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/GeoUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/GeoUtilsTest.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/GeoUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/GeoUtils.java	2014-05-29 09:04:36 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/GeoUtils.java	2014-06-21 16:59:46 +0000
@@ -34,6 +34,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.lang.StringUtils;
 import org.geotools.geojson.geom.GeometryJSON;
 import org.geotools.referencing.GeodeticCalculator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -49,6 +50,8 @@
 {
     private static final Pattern SVG_TEXT_PATTERN = Pattern.compile( "text=\"(.*?)\"", Pattern.DOTALL );
     
+    private static final String SVG_FONT_REGEX = "(\\s+)font=\"(.*?)\"";
+    
     /**
      * Returns boundaries of a box shape which centre is the point defined by the 
      * given longitude and latitude. The distance between the center point and the
@@ -185,21 +188,34 @@
             return null;
         }
 
+        svg = replaceText( svg );
+        svg = replaceFont( svg );
+        
+        return svg;
+    }
+    
+    private static String replaceText( String svg )
+    {
         StringBuffer sb = new StringBuffer();
         
-        Matcher matcher = SVG_TEXT_PATTERN.matcher( svg );
+        Matcher textMatcher = SVG_TEXT_PATTERN.matcher( svg );
         
-        while ( matcher.find() )
+        while ( textMatcher.find() )
         {
-            String text = matcher.group( 1 );
+            String text = textMatcher.group( 1 );
             
             if ( text != null && !text.isEmpty() )
             {
                 text = "text=\"" + text.replaceAll( "[<>&]", "" ) + "\"";                
-                matcher.appendReplacement( sb, text );
+                textMatcher.appendReplacement( sb, text );
             }
         }
-        
-        return matcher.appendTail( sb ).toString();
+                
+        return textMatcher.appendTail( sb ).toString();        
+    }
+    
+    private static String replaceFont( String svg )
+    {
+        return svg.replaceAll( SVG_FONT_REGEX, StringUtils.EMPTY );
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/GeoUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/GeoUtilsTest.java	2014-05-29 09:04:36 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/GeoUtilsTest.java	2014-06-21 16:59:46 +0000
@@ -68,8 +68,8 @@
     {
         String text = 
             "<svg xmlns=\"http://www.w3.org/2000/svg\";>" +
-            "<text id=\"ext-sprite-1866\" zIndex=\"500\" text=\"Measles Coverage <1y\" hidden=\"false\">" +
-            "<text id=\"ext-sprite-1866\" zIndex=\"500\" text=\"BCG & DPT Coverage\" hidden=\"false\">" +
+            "<text id=\"ext-sprite-1866\" zIndex=\"500\" text=\"Measles Coverage <1y\" font=\"bold 18px Arial,Sans-serif,Lucida Grande\" hidden=\"false\">" +
+            "<text id=\"ext-sprite-1866\" zIndex=\"500\" text=\"BCG & DPT Coverage\" font=\"bold 18px Arial,Sans-serif,Lucida Grande\" hidden=\"false\">" +
             "</svg>";
 
         String expected =