Revision: 4337
          http://sourceforge.net/p/jump-pilot/code/4337
Author:   michaudm
Date:     2015-03-14 16:55:27 +0000 (Sat, 14 Mar 2015)
Log Message:
-----------
Manage new attribute types BOOLEAN and LONG in jml and shp drivers 
(also manage other datatypes so that they can be written as one of the 
well-known datatype instead of throwing an error message)

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

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2015-03-14 13:54:44 UTC (rev 4336)
+++ core/trunk/ChangeLog        2015-03-14 16:55:27 UTC (rev 4337)
@@ -1,5 +1,10 @@
 # for display continuity sake please use 2 spaces instead of tabs
 
+2015-03-14 mmichaud <[email protected]>
+  * Manage new attribute types BOOLEAN and LONG in jml and shp drivers
+    (also manage other datatypes so that they can be written as one
+    of the well-known datatype instead of throwing an error message)
+
 2015-02-28 mmichaud <[email protected]>
   * FR 215 : don't open a new ViewAttributesFrame if there is already one
     open for the selected layer Layer

Modified: core/trunk/src/com/vividsolutions/jump/io/GMLInputTemplate.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/io/GMLInputTemplate.java     
2015-03-14 13:54:44 UTC (rev 4336)
+++ core/trunk/src/com/vividsolutions/jump/io/GMLInputTemplate.java     
2015-03-14 16:55:27 UTC (rev 4337)
@@ -276,11 +276,17 @@
         //have the value as a string, make it an object
         cd = (ColumnDescription) columnDefinitions.get(index);
 
-        if (cd.type == AttributeType.STRING) {
+        if (cd.type == AttributeType.STRING ||
+                cd.type == AttributeType.VARCHAR ||
+                cd.type == AttributeType.LONGVARCHAR ||
+                cd.type == AttributeType.CHAR ||
+                cd.type == AttributeType.TEXT) {
             return val;
         }
 
-        if (cd.type == AttributeType.INTEGER) {
+        if (cd.type == AttributeType.INTEGER ||
+                cd.type == AttributeType.SMALLINT ||
+                cd.type == AttributeType.TINYINT) {
             try {
                 //Was Long, but JUMP expects AttributeType.INTEGER to hold 
Integers.
                 //e.g. open JML file then save as Shapefile => get 
ClassCastException.
@@ -291,19 +297,26 @@
                 //Compromise -- try Long if Integer fails. Some other parts of 
JUMP
                 //won't like it (exceptions), but it's better than null. 
Actually I don't like
                 //this null business -- future: warn the user. [Jon Aquino 
1/13/2004]
-                try {
-                    return new Integer(val);
-                }
-                catch (Exception e) {
-                    return new Long(val);
-                }
+                return Integer.parseInt(val);
             } catch (Exception e) {
                 return null;
             }
         }
 
-        if (cd.type == AttributeType.DOUBLE) {
+        if (cd.type == AttributeType.LONG) {
             try {
+                return Long.parseLong(val);
+            } catch (Exception e) {
+                return null;
+            }
+        }
+
+        if (cd.type == AttributeType.DOUBLE ||
+                cd.type == AttributeType.REAL ||
+                cd.type == AttributeType.FLOAT ||
+                cd.type == AttributeType.DECIMAL ||
+                cd.type == AttributeType.BIGDECIMAL) {
+            try {
                 return new Double(val);
             } catch (Exception e) {
                 return null;
@@ -312,14 +325,22 @@
         
         //Adding date support. Can we throw an exception if an exception
         //occurs or if the type is unrecognized? [Jon Aquino]
-        if (cd.type == AttributeType.DATE) {
+        if (cd.type == AttributeType.DATE || cd.type == 
AttributeType.TIMESTAMP) {
             try {
                 return dateParser.parse(val, false);
             } catch (Exception e) {
                 return null;
             }
-        }        
-        
+        }
+
+        if (cd.type == AttributeType.BOOLEAN || cd.type == AttributeType.BIT) {
+            try {
+                return Boolean.parseBoolean(val);
+            } catch (Exception e) {
+                return null;
+            }
+        }
+
         if (cd.type == AttributeType.OBJECT)
         {
                return val; // the GML file has text in it and we want to 
convert it to an "object"

Modified: core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java      
2015-03-14 13:54:44 UTC (rev 4336)
+++ core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java      
2015-03-14 16:55:27 UTC (rev 4337)
@@ -434,19 +434,36 @@
             }
             // end
 
-            if (columnType == AttributeType.INTEGER) {
+            if (columnType == AttributeType.INTEGER ||
+                    columnType == AttributeType.SMALLINT ||
+                    columnType == AttributeType.TINYINT) {
                 fields[f] = new DbfFieldDef(columnName, 'N', 11, 0);  //LDB: 
previously 16
                 DbfFieldDef fromFile = 
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
                 if (fromFile.fieldnumdec == 0)
                     fields[f] = fromFile;
                 f++;
-            } else if (columnType == AttributeType.DOUBLE) {
+            } else if (columnType == AttributeType.LONG) {
+                fields[f] = new DbfFieldDef(columnName, 'N', 21, 0);
+                DbfFieldDef fromFile = 
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
+                if (fromFile.fieldnumdec == 0)
+                    fields[f] = fromFile;
+                f++;
+            } else if (columnType == AttributeType.DOUBLE ||
+                        columnType == AttributeType.REAL ||
+                        columnType == AttributeType.FLOAT ||
+                        columnType == AttributeType.DECIMAL ||
+                        columnType == AttributeType.BIGDECIMAL) {
                 fields[f] = new DbfFieldDef(columnName, 'N', 33, 16);
                 DbfFieldDef fromFile = 
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
                 if (fromFile.fieldnumdec > 0)
                     fields[f] = fromFile;
-               f++;
-            } else if (columnType == AttributeType.STRING || columnType == 
AttributeType.OBJECT) {
+                f++;
+            } else if (columnType == AttributeType.STRING ||
+                        columnType == AttributeType.OBJECT ||
+                        columnType == AttributeType.VARCHAR ||
+                        columnType == AttributeType.LONGVARCHAR ||
+                        columnType == AttributeType.CHAR ||
+                        columnType == AttributeType.TEXT) {
                 int maxlength = findMaxStringLength(featureCollection, t);
 
                 if (maxlength > 255) {
@@ -475,9 +492,12 @@
                 fields[f] = new DbfFieldDef(columnName, 'C', maxlength, 0);
                 //fields[f] = 
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
                f++;
-            } else if (columnType == AttributeType.DATE) {
+            } else if (columnType == AttributeType.DATE || columnType == 
AttributeType.TIMESTAMP) {
                 fields[f] = new DbfFieldDef(columnName, 'D', 8, 0);
                 f++;                
+            } else if (columnType == AttributeType.BOOLEAN || columnType == 
AttributeType.BIT) {
+                fields[f] = new DbfFieldDef(columnName, 'L', 1, 0);
+                f++;
             } else if (columnType == AttributeType.GEOMETRY) {
                 //do nothing - the .shp file handles this
             } else if (columnType == null) {
@@ -537,30 +557,49 @@
             for (u = 0; u < fs.getAttributeCount(); u++) {
                 AttributeType columnType = fs.getAttributeType(u);
 
-                if (columnType == AttributeType.INTEGER) {
+                if (columnType == AttributeType.INTEGER ||
+                        columnType == AttributeType.SMALLINT ||
+                        columnType == AttributeType.TINYINT) {
                     Object a = feature.getAttribute(u);
 
                     if (a == null) {
                         DBFrow.add(new Integer(0));
                     } else {
-                        DBFrow.add((Integer) a);
+                        DBFrow.add(a);
                     }
-                } else if (columnType == AttributeType.DOUBLE) {
+                } else if (columnType == AttributeType.LONG) {
                     Object a = feature.getAttribute(u);
 
                     if (a == null) {
+                        DBFrow.add(new Long(0));
+                    } else {
+                        DBFrow.add(a);
+                    }
+                } else if (columnType == AttributeType.DOUBLE ||
+                        columnType == AttributeType.REAL ||
+                        columnType == AttributeType.FLOAT ||
+                        columnType == AttributeType.DECIMAL ||
+                        columnType == AttributeType.BIGDECIMAL) {
+                    Object a = feature.getAttribute(u);
+
+                    if (a == null) {
                         DBFrow.add(new Double(0.0));
                     } else {
-                        DBFrow.add((Double) a);
+                        DBFrow.add(a);
                     }
-                } else if (columnType == AttributeType.DATE) {
+                } else if (columnType == AttributeType.DATE || columnType == 
AttributeType.TIMESTAMP) {
                     Object a = feature.getAttribute(u);
                     if (a == null) {
                         DBFrow.add("");
                     } else {
                         DBFrow.add(DbfFile.DATE_PARSER.format((Date)a));
                     }                    
-                } else if (columnType == AttributeType.STRING || columnType == 
AttributeType.OBJECT) {
+                } else if (columnType == AttributeType.STRING ||
+                        columnType == AttributeType.OBJECT ||
+                        columnType == AttributeType.VARCHAR ||
+                        columnType == AttributeType.LONGVARCHAR ||
+                        columnType == AttributeType.CHAR ||
+                        columnType == AttributeType.TEXT) {
                     Object a = feature.getAttribute(u);
 
                     if (a == null) {
@@ -573,6 +612,13 @@
                             DBFrow.add(a.toString());
                         }
                     }
+                } else if (columnType == AttributeType.BOOLEAN || columnType 
== AttributeType.BIT) {
+                    Object a = feature.getAttribute(u);
+                    if (a == null) {
+                        DBFrow.add(null);
+                    } else {
+                        DBFrow.add(a);
+                    }
                 } else if (columnType == null) {
                        // [sstein 9 Nov. 2012] added:
                        // in case there is no attribute type but an attribute 
name

Modified: core/trunk/src/org/geotools/dbffile/DbfFieldDef.java
===================================================================
--- core/trunk/src/org/geotools/dbffile/DbfFieldDef.java        2015-03-14 
13:54:44 UTC (rev 4336)
+++ core/trunk/src/org/geotools/dbffile/DbfFieldDef.java        2015-03-14 
16:55:27 UTC (rev 4337)
@@ -4,25 +4,30 @@
 
 import com.vividsolutions.jump.io.EndianDataInputStream;
 import java.nio.charset.Charset;
+
 /**
-* class to hold infomation about the fields in the file
-*/
+ * class to hold infomation about the fields in the file
+ */
 public class DbfFieldDef implements DbfConsts{
-  static final boolean DEBUG=false;
-  public StringBuffer fieldname = new StringBuffer(DBF_NAMELEN);
-  public char fieldtype;
-  public int  fieldstart;
-  public int  fieldlen;
-  public int  fieldnumdec;
-       public DbfFieldDef(){ /* do nothing*/ }
-       public DbfFieldDef(String fieldname,char fieldtype,int fieldlen, int
-               fieldnumdec){
+
+    static final boolean DEBUG=false;
+
+    public StringBuffer fieldname = new StringBuffer(DBF_NAMELEN);
+    public char fieldtype;
+    public int  fieldstart;
+    public int  fieldlen;
+    public int  fieldnumdec;
+
+    public DbfFieldDef(){ /* do nothing*/ }
+
+    public DbfFieldDef(String fieldname, char fieldtype, int fieldlen, int 
fieldnumdec){
                this.fieldname = new StringBuffer(fieldname);
                this.fieldname.setLength(DBF_NAMELEN);
                this.fieldtype = fieldtype;
                this.fieldlen = fieldlen;
                this.fieldnumdec = fieldnumdec;
        }
+
        public String toString(){
                return new String(""+fieldname+" "+fieldtype+" "+fieldlen+
                        "."+fieldnumdec);
@@ -39,9 +44,9 @@
    * @param dFile
    * @throws IOException
    */
-  public void setup(int pos, EndianDataInputStream dFile) throws IOException {
-         setup(pos, dFile, Charset.defaultCharset());
-  }
+    public void setup(int pos, EndianDataInputStream dFile) throws IOException 
{
+           setup(pos, dFile, Charset.defaultCharset());
+    }
 
   /**
    * Sets up the Dbf field definition with a specified Charset for the 
fieldnames.
@@ -51,57 +56,57 @@
    * @param charset
    * @throws IOException
    */
-  public void setup(int pos, EndianDataInputStream dFile, Charset charset) 
throws IOException {
+    public void setup(int pos, EndianDataInputStream dFile, Charset charset) 
throws IOException {
 
-  //two byte character modification thanks to Hisaji ONO
-  byte[] strbuf = new byte[DBF_NAMELEN]; // <---- byte array buffer for 
storing string's byte data 
-       int j=-1;
-       int term =-1;
-  for(int i=0;i<DBF_NAMELEN;i++){ 
-        byte b = dFile.readByteLE();
-        if(b==0){
-          if(term== -1 )
-            term=j;
-          continue;
+        //two byte character modification thanks to Hisaji ONO
+        byte[] strbuf = new byte[DBF_NAMELEN]; // <---- byte array buffer for 
storing string's byte data
+           int j = -1;
+           int term = -1;
+        for(int i = 0 ; i < DBF_NAMELEN ; i++){
+            byte b = dFile.readByteLE();
+            if(b == 0){
+                if(term == -1 ) {
+                    term = j;
+                }
+                continue;
+            }
+            j++;
+            strbuf[j] = b; // <---- read string's byte data
         }
-        j++;
-        strbuf[j] = b; // <---- read string's byte data
-  } 
-      if(term==-1) term=j;
-      String name = new String(strbuf, 0, term+1, charset.name());
+        if(term == -1) term = j;
+        String name = new String(strbuf, 0, term + 1, charset.name());
 
-  fieldname.append(name.trim()); // <- append byte array to String Buffer 
+        fieldname.append(name.trim()); // <- append byte array to String Buffer
 
-  if(DEBUG)System.out.println("Fieldname "+fieldname);
-  fieldtype=(char)dFile.readUnsignedByteLE();
-  fieldstart=pos;
-  dFile.skipBytes(4);
-  switch(fieldtype){
-    case 'C':
-    case 'c':
-    case 'D':
-    case 'L':
-    case 'M':
-    case 'G':
-      fieldlen=(int)dFile.readUnsignedByteLE();
-      fieldnumdec=(int)dFile.readUnsignedByteLE();
-      fieldnumdec=0;
-      break;
-               case 'N':
-               case 'n':
-    case 'F':
-    case 'f':
-      fieldlen=(int)dFile.readUnsignedByteLE();
-      fieldnumdec=(int)dFile.readUnsignedByteLE();
-      break;
-    default:
-      System.out.println("Help - wrong field type: "+fieldtype);
-  }
-  if(DEBUG)System.out.println("Fieldtype "+fieldtype+" width "+fieldlen+
-    "."+fieldnumdec);
+        if(DEBUG) System.out.println("Fieldname " + fieldname);
+        fieldtype=(char)dFile.readUnsignedByteLE();
+        fieldstart=pos;
+        dFile.skipBytes(4);
+        switch(fieldtype){
+            case 'C':
+            case 'c':
+            case 'D':
+            case 'L':
+            case 'M':
+            case 'G':
+                fieldlen = dFile.readUnsignedByteLE();
+                fieldnumdec = dFile.readUnsignedByteLE();
+                fieldnumdec = 0;
+                break;
+                   case 'N':
+                   case 'n':
+            case 'F':
+            case 'f':
+                fieldlen = dFile.readUnsignedByteLE();
+                fieldnumdec = dFile.readUnsignedByteLE();
+                break;
+            default:
+                System.out.println("Help - wrong field type: "+fieldtype);
+        }
+        if(DEBUG) System.out.println("Fieldtype "+fieldtype+" width "+fieldlen+
+            "."+fieldnumdec);
 
-  dFile.skipBytes(14);
-    
+        dFile.skipBytes(14);
 
-  }
+    }
 }

Modified: core/trunk/src/org/geotools/dbffile/DbfFile.java
===================================================================
--- core/trunk/src/org/geotools/dbffile/DbfFile.java    2015-03-14 13:54:44 UTC 
(rev 4336)
+++ core/trunk/src/org/geotools/dbffile/DbfFile.java    2015-03-14 16:55:27 UTC 
(rev 4337)
@@ -129,29 +129,37 @@
         String realtype;
 
         switch (type) {
-        case 'C':
-            realtype = "STRING";
-            break;
+            case 'C':
+                realtype = "STRING";
+                break;
 
-        case 'N':
-            if (fielddef[col].fieldnumdec == 0) {
-                realtype = "INTEGER";
-            } else {
+            case 'N':
+                if (fielddef[col].fieldnumdec == 0) {
+                    if (fielddef[col].fieldlen > 11) {
+                        realtype = "LONG";
+                    } else {
+                        realtype = "INTEGER";
+                    }
+                } else {
+                    realtype = "DOUBLE";
+                }
+                break;
+
+            case 'F':
                 realtype = "DOUBLE";
-            }
-            break;
+                break;
 
-        case 'F':
-            realtype = "DOUBLE";
-            break;
+            case 'D': //Added by [Jon Aquino]
+                realtype = "DATE";
+                break;
 
-        case 'D': //Added by [Jon Aquino]
-            realtype = "DATE";
-            break;
+            case 'L': //Added by [Jon Aquino]
+                realtype = "BOOLEAN";
+                break;
 
-        default:
-            realtype = "STRING";
-            break;
+            default:
+                realtype = "STRING";
+                break;
         }
 
         return realtype;
@@ -234,9 +242,9 @@
      * @param row - the row to fetch
      * @exception java.io.IOException on read error.
      */
-    public Vector ParseDbfRecord(long row) throws java.io.IOException {
-        return ParseRecord(GetDbfRec(row));
-    }
+    //public Vector ParseDbfRecord(long row) throws java.io.IOException {
+    //    return ParseRecord(GetDbfRec(row));
+    //}
 
     // like public Vector ParseRecord(StringBuffer rec), but this
     // will try to minimize the number of object created to keep
@@ -257,63 +265,83 @@
         int end;
         start = fielddef[wantedCol].fieldstart;
         int len = fielddef[wantedCol].fieldlen;                 //[sstein 
9.Sept.08]
-        end = start + fielddef[wantedCol].fieldlen;
+        end = start + len;
         String s;
         String masterString;
+
         switch (fielddef[wantedCol].fieldtype) {
             
-        case 'C': //character
-            while ((start < end) &&
-                   (rec[end-1] == ' ' ||    //[sstein 9.Sept.08]
-                    rec[end-1] == 0))       //[mmichaud 16 june 2010]
-                    end--;  //trim trailing spaces
-            s = new String(rec, start, end - start, charset.name());  
//[sstein 9.Sept.08] + [Matthias Scholz 3. Sept.10] Charset added
-            masterString = uniqueStrings.get(s);
-            if (masterString!=null) return masterString;
-            else {
-                uniqueStrings.put(s,s);
-                return s;
-            }
+            case 'C': //character
+                while ((start < end) &&
+                       (rec[end-1] == ' ' ||    //[sstein 9.Sept.08]
+                        rec[end-1] == 0))       //[mmichaud 16 june 2010]
+                        end--;  //trim trailing spaces
+                //[sstein 9.Sept.08] + [Matthias Scholz 3. Sept.10] Charset 
added
+                s = new String(rec, start, end - start, charset.name());
+                masterString = uniqueStrings.get(s);
+                if (masterString != null) {
+                    return masterString;
+                } else {
+                    uniqueStrings.put(s,s);
+                    return s;
+                }
 
-        case 'F': //same as numeric, more or less
-        case 'N': //numeric
+            case 'F': //same as numeric, more or less
 
-          // fields of type 'F' are always represented as Doubles
-          boolean isInteger = fielddef[wantedCol].fieldnumdec == 0
-                && fielddef[wantedCol].fieldtype == 'N';
+            case 'N': //numeric
 
-          // The number field should be trimed from the start AND the end.
-          // Added .trim() to 'String numb = rec.substring(start, end)' 
instead. [Kevin Neufeld]
-          // while ((start < end) && (rec.charAt(start) == ' '))
-          //   start++;
+                // fields of type 'F' are always represented as Doubles
+                boolean isInteger = fielddef[wantedCol].fieldnumdec == 0
+                    && fielddef[wantedCol].fieldtype == 'N';
+                boolean isLong = isInteger && fielddef[wantedCol].fieldlen > 
11;
 
-          String numb = new String(rec, start, len).trim();  //[sstein 
9.Sept.08]
-          if (isInteger) { //its an int
-              try {
-                  return new Integer(numb);
-              } catch (java.lang.NumberFormatException e) {
-                  return new Integer(0);
-              }
-          } else { //its a float
-              try {
-                  return new Double(numb);
-              } catch (java.lang.NumberFormatException e) {
-                  // dBase can have numbers that look like '********' !! This 
isn't ideal but at least reads them
-                  return new Double(Double.NaN);
-              }
-          }
+                // The number field should be trimed from the start AND the 
end.
+                // Added .trim() to 'String numb = rec.substring(start, end)' 
instead. [Kevin Neufeld]
+                // while ((start < end) && (rec.charAt(start) == ' '))
+                //     start++;
 
-        case 'D': //date. Added by [Jon Aquino]
-            return parseDate(new String(rec, start, len));  //[sstein 
9.Sept.08]
+                String numb = new String(rec, start, len).trim();  //[sstein 
9.Sept.08]
+                if (isLong) { //its an int
+                    try {
+                        return Long.parseLong(numb);
+                    } catch (java.lang.NumberFormatException e) {
+                        return new Long(0);
+                    }
+                }
+                else if (isInteger) { //its an int
+                    try {
+                        return Integer.parseInt(numb);
+                    } catch (java.lang.NumberFormatException e) {
+                        return new Integer(0);
+                    }
+                }
+                else { //its a float
+                    try {
+                        return Double.parseDouble(numb);
+                    } catch (java.lang.NumberFormatException e) {
+                        // dBase can have numbers that look like '********' !! 
This isn't ideal but at least reads them
+                        return new Double(Double.NaN);
+                    }
+                }
 
-        default:
-               s = new String(rec, start, len);  //[sstein 9.Sept.08]
-            masterString = uniqueStrings.get(s);
-            if (masterString!=null) return masterString;
-            else {
-                uniqueStrings.put(s,s);
-                return s;
-            }
+            case 'L': //boolean added by mmichaud
+                String bool = new String(rec, start, len).trim().toLowerCase();
+                if (bool.equals("?")) return null;
+                else if (bool.equals("t") || bool.equals("y") || 
bool.equals("1")) return Boolean.TRUE;
+                else return Boolean.FALSE;
+
+            case 'D': //date. Added by [Jon Aquino]
+                return parseDate(new String(rec, start, len));  //[sstein 
9.Sept.08]
+
+            default:
+                   s = new String(rec, start, len);  //[sstein 9.Sept.08]
+                masterString = uniqueStrings.get(s);
+                if (masterString!=null) {
+                    return masterString;
+                } else {
+                    uniqueStrings.put(s,s);
+                    return s;
+                }
         }
     }
 
@@ -323,6 +351,7 @@
      * @param rec the record to be parsed.
      */
     //public Vector ParseRecord(StringBuffer rec) {  //[sstein 9.Sept.08]
+    /*
     public Vector ParseRecord(byte[] rec) {  //[sstein 9.Sept.08]
 
         Vector record = new Vector(numfields);
@@ -348,26 +377,46 @@
                     try {
                         String tt = t.substring(fielddef[i].fieldstart,
                                 fielddef[i].fieldstart + fielddef[i].fieldlen);
-                        record.addElement(Integer.valueOf(tt.trim()));
+                        if (fielddef[i].fieldlen > 11) {
+                            record.addElement(Long.parseLong(tt.trim()));
+                        }
+                        else {
+                            record.addElement(Integer.parseInt(tt.trim()));
+                        }
                     } catch (java.lang.NumberFormatException e) {
-                        record.addElement(new Integer(0));
+                        if (fielddef[i].fieldlen > 11) {
+                            record.addElement(null);
+                        } else {
+                            record.addElement(null);
+                        }
                     }
                 } else { //its a float
 
                     try {
-                        record.addElement(Double.valueOf(t.substring(
+                        record.addElement(Double.parseDouble(t.substring(
                                     fielddef[i].fieldstart,
                                     fielddef[i].fieldstart +
                                     fielddef[i].fieldlen).trim()));
                     } catch (java.lang.NumberFormatException e) {
-                        record.addElement(new Double(0.0));
+                        record.addElement(null);
                     }
                 }
                 break;
 
+            case 'L':
+                String bool = t.substring(fielddef[i].fieldstart,
+                        fielddef[i].fieldstart + 
fielddef[i].fieldlen).trim().toLowerCase();
+                if (bool.equals("?")) {
+                    record.addElement(null);
+                } else if (bool.equals("t") || bool.equals("y") || 
bool.equals("1")) {
+                    record.addElement(Boolean.TRUE);
+                } else  {
+                    record.addElement(Boolean.FALSE);
+                }
+                break;
             case 'F':
                 try {
-                    record.addElement(Double.valueOf(t.substring(
+                    record.addElement(Double.parseDouble(t.substring(
                                 fielddef[i].fieldstart,
                                 fielddef[i].fieldstart + fielddef[i].fieldlen)
                                                  .trim()));
@@ -389,6 +438,7 @@
 
         return record;
     }
+    */
 
     /**
      * Fetches a column of Integers from the database file.
@@ -396,10 +446,12 @@
      * @exception java.io.IOException - on read error
      * @exception DbfFileException - column is not an Integer.
      */
+    /*
     public Integer[] getIntegerCol(int col)
             throws java.io.IOException, DbfFileException {
         return getIntegerCol(col, 0, last_rec);
     }
+    */
 
     /**
      * Fetches a part column of Integers from the database file.
@@ -409,6 +461,7 @@
      * @exception java.io.IOException - on read error
      * @exception DbfFileException - column is not an Integer.
      */
+    /*
     public Integer[] getIntegerCol(int col, int start, int end)
             throws java.io.IOException, DbfFileException {
         Integer[] column = new Integer[end - start];
@@ -457,19 +510,94 @@
 
         return column;
     }
+    */
 
     /**
+     * Fetches a column of Longs from the database file.
+     * @param col - the column to fetch
+     * @exception java.io.IOException - on read error
+     * @exception DbfFileException - column is not an Long.
+     */
+    /*
+    public Long[] getLongCol(int col)
+            throws java.io.IOException, DbfFileException {
+        return getLongCol(col, 0, last_rec);
+    }
+    */
+
+    /**
      * Fetches a column of Double from the database file.
      * @param col - the column to fetch
      * @exception java.io.IOException - on read error
      * @exception DbfFileException - column is not an Integer.
      */
+    /*
     public Double[] getFloatCol(int col)
             throws DbfFileException, java.io.IOException {
         return getFloatCol(col, 0, last_rec);
     }
+    */
 
     /**
+     * Fetches a part column of Longs from the database file.
+     * @param col - the column to fetch
+     * @param start - the row to start fetching from
+     * @param end - the row to stop fetching at.
+     * @exception java.io.IOException - on read error
+     * @exception DbfFileException - column is not a Long.
+     */
+    /*
+    public Long[] getLongCol(int col, int start, int end)
+            throws java.io.IOException, DbfFileException {
+        Long[] column = new Long[end - start];
+        StringBuilder sb = new StringBuilder(numfields);
+        int k = 0;
+        int i = 0;
+
+        if (col >= numfields) {
+            throw new DbfFileException("DbFi>No Such Column in file: " + col);
+        }
+
+        if (fielddef[col].fieldtype != 'N') {
+            throw new DbfFileException("DbFi>Column " + col +
+                    " is not Integer");
+        }
+
+        // move to start of data
+        try {
+            rFile.seek(data_offset + (rec_size * start));
+
+            for (i = start; i < end; i++) {
+                sb.setLength(0);
+
+                for (k = 0; k < rec_size; k++)
+                    sb.append((char) rFile.readUnsignedByte());
+
+                String record = sb.toString();
+                try {
+                    column[i - start] = new Long(record.substring(
+                            fielddef[col].fieldstart,
+                            fielddef[col].fieldstart +
+                                    fielddef[col].fieldlen));
+                } catch (java.lang.NumberFormatException e) {
+                    column[i - start] = new Long(0);
+                }
+            }
+        } catch (java.io.EOFException e) {
+            System.err.println("DbFi>" + e);
+            System.err.println("DbFi>record " + i + " byte " + k +
+                    " file pos " + rFile.getFilePointer());
+        } catch (java.io.IOException e) {
+            System.err.println("DbFi>" + e);
+            System.err.println("DbFi>record " + i + " byte " + k +
+                    " file pos " + rFile.getFilePointer());
+        }
+
+        return column;
+    }
+    */
+
+    /**
      * Fetches a part column of Double from the database file.
      * @param col - the column to fetch
      * @param start - the row to start fetching from
@@ -477,6 +605,7 @@
      * @exception java.io.IOException - on read error
      * @exception DbfFileException - column is not an Integer.
      */
+    /*
     public Double[] getFloatCol(int col, int start, int end)
             throws DbfFileException, java.io.IOException {
         Double[] column = new Double[end - start];
@@ -532,6 +661,7 @@
 
         return column;
     }
+    */
 
     /**
      * Fetches a column of Strings from the database file.
@@ -539,10 +669,12 @@
      * @exception java.io.IOException - on read error
      * @exception DbfFileException - column is not an Integer.
      */
+    /*
     public String[] getStringCol(int col)
         throws DbfFileException, java.io.IOException {
         return getStringCol(col, 0, last_rec);
     }
+    */
 
     /**
      * Fetches a part column of Strings from the database file.
@@ -552,6 +684,7 @@
      * @exception java.io.IOException - on read error
      * @exception DbfFileException - column is not an Integer.
      */
+    /*
     public String[] getStringCol(int col, int start, int end)
         throws DbfFileException, java.io.IOException {
         String[] column = new String[end - start];
@@ -596,6 +729,7 @@
 
         return column;
     }
+    */
 
     public void close() throws IOException {
         dFile.close();

Modified: core/trunk/src/org/geotools/dbffile/DbfFileWriter.java
===================================================================
--- core/trunk/src/org/geotools/dbffile/DbfFileWriter.java      2015-03-14 
13:54:44 UTC (rev 4336)
+++ core/trunk/src/org/geotools/dbffile/DbfFileWriter.java      2015-03-14 
16:55:27 UTC (rev 4337)
@@ -48,7 +48,7 @@
         NoFields = f.length;
         NoRecs = nrecs;
         fields = new DbfFieldDef[NoFields];
-        for(int i=0;i<NoFields;i++){
+        for(int i = 0 ; i < NoFields ; i++){
             fields[i]=f[i];
         }
         ls.writeByteLE(3); // ID - dbase III with out memo
@@ -75,7 +75,7 @@
         for(int i=0;i<20;i++) ls.writeByteLE(0); // 20 bytes of junk!
 
         // field descriptions
-        for(int i=0;i<NoFields;i++){
+        for(int i = 0 ; i < NoFields ; i++){
             //patch from Hisaji Ono for Double byte characters
             ls.write(fields[i].fieldname.toString().getBytes(charset.name()), 
0, 11 ); // [Matthias Scholz 04.Sept.2010] Charset added
             ls.writeByteLE(fields[i].fieldtype);
@@ -116,7 +116,7 @@
         ls.writeByteLE(' ');
         int len;
         StringBuffer tmps;
-        for(int i=0;i<NoFields;i++){
+        for(int i = 0 ; i < NoFields ; i++){
             len = fields[i].fieldlen;
             Object o = rec.elementAt(i);
             switch(fields[i].fieldtype){
@@ -173,14 +173,14 @@
                 case 'F':
                 case 'f':
                     //double
-                    s = ((Double)o).toString();
+                    s = o.toString();
                     String x = 
FormatedString.format(s,fields[i].fieldnumdec,fields[i].fieldlen);
                     ls.writeBytesLE(x);
                     break;
                 // Case 'logical' added by mmichaud on 18 sept. 2004
                 case 'L':
                     //boolean
-                    if (o==null || o.equals("") || o.equals(" ")) 
ls.writeBytesLE(" ");
+                    if (o==null || o.equals("") || o.equals(" ") || 
o.equals("?")) ls.writeBytesLE(" ");
                     else {
                         boolean b = ((Boolean)o).booleanValue();
                         ls.writeBytesLE(b?"T":"F");


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to