Revision: 4507
          http://sourceforge.net/p/jump-pilot/code/4507
Author:   michaudm
Date:     2015-06-23 21:55:53 +0000 (Tue, 23 Jun 2015)
Log Message:
-----------
fix a bug in shapefile charset management (dbf field length was sometimes too 
short to store strings with accentuated characters)

Modified Paths:
--------------
    core/trunk/ChangeLog
    core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
    core/trunk/src/org/geotools/dbffile/DbfFileWriter.java

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2015-06-23 12:29:52 UTC (rev 4506)
+++ core/trunk/ChangeLog        2015-06-23 21:55:53 UTC (rev 4507)
@@ -6,6 +6,8 @@
 
 2015-06-23 mmichaud <m.michael.mich...@orange.fr>
   * fix bug #406 wrong message "layers not saved"
+  * fix a bug in shapefile charset management (dbf field length was sometimes
+    too short to store strings with accentuated characters)
 
 2015-06-17 bertazza 
   * added Raster Styler to manage symbologies for 1-banded raster

Modified: core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java      
2015-06-23 12:29:52 UTC (rev 4506)
+++ core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java      
2015-06-23 21:55:53 UTC (rev 4507)
@@ -439,7 +439,7 @@
             if (columnType == AttributeType.INTEGER ||
                     columnType == AttributeType.SMALLINT ||
                     columnType == AttributeType.TINYINT) {
-                int maxlength = findMaxStringLength(featureCollection, t);
+                int maxlength = findMaxStringLength(featureCollection, t, 
charset);
                 if (maxlength <= 3) fields[f] = new DbfFieldDef(columnName, 
'N', 3, 0);
                 else if (maxlength <= 6) fields[f] = new 
DbfFieldDef(columnName, 'N', 6, 0);
                 else if (maxlength <= 9) fields[f] = new 
DbfFieldDef(columnName, 'N', 9, 0);
@@ -452,7 +452,7 @@
 
             else if (columnType == AttributeType.LONG ||
                     columnType == AttributeType.BIGINT) {
-                int maxlength = findMaxStringLength(featureCollection, t);
+                int maxlength = findMaxStringLength(featureCollection, t, 
charset);
                 if (maxlength <= 12) fields[f] = new DbfFieldDef(columnName, 
'N', 12, 0);
                 else if (maxlength <= 15) fields[f] = new 
DbfFieldDef(columnName, 'N', 15, 0);
                 else if (maxlength <= 18) fields[f] = new 
DbfFieldDef(columnName, 'N', 18, 0);
@@ -495,7 +495,7 @@
                         columnType == AttributeType.LONGVARCHAR ||
                         columnType == AttributeType.CHAR ||
                         columnType == AttributeType.TEXT) {
-                int maxlength = findMaxStringLength(featureCollection, t);
+                int maxlength = findMaxStringLength(featureCollection, t, 
charset);
 
                 if (maxlength > 255) {
                     // If truncate option has been applied for less than 30 s
@@ -537,7 +537,7 @@
                //[sstein 9.Nov.2012] added this, as Sextante delivered an 
AttributeType set to null
                if(columnName.isEmpty() == false){
                        // treat as string
-                       int maxlength = findMaxStringLength(featureCollection, 
t);
+                       int maxlength = findMaxStringLength(featureCollection, 
t, charset);
        
                        if (maxlength > 255) {
                            // If truncate option has been applied for less 
than 30 s
@@ -743,7 +743,7 @@
      *@param fc features to look at
      *@param attributeNumber which of the column to test.
      */
-    int findMaxStringLength(FeatureCollection fc, int attributeNumber) {
+    int findMaxStringLength(FeatureCollection fc, int attributeNumber, Charset 
charset) {
         int l;
         int maxlen = 0;
         Feature f;
@@ -751,7 +751,7 @@
         for (Iterator i = fc.iterator(); i.hasNext();) {
             f = (Feature) i.next();
             //patch from Hisaji Ono for Double byte characters
-            l = f.getString(attributeNumber).getBytes().length;
+            l = f.getString(attributeNumber).getBytes(charset).length;
 
             if (l > maxlen) {
                 maxlen = l;

Modified: core/trunk/src/org/geotools/dbffile/DbfFileWriter.java
===================================================================
--- core/trunk/src/org/geotools/dbffile/DbfFileWriter.java      2015-06-23 
12:29:52 UTC (rev 4506)
+++ core/trunk/src/org/geotools/dbffile/DbfFileWriter.java      2015-06-23 
21:55:53 UTC (rev 4507)
@@ -128,7 +128,7 @@
                 case 'G':
                 //chars
                     String ss = (String) o;
-                    while  (ss.length() < fields[i].fieldlen) {
+                    while  (ss.getBytes(charset.name()).length < 
fields[i].fieldlen) {
                         //need to fill it with ' ' chars
                         //this should converge quickly
                         ss = ss + "                                            
                                                                      ";


------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to