← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4623: Reimplemented coords transformation in gml2dxf as a static java function

 

------------------------------------------------------------
revno: 4623
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Tue 2011-09-20 23:17:20 +0100
message:
  Reimplemented coords transformation in gml2dxf as a static java function
removed:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/ExcelExtension.java
added:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/transform/gml2dxf.xsl


--
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
=== removed file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/ExcelExtension.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/ExcelExtension.java	2010-07-13 00:31:39 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/ExcelExtension.java	1970-01-01 00:00:00 +0000
@@ -1,58 +0,0 @@
-package org.hisp.dhis.importexport.xml;
-
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-
-/*
- * Copyright (c) 2004-2005, 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 <ORGANIZATION> 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 bobj
- */
-public class ExcelExtension
-{
-    public static String date( String xltimestr )
-    {
-        try
-        {
-            // the number of days since 1/1/1900
-            Integer xldays = new Integer( xltimestr );
-
-            // the beginning of excel time is 1/1/1900
-            Calendar cal = new GregorianCalendar();
-            cal.set( 1900, 0, 1 );
-            // cal.add( Calendar.DAY_OF_MONTH, 20 );
-            cal.add( Calendar.DAY_OF_MONTH, xldays.intValue() - 2 );
-            return cal.getTime().toString();
-        }
-        catch ( Exception ex )
-        {
-            return "";
-        }
-    }
-}

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java	2011-09-20 22:17:20 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.importexport.xml;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.StringTokenizer;
+
+/*
+ * Copyright (c) 2004-2005, 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 <ORGANIZATION> 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 bobj
+ *
+ * Some static helper functions
+ *
+ */
+public class Util
+{
+    /**
+     * Compensating for Excel wonky storage for dates
+     *
+     * @param xltimestr the number of days since 1/1/1900 as undertood by excel
+     * @return
+     */
+    public static String date( String xltimestr )
+    {
+        try
+        {
+            // the number of days since 1/1/1900
+            Integer xldays = new Integer( xltimestr );
+
+            // the beginning of excel time is 1/1/1900
+            Calendar cal = new GregorianCalendar();
+            cal.set( 1900, 0, 1 );
+            // cal.add( Calendar.DAY_OF_MONTH, 20 );
+            cal.add( Calendar.DAY_OF_MONTH, xldays.intValue() - 2 );
+            return cal.getTime().toString();
+        }
+        catch ( Exception ex )
+        {
+            return "";
+        }
+    }
+
+    /**
+     * Tokenizer to convert coordinates in GML to a sequence of <coord>nnn,nnn</coord>
+     * @param coordinates
+     * @return
+     */
+    public static String gmlToCoords(String coordinates)
+    {
+        StringBuilder sb = new StringBuilder();
+        String[] coords = coordinates.split( "\\s");
+
+        for (String coord : coords)
+        {
+            sb.append( "<coord>");
+            sb.append( coord);
+            sb.append( "</coord>");
+        }
+
+        return sb.toString();
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/transform/gml2dxf.xsl'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/transform/gml2dxf.xsl	2011-09-16 11:07:56 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/transform/gml2dxf.xsl	2011-09-20 22:17:20 +0000
@@ -1,31 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:gml="http://www.opengis.net/gml";>
+<xsl:stylesheet version="1.0" 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+  xmlns:gml="http://www.opengis.net/gml";
+>
 
-<xsl:param name="roundingFactor">10000</xsl:param>
+<xsl:param name="roundingFactor">100000</xsl:param>
   
 <xsl:template match="gml:coordinates">
   <coordinatesTuple>
-  <xsl:call-template name="coordinates-delimiter">
-    <xsl:with-param name="coordinates"><xsl:value-of select="."/></xsl:with-param>
-  </xsl:call-template>
-</coordinatesTuple>
-</xsl:template>
-
-<xsl:template name="coordinates-delimiter">
-  <xsl:param name="coordinates"/>
-  <xsl:variable name="newlist" select="concat(normalize-space($coordinates), ' ')"/>
-  <xsl:variable name="first" select="substring-before($newlist, ' ')"/>
-  <xsl:variable name="xcoord" select="substring-before($first, ',')"/>
-  <xsl:variable name="ycoord" select="substring-after($first, ',')"/>
-  <xsl:variable name="remaining" select="substring-after($newlist, ' ')"/>
-  <coord><xsl:value-of select="round($roundingFactor*$xcoord) div $roundingFactor"/>,<xsl:value-of select="round($roundingFactor*$ycoord) div $roundingFactor"/></coord>
-  <xsl:if test="$remaining">
-    <xsl:call-template name="coordinates-delimiter">
-      <xsl:with-param name="coordinates" select="$remaining"/>
-    </xsl:call-template>
-  </xsl:if>
-</xsl:template>
-
+      <xsl:value-of select="dhis:gmlToCoords(normalize-space(.))" 
+        disable-output-escaping="yes" 
+        xmlns:dhis="org.hisp.dhis.importexport.xml.Util" />
+  </coordinatesTuple>
+</xsl:template>
 
 <xsl:template match="gml:Polygon">
   <feature type="Polygon">
@@ -71,4 +58,5 @@
 </dxf>
 </xsl:template>
 
+
 </xsl:stylesheet>
\ No newline at end of file