=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-06-01 19:49:10 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-06-04 22:08:39 +0000 @@ -52,7 +52,7 @@ import org.hisp.dhis.system.filter.OrganisationUnitPolygonCoveringCoordinateFilter; import org.hisp.dhis.commons.filter.Filter; import org.hisp.dhis.util.FilterUtils; -import org.hisp.dhis.util.GeoUtils; +import org.hisp.dhis.system.util.GeoUtils; import org.hisp.dhis.system.util.ValidationUtils; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2015-05-28 18:21:56 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2015-06-04 22:08:39 +0000 @@ -52,7 +52,7 @@ import org.hisp.dhis.util.Encoder; import org.hisp.dhis.commons.filter.Filter; import org.hisp.dhis.util.FilterUtils; -import org.hisp.dhis.util.JRExportUtils; +import org.hisp.dhis.system.util.JRExportUtils; import org.hisp.dhis.util.StreamUtils; import org.hisp.dhis.system.velocity.VelocityManager; import org.springframework.jdbc.datasource.DataSourceUtils; === modified file 'dhis-2/dhis-support/dhis-support-commons/pom.xml' --- dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-05-30 15:33:12 +0000 +++ dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-06-04 22:08:39 +0000 @@ -14,6 +14,14 @@ jar DHIS Support Commons + + org.apache.commons @@ -32,22 +40,6 @@ commons-jexl - org.geotools - gt-referencing - - - org.geotools - gt-geojson - - - com.vividsolutions - jts - - - net.sf.jasperreports - jasperreports - - org.scijava jep === removed file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/GeoUtils.java' --- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/GeoUtils.java 2015-05-28 18:00:11 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/GeoUtils.java 1970-01-01 00:00:00 +0000 @@ -1,245 +0,0 @@ -package org.hisp.dhis.util; - -/* - * Copyright (c) 2004-2015, 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 com.vividsolutions.jts.geom.MultiPolygon; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import org.apache.commons.lang3.StringUtils; -import org.geotools.geojson.geom.GeometryJSON; -import org.geotools.referencing.GeodeticCalculator; - -import java.awt.geom.Point2D; -import java.io.IOException; -import java.io.StringReader; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author Lars Helge Overland - */ -public class GeoUtils -{ - private static final Pattern SVG_TEXT_PATTERN = Pattern.compile( "text=\"(.*?)\"", Pattern.DOTALL ); - - private static final String SVG_FONT_REGEX = "(\\s+)font=\"(.*?)\""; - - private static final String FEATURETYPE_POLYGON = "Polygon"; - - private static final String FEATURETYPE_MULTIPOLYGON = "MultiPolygon"; - - /** - * 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 - * edges of the box is defined in meters by the given distance. Based on standard - * EPSG:4326 long/lat projection. The result is an array of length 4 where - * the values at each index are: - * - * - * - * @param longitude the longitude. - * @param latitude the latitude. - * @param distance the distance in meters to each box edge. - * @return an array of length 4. - */ - public static double[] getBoxShape( double longitude, double latitude, double distance ) - { - double[] box = new double[4]; - - GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint( longitude, latitude ); - - calc.setDirection( 0, distance ); - Point2D north = calc.getDestinationGeographicPoint(); - - calc.setDirection( 90, distance ); - Point2D east = calc.getDestinationGeographicPoint(); - - calc.setDirection( 180, distance ); - Point2D south = calc.getDestinationGeographicPoint(); - - calc.setDirection( -90, distance ); - Point2D west = calc.getDestinationGeographicPoint(); - - box[0] = north.getY(); - box[1] = east.getX(); - box[2] = south.getY(); - box[3] = west.getX(); - - return box; - } - - /** - * Computes the distance between two points. - * - * @param from the origin point. - * @param to the end point. - * @return the orthodromic distance between the given points. - */ - public static double getDistanceBetweenTwoPoints( Point2D from, Point2D to) - { - GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint( from ); - calc.setDestinationGeographicPoint( to); - - return calc.getOrthodromicDistance(); - } - - /** - * Get GeometryJSON point. - * - * @param longitude the longitude. - * @param latitude the latitude. - * @return the GeoJSON representation of the given point. - */ - public static Point getGeoJsonPoint( double longitude, double latitude ) - throws IOException - { - Point point = null; - - GeometryJSON gtjson = new GeometryJSON(); - - point = gtjson.readPoint( new StringReader( "{\"type\":\"Point\", \"coordinates\":[" + longitude + "," - + latitude + "]}" ) ); - - return point; - } - - /** - * Check if GeometryJSON point created with this coordinate is valid. - * - * @param latitude the latitude. - * @param longitude the longitude. - * @return true if the point is valid or false. - */ - public static boolean checkGeoJsonPointValid( double longitude, double latitude ) - { - try - { - return getGeoJsonPoint( longitude, latitude ).isValid(); - } - catch ( Exception ex ) - { - return false; - } - } - - /** - * Check if the point coordinate falls within the polygon/MultiPolygon Shape - * - * @param longitude the longitude. - * @param latitude the latitude. - * @param multiPolygonJson the GeoJSON coordinates of the MultiPolygon - * @param featureType the featureType of the MultiPolygon. - */ - public static boolean checkPointWithMultiPolygon( double longitude, double latitude, - String multiPolygonJson, String featureType ) - { - try - { - boolean contains = false; - - GeometryJSON gtjson = new GeometryJSON(); - - Point point = getGeoJsonPoint( longitude, latitude ); - - if ( point != null && point.isValid() ) - { - if ( featureType.compareTo( FEATURETYPE_POLYGON ) == 0 ) - { - Polygon polygon = gtjson.readPolygon( new StringReader( - "{\"type\":\"Polygon\", \"coordinates\":" + multiPolygonJson + "}" ) ); - - contains = polygon.contains( point ); - } - else if ( featureType.compareTo( FEATURETYPE_MULTIPOLYGON ) == 0 ) - { - MultiPolygon multiPolygon = gtjson.readMultiPolygon( new StringReader( - "{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}" ) ); - - contains = multiPolygon.contains( point ); - } - } - - return contains; - } - catch ( Exception ex ) - { - return false; - } - } - - /** - * Escapes the String encoded SVG. - * @param svg the String encoded SVG. - * @return the escaped representation. - */ - public static final String replaceUnsafeSvgText( String svg ) - { - if ( svg == null ) - { - return null; - } - - svg = replaceText( svg ); - svg = replaceFont( svg ); - - return svg; - } - - private static String replaceText( String svg ) - { - StringBuffer sb = new StringBuffer(); - - Matcher textMatcher = SVG_TEXT_PATTERN.matcher( svg ); - - while ( textMatcher.find() ) - { - String text = textMatcher.group( 1 ); - - if ( text != null && !text.isEmpty() ) - { - text = "text=\"" + text.replaceAll( "[<>&]", "" ) + "\""; - textMatcher.appendReplacement( sb, text ); - } - } - - return textMatcher.appendTail( sb ).toString(); - } - - private static String replaceFont( String svg ) - { - return svg.replaceAll( SVG_FONT_REGEX, StringUtils.EMPTY ); - } -} === removed file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/JRExportUtils.java' --- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/JRExportUtils.java 2015-05-28 18:00:11 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/JRExportUtils.java 1970-01-01 00:00:00 +0000 @@ -1,128 +0,0 @@ -package org.hisp.dhis.util; - -/* - * Copyright (c) 2004-2015, 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 net.sf.jasperreports.engine.JRAbstractExporter; -import net.sf.jasperreports.engine.JRException; -import net.sf.jasperreports.engine.JRExporterParameter; -import net.sf.jasperreports.engine.JasperPrint; -import net.sf.jasperreports.engine.export.JRHtmlExporter; -import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; -import net.sf.jasperreports.engine.export.JRPdfExporter; -import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter; -import net.sf.jasperreports.engine.export.JRXlsExporter; - -import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; - -/** - * Supports PDF, HMTL and XLS exports. - * - * @author Lars Helge Overland - */ -public class JRExportUtils -{ - public static final String TYPE_XLS = "xls"; - public static final String TYPE_PDF = "pdf"; - public static final String TYPE_HTML = "html"; - - private static final Map exporters = new HashMap() { - { - put( TYPE_XLS, new JRXlsExportProvider() ); - put( TYPE_PDF, new JRPdfExportProvider() ); - put( TYPE_HTML, new JRHtmlExportProvider() ); - } }; - - /** - * Export the provided JasperPrint the format given by type. - * - * @param type the type to export to. XLS, PDF and HTML are supported. - * @param out the OutputStream to export to. - * @param jasperPrint the JasperPrint to export. - * @throws JRException on export failure. - */ - public static void export( String type, OutputStream out, JasperPrint jasperPrint ) - throws JRException - { - JRExportProvider provider = exporters.get( type ); - - if ( provider != null ) - { - JRAbstractExporter exporter = provider.provide(); - - exporter.setParameter( JRExporterParameter.OUTPUT_STREAM, out ); - exporter.setParameter( JRExporterParameter.JASPER_PRINT, jasperPrint ); - exporter.exportReport(); - } - } - - private interface JRExportProvider - { - JRAbstractExporter provide(); - } - - private static class JRXlsExportProvider implements JRExportProvider - { - @Override - public JRAbstractExporter provide() - { - JRXlsExporter exporter = new JRXlsExporter(); - exporter.setParameter( JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE ); - exporter.setParameter( JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE ); - exporter.setParameter( JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE ); - exporter.setParameter( JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE ); - exporter.setParameter( JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE ); - return exporter; - } - } - - private static class JRPdfExportProvider implements JRExportProvider - { - @Override - public JRAbstractExporter provide() - { - return new JRPdfExporter(); - } - } - - private static class JRHtmlExportProvider implements JRExportProvider - { - @Override - public JRAbstractExporter provide() - { - JRHtmlExporter exporter = new JRHtmlExporter(); - exporter.setParameter( JRHtmlExporterParameter.IMAGES_URI, "../jasperReports/img?image=" ); - - return exporter; - } - } -} - - === modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml' --- dhis-2/dhis-support/dhis-support-system/pom.xml 2015-05-30 15:29:37 +0000 +++ dhis-2/dhis-support/dhis-support-system/pom.xml 2015-06-04 22:08:39 +0000 @@ -60,14 +60,25 @@ org.springframework spring-jdbc + + + + + org.geotools + gt-referencing + + + org.geotools + gt-geojson + + + com.vividsolutions + jts + - org.hibernate - hibernate-core - - net.sf.jasperreports jasperreports @@ -90,6 +101,10 @@ + org.hibernate + hibernate-core + + log4j log4j === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilter.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilter.java 2015-05-28 18:21:56 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitPolygonCoveringCoordinateFilter.java 2015-06-04 22:08:39 +0000 @@ -30,7 +30,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.commons.filter.Filter; -import org.hisp.dhis.util.GeoUtils; +import org.hisp.dhis.system.util.GeoUtils; public class OrganisationUnitPolygonCoveringCoordinateFilter implements Filter === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/GeoUtils.java 2015-06-04 22:08:39 +0000 @@ -0,0 +1,245 @@ +package org.hisp.dhis.system.util; + +/* + * Copyright (c) 2004-2015, 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 com.vividsolutions.jts.geom.MultiPolygon; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.Polygon; +import org.apache.commons.lang3.StringUtils; +import org.geotools.geojson.geom.GeometryJSON; +import org.geotools.referencing.GeodeticCalculator; + +import java.awt.geom.Point2D; +import java.io.IOException; +import java.io.StringReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Lars Helge Overland + */ +public class GeoUtils +{ + private static final Pattern SVG_TEXT_PATTERN = Pattern.compile( "text=\"(.*?)\"", Pattern.DOTALL ); + + private static final String SVG_FONT_REGEX = "(\\s+)font=\"(.*?)\""; + + private static final String FEATURETYPE_POLYGON = "Polygon"; + + private static final String FEATURETYPE_MULTIPOLYGON = "MultiPolygon"; + + /** + * 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 + * edges of the box is defined in meters by the given distance. Based on standard + * EPSG:4326 long/lat projection. The result is an array of length 4 where + * the values at each index are: + * + *
    + *
  • Index 0: Maximum latitude (north edge of box shape).
  • + *
  • Index 1: Maxium longitude (east edge of box shape).
  • + *
  • Index 2: Minimum latitude (south edge of box shape).
  • + *
  • Index 3: Minumum longitude (west edge of box shape).
  • + *
+ * + * @param longitude the longitude. + * @param latitude the latitude. + * @param distance the distance in meters to each box edge. + * @return an array of length 4. + */ + public static double[] getBoxShape( double longitude, double latitude, double distance ) + { + double[] box = new double[4]; + + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint( longitude, latitude ); + + calc.setDirection( 0, distance ); + Point2D north = calc.getDestinationGeographicPoint(); + + calc.setDirection( 90, distance ); + Point2D east = calc.getDestinationGeographicPoint(); + + calc.setDirection( 180, distance ); + Point2D south = calc.getDestinationGeographicPoint(); + + calc.setDirection( -90, distance ); + Point2D west = calc.getDestinationGeographicPoint(); + + box[0] = north.getY(); + box[1] = east.getX(); + box[2] = south.getY(); + box[3] = west.getX(); + + return box; + } + + /** + * Computes the distance between two points. + * + * @param from the origin point. + * @param to the end point. + * @return the orthodromic distance between the given points. + */ + public static double getDistanceBetweenTwoPoints( Point2D from, Point2D to) + { + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint( from ); + calc.setDestinationGeographicPoint( to); + + return calc.getOrthodromicDistance(); + } + + /** + * Get GeometryJSON point. + * + * @param longitude the longitude. + * @param latitude the latitude. + * @return the GeoJSON representation of the given point. + */ + public static Point getGeoJsonPoint( double longitude, double latitude ) + throws IOException + { + Point point = null; + + GeometryJSON gtjson = new GeometryJSON(); + + point = gtjson.readPoint( new StringReader( "{\"type\":\"Point\", \"coordinates\":[" + longitude + "," + + latitude + "]}" ) ); + + return point; + } + + /** + * Check if GeometryJSON point created with this coordinate is valid. + * + * @param latitude the latitude. + * @param longitude the longitude. + * @return true if the point is valid or false. + */ + public static boolean checkGeoJsonPointValid( double longitude, double latitude ) + { + try + { + return getGeoJsonPoint( longitude, latitude ).isValid(); + } + catch ( Exception ex ) + { + return false; + } + } + + /** + * Check if the point coordinate falls within the polygon/MultiPolygon Shape + * + * @param longitude the longitude. + * @param latitude the latitude. + * @param multiPolygonJson the GeoJSON coordinates of the MultiPolygon + * @param featureType the featureType of the MultiPolygon. + */ + public static boolean checkPointWithMultiPolygon( double longitude, double latitude, + String multiPolygonJson, String featureType ) + { + try + { + boolean contains = false; + + GeometryJSON gtjson = new GeometryJSON(); + + Point point = getGeoJsonPoint( longitude, latitude ); + + if ( point != null && point.isValid() ) + { + if ( featureType.compareTo( FEATURETYPE_POLYGON ) == 0 ) + { + Polygon polygon = gtjson.readPolygon( new StringReader( + "{\"type\":\"Polygon\", \"coordinates\":" + multiPolygonJson + "}" ) ); + + contains = polygon.contains( point ); + } + else if ( featureType.compareTo( FEATURETYPE_MULTIPOLYGON ) == 0 ) + { + MultiPolygon multiPolygon = gtjson.readMultiPolygon( new StringReader( + "{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}" ) ); + + contains = multiPolygon.contains( point ); + } + } + + return contains; + } + catch ( Exception ex ) + { + return false; + } + } + + /** + * Escapes the String encoded SVG. + * @param svg the String encoded SVG. + * @return the escaped representation. + */ + public static final String replaceUnsafeSvgText( String svg ) + { + if ( svg == null ) + { + return null; + } + + svg = replaceText( svg ); + svg = replaceFont( svg ); + + return svg; + } + + private static String replaceText( String svg ) + { + StringBuffer sb = new StringBuffer(); + + Matcher textMatcher = SVG_TEXT_PATTERN.matcher( svg ); + + while ( textMatcher.find() ) + { + String text = textMatcher.group( 1 ); + + if ( text != null && !text.isEmpty() ) + { + text = "text=\"" + text.replaceAll( "[<>&]", "" ) + "\""; + textMatcher.appendReplacement( sb, text ); + } + } + + return textMatcher.appendTail( sb ).toString(); + } + + private static String replaceFont( String svg ) + { + return svg.replaceAll( SVG_FONT_REGEX, StringUtils.EMPTY ); + } +} === added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java 2015-06-04 22:08:39 +0000 @@ -0,0 +1,128 @@ +package org.hisp.dhis.system.util; + +/* + * Copyright (c) 2004-2015, 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 net.sf.jasperreports.engine.JRAbstractExporter; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.export.JRHtmlExporter; +import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; +import net.sf.jasperreports.engine.export.JRPdfExporter; +import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter; +import net.sf.jasperreports.engine.export.JRXlsExporter; + +import java.io.OutputStream; +import java.util.HashMap; +import java.util.Map; + +/** + * Supports PDF, HMTL and XLS exports. + * + * @author Lars Helge Overland + */ +public class JRExportUtils +{ + public static final String TYPE_XLS = "xls"; + public static final String TYPE_PDF = "pdf"; + public static final String TYPE_HTML = "html"; + + private static final Map exporters = new HashMap() { + { + put( TYPE_XLS, new JRXlsExportProvider() ); + put( TYPE_PDF, new JRPdfExportProvider() ); + put( TYPE_HTML, new JRHtmlExportProvider() ); + } }; + + /** + * Export the provided JasperPrint the format given by type. + * + * @param type the type to export to. XLS, PDF and HTML are supported. + * @param out the OutputStream to export to. + * @param jasperPrint the JasperPrint to export. + * @throws JRException on export failure. + */ + public static void export( String type, OutputStream out, JasperPrint jasperPrint ) + throws JRException + { + JRExportProvider provider = exporters.get( type ); + + if ( provider != null ) + { + JRAbstractExporter exporter = provider.provide(); + + exporter.setParameter( JRExporterParameter.OUTPUT_STREAM, out ); + exporter.setParameter( JRExporterParameter.JASPER_PRINT, jasperPrint ); + exporter.exportReport(); + } + } + + private interface JRExportProvider + { + JRAbstractExporter provide(); + } + + private static class JRXlsExportProvider implements JRExportProvider + { + @Override + public JRAbstractExporter provide() + { + JRXlsExporter exporter = new JRXlsExporter(); + exporter.setParameter( JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE ); + exporter.setParameter( JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE ); + exporter.setParameter( JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE ); + exporter.setParameter( JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE ); + exporter.setParameter( JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE ); + return exporter; + } + } + + private static class JRPdfExportProvider implements JRExportProvider + { + @Override + public JRAbstractExporter provide() + { + return new JRPdfExporter(); + } + } + + private static class JRHtmlExportProvider implements JRExportProvider + { + @Override + public JRAbstractExporter provide() + { + JRHtmlExporter exporter = new JRHtmlExporter(); + exporter.setParameter( JRHtmlExporterParameter.IMAGES_URI, "../jasperReports/img?image=" ); + + return exporter; + } + } +} + + === 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 2015-05-28 14:33:21 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/GeoUtilsTest.java 2015-06-04 22:08:39 +0000 @@ -28,8 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static org.hisp.dhis.util.GeoUtils.getBoxShape; -import static org.hisp.dhis.util.GeoUtils.replaceUnsafeSvgText; +import static org.hisp.dhis.system.util.GeoUtils.getBoxShape; +import static org.hisp.dhis.system.util.GeoUtils.replaceUnsafeSvgText; import static org.junit.Assert.assertEquals; import org.junit.Test; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SvgConversionController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SvgConversionController.java 2015-05-28 16:10:07 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SvgConversionController.java 2015-06-04 22:08:39 +0000 @@ -49,7 +49,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import static org.hisp.dhis.util.GeoUtils.replaceUnsafeSvgText; +import static org.hisp.dhis.system.util.GeoUtils.replaceUnsafeSvgText; @Controller @RequestMapping