← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2369: (GIS) Fixed bug: Special characters in e.g. indicator/dataelement name caused image export crash.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 2369 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-10-14 14:06:08 +0200
message:
  (GIS) Fixed bug: Special characters in e.g. indicator/dataelement name caused image export crash.
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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/util.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/core/GeoStat.js


--
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-09-03 14:54:54 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java	2010-10-14 11:58:33 +0000
@@ -58,8 +58,6 @@
 import org.hisp.dhis.mapping.export.SVGUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.util.StreamActionSupport;
 
 /**
@@ -67,7 +65,6 @@
  * @version $Id$
  */
 
-@SuppressWarnings( "serial" )
 public class ExportExcelAction
     extends StreamActionSupport
 {
@@ -104,13 +101,6 @@
         this.organisationUnitService = organisationUnitService;
     }
 
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-
     private IndicatorService indicatorService;
 
     public void setIndicatorService( IndicatorService indicatorService )

=== 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-09-27 11:18:38 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java	2010-10-14 11:58:33 +0000
@@ -32,16 +32,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.mapping.MappingService;
 import org.hisp.dhis.mapping.export.SVGDocument;
 import org.hisp.dhis.mapping.export.SVGUtils;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.util.SessionUtils;
 import org.hisp.dhis.util.StreamActionSupport;
 
@@ -49,7 +45,7 @@
  * @author Tran Thanh Tri
  * @version $Id$
  */
-@SuppressWarnings( "serial" )
+
 public class ExportImageAction
     extends StreamActionSupport
 {
@@ -61,13 +57,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-
     private IndicatorService indicatorService;
 
     public void setIndicatorService( IndicatorService indicatorService )
@@ -81,13 +70,6 @@
     {
         this.dataElementService = dataElementService;
     }
-    
-    private MappingService mappingService;
-    
-    public void setMappingService( MappingService mappingService )
-    {
-        this.mappingService = mappingService;
-    }
 
     // -------------------------------------------------------------------------
     // Output & input
@@ -155,7 +137,7 @@
     protected String execute( HttpServletResponse response, OutputStream out )
         throws Exception
     {
-        log.info( "Exporting image, title: " + title + ", indicator: " + indicator + ", period" + period + ", width: " + width + ", height: " + height );
+        log.info( "Exporting image, title: " + title + ", indicator: " + indicator + ", period: " + period + ", width: " + width + ", height: " + height );
         
         log.info( "Legends: " + legends );
         

=== 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-09-27 11:18:38 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java	2010-10-14 11:58:33 +0000
@@ -30,6 +30,7 @@
 import net.sf.json.JSONObject;
 import net.sf.json.JSONSerializer;
 
+import org.apache.commons.lang.StringEscapeUtils;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.indicator.Indicator;
 
@@ -70,15 +71,15 @@
     public StringBuffer getSVGForImage()
     {
         String indicatorName = this.indicator != null ? this.indicator.getName() : this.dataElement.getName();
-        
+
         String title_ = "<g id=\"title\" style=\"display: block; visibility: visible;\"><text id=\"title\" x=\"30\" y=\"15\" font-size=\"14\" font-weight=\"bold\"><tspan>"
-            + this.title + "</tspan></text></g>";
+            + StringEscapeUtils.escapeXml( this.title ) + "</tspan></text></g>";
 
         String indicator_ = "<g id=\"indicator\" style=\"display: block; visibility: visible;\"><text id=\"indicator\" x=\"30\" y=\"30\" font-size=\"12\"><tspan>"
-            + indicatorName + "</tspan></text></g>";
+            + StringEscapeUtils.escapeXml( indicatorName ) + "</tspan></text></g>";
 
         String period_ = "<g id=\"period\" style=\"display: block; visibility: visible;\"><text id=\"period\" x=\"30\" y=\"45\" font-size=\"12\"><tspan>"
-            + this.period + "</tspan></text></g>";
+            + StringEscapeUtils.escapeXml( this.period ) + "</tspan></text></g>";
 
         String svg_ = doctype + this.svg;
 
@@ -131,13 +132,10 @@
         for ( int i = 0; i < jsonLegends.size(); i++ )
         {
             legend = jsonLegends.getJSONObject( i );
-
-            String label = legend.getString( "label" );
-
-            String color = legend.getString( "color" );
-
-            System.out.println( "1 l " + label + " c " + color );
-            System.out.println( legend );
+            
+            String label = StringEscapeUtils.escapeXml( legend.getString( "label" ) );
+            
+            String color = StringEscapeUtils.escapeXml( legend.getString( "color" ) );
             
             result += "<rect x='" + x + "' y='" + (y + 1) + "' height='1' width='1' fill='" + color
                 + "' stroke='#000000' stroke-width='0.001'/>";
@@ -168,13 +166,10 @@
         for ( int i = 0; i < jsonLegends.size(); i++ )
         {
             legend = jsonLegends.getJSONObject( i );
-
-            String label = legend.getString( "label" );
-
-            String color = legend.getString( "color" );
-
-            System.out.println( "1 l " + label + " c " + color );
-            System.out.println( legend );
+            
+            String label = StringEscapeUtils.escapeXml( legend.getString( "label" ) );
+            
+            String color = StringEscapeUtils.escapeXml( legend.getString( "color" ) );
             
             result += "<rect x='" + x + "' y='" + (y + 15) + "' height='15' width='30' fill='" + color
                 + "' stroke='#000000' stroke-width='1'/>";

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-10-13 13:00:43 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-10-14 11:58:33 +0000
@@ -364,14 +364,12 @@
 
 	<bean id="org.hisp.dhis.mapping.action.ExportImageAction" class="org.hisp.dhis.mapping.action.ExportImageAction"
 		scope="prototype">
-		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
 		<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.mapping.action.ExportExcelAction" class="org.hisp.dhis.mapping.action.ExportExcelAction"
 		scope="prototype">
-		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
 		<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
 		<property name="organisationUnitService"
 			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/util.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/util.js	2010-10-13 14:51:29 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/util.js	2010-10-14 11:58:33 +0000
@@ -168,11 +168,11 @@
             json += '{';
             json += '"organisation": "' + mapValues[i].orgUnitId + '",';
             json += '"value": "' + mapValues[i].value + '" ';
-            json += i < mapValues.length - 1 ? '},' : '}'
+            json += i < mapValues.length - 1 ? '},' : '}';
         }
         json += ']';
         json += '}';
-        return json
+        return json;
     },
 
     getLegendsJSON: function() {

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/core/GeoStat.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/core/GeoStat.js	2010-10-13 21:44:10 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/core/GeoStat.js	2010-10-14 11:58:33 +0000
@@ -255,10 +255,10 @@
             var labelGenerator = this.labelGenerator || this.defaultLabelGenerator;
             bins[i].label = labelGenerator(bins[i], i, nbBins, maxDec);
 			imageLegend[i] = new Object();
-			imageLegend[i].label = bins[i].label;
+			imageLegend[i].label = bins[i].label.replace('&nbsp;&nbsp;', ' ');
         }
         
-        if (ACTIVEPANEL == GLOBALS.config.thematicMap) {   
+        if (ACTIVEPANEL == GLOBALS.config.thematicMap) {
             choropleth.imageLegend = imageLegend;
         }
         else if (ACTIVEPANEL == GLOBALS.config.thematicMap2) {