Revision 12910

View differences:

branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/IndexedShpDriver.java
156 156
		// bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
157 157
        bb = new BigByteBuffer2(channel, FileChannel.MapMode.READ_ONLY);
158 158

  
159
        finShx = new FileInputStream(getShxFile(f));
159
        finShx = new FileInputStream(SHP.getShxFile(f));
160 160

  
161 161
        // Open the file and then get a channel from the stream
162 162
        channelShx = finShx.getChannel();
......
825 825
		return "gdbms dbf driver";
826 826
	}
827 827

  
828
	/**
829
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataFile(java.io.File)
830
	 */
831
	public File getDataFile(File f) {
832
		String str = f.getAbsolutePath();
833
		if (str.endsWith("SHP"))
834
			return new File(str.substring(0, str.length() - 3) + "DBF");
835

  
836
		return new File(str.substring(0, str.length() - 3) + "dbf");
837
	}
838

  
839
    public File getShxFile(File f) {
840
        String str = f.getAbsolutePath();
841
        if (str.endsWith("SHP"))
842
			return new File(str.substring(0, str.length() - 3) + "SHX");
843

  
844
        return new File(str.substring(0, str.length() - 3) + "shx");
845
    }
846

  
847

  
848 828
	/* (non-Javadoc)
849 829
	 * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int)
850 830
	 */
......
918 898
			DriverUtilities.copy(fcinShp, fcoutShp);
919 899

  
920 900
			// Shx
921
			File shxFile = getShxFile(fTemp);
901
			File shxFile = SHP.getShxFile(fTemp);
922 902
			FileChannel fcinShx = new FileInputStream(shxFile).getChannel();
923
			FileChannel fcoutShx = new FileOutputStream(getShxFile(fileShp)).getChannel();
903
			FileChannel fcoutShx = new FileOutputStream(SHP.getShxFile(fileShp)).getChannel();
924 904
			DriverUtilities.copy(fcinShx, fcoutShx);
925 905

  
926 906
			// Dbf
......
1003 983
	public boolean isWriteAll() {
1004 984
		return true;
1005 985
	}
986

  
987
	public File getDataFile(File f) {
988
		return SHP.getDbfFile(f);
989
	}
1006 990
}
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/SHP.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.drivers.shp;
42 42

  
43
import java.io.File;
44
import java.util.BitSet;
45

  
43 46
import com.iver.cit.gvsig.fmap.core.IGeometry;
44 47
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiLine;
45 48
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiPoint;
......
49 52
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException;
50 53
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
51 54

  
52
import java.io.File;
53 55

  
54
import java.util.BitSet;
55

  
56

  
57 56
/**
58 57
 * Clase con las constantes que representan los diferentes tipos de Shape y
59 58
 * m?todos est?ticos relativos a los shapes.
......
179 178

  
180 179
        return new double[] { min, max };
181 180
    }
181
    public static File getDbfFile(File shpFile){
182
    	String str = shpFile.getAbsolutePath();
183
		File directory=shpFile.getParentFile();
184
		MyFileFilter myFileFilter = new MyFileFilter(str);
185
		File[] files=directory.listFiles(myFileFilter);
186
		String[] ends=new String[] {"dbf","DBF","Dbf","dBf","DBf","dbF","DbF","dBF"};
187
		File dbfFile=findEnd(str,files,ends);
188
		return dbfFile;
189
    }
190
    public static File getShxFile(File shpFile){
191
    	String str = shpFile.getAbsolutePath();
192
		File directory=shpFile.getParentFile();
193
		MyFileFilter myFileFilter = new MyFileFilter(str);
194
		File[] files=directory.listFiles(myFileFilter);
195
		String[] ends=new String[] {"shx","SHX","Shx","sHx","SHx","shX","ShX","sHX"};
196
		File shxFile=findEnd(str,files,ends);
197
		return shxFile;
198
    } 
199
    private static File findEnd(String str,File[] files, String[] ends) {
200
    	for (int i=0;i<files.length;i++) {
201
			File dbfFile=files[i];
202
			if (dbfFile.getAbsolutePath().endsWith(ends[0]))
203
				return dbfFile;
204
		}
205
		for (int i=0;i<files.length;i++) {
206
			File dbfFile=files[i];
207
			if (dbfFile.getAbsolutePath().endsWith(ends[1]))
208
				return dbfFile;
209
		}
210
		for (int i=0;i<files.length;i++) {
211
			File dbfFile=files[i];
212
			if (dbfFile.getAbsolutePath().endsWith(ends[2]))
213
				return dbfFile;
214
		}
215
		for (int i=0;i<files.length;i++) {
216
			File dbfFile=files[i];
217
			if (dbfFile.getAbsolutePath().endsWith(ends[3]))
218
				return dbfFile;
219
		}
220
		for (int i=0;i<files.length;i++) {
221
			File dbfFile=files[i];
222
			if (dbfFile.getAbsolutePath().endsWith(ends[4]))
223
				return dbfFile;
224
		}
225
		for (int i=0;i<files.length;i++) {
226
			File dbfFile=files[i];
227
			if (dbfFile.getAbsolutePath().endsWith(ends[5]))
228
				return dbfFile;
229
		}
230
		for (int i=0;i<files.length;i++) {
231
			File dbfFile=files[i];
232
			if (dbfFile.getAbsolutePath().endsWith(ends[6]))
233
				return dbfFile;
234
		}
235
		for (int i=0;i<files.length;i++) {
236
			File dbfFile=files[i];
237
			if (dbfFile.getAbsolutePath().endsWith(ends[7]))
238
				return dbfFile;
239
		}
240
		return new File(str.substring(0, str.length() - 3) + ends[0]);
241
    }
242

  
182 243
}
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/MyFileFilter.java
1
package com.iver.cit.gvsig.fmap.drivers.shp;
2

  
3
import java.io.File;
4
import java.io.FileFilter;
5

  
6
public class MyFileFilter implements FileFilter {
7
	private String shpPath;
8
	public MyFileFilter(String shpPath){
9
		this.shpPath=shpPath;
10
	}
11
	public boolean accept(File pathname) {
12
		String strend=pathname.getAbsolutePath();
13
		strend=strend.substring(0,strend.length()-3);
14
		String strshp=shpPath.substring(0, shpPath.length() - 3);
15
		if (strend.equals(strshp)) {
16
			return true;
17
		}
18
		return false;
19
	}
20

  
21
}
0 22

  
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/shp/ShpWriter.java
17 17
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
18 18
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO;
19 19
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO;
20
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
20 21
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPFileWrite;
21 22
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException;
22 23
import com.iver.cit.gvsig.fmap.edition.EditionException;
......
68 69
	{
69 70
		shpPath = f.getAbsolutePath();
70 71

  
71
		String strFichshx = f.getAbsolutePath().replaceAll("\\.shp", ".shx");
72
		shxPath = strFichshx.replaceAll("\\.SHP", ".SHX");
72
		shxPath = SHP.getShxFile(f).getAbsolutePath();
73 73

  
74
		String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf");
75
		dbfPath = strFichDbf.replaceAll("\\.SHP", ".DBF");
74
		dbfPath = SHP.getDbfFile(f).getAbsolutePath();
76 75

  
77 76
		shpFile = f;
78 77
	}
branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/dbf/DbfWriter.java
13 13
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
14 14
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO;
15 15
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO;
16
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
16 17
import com.iver.cit.gvsig.fmap.edition.EditionException;
17 18
import com.iver.cit.gvsig.fmap.edition.IFieldManager;
18 19
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
......
40 41
	private FBitSet selection = null;
41 42

  
42 43
	private FieldDescription[] originalFields;
43
	
44

  
44 45
	public DbfWriter() {
45 46
		super();
46 47
		this.capabilities.setProperty("FieldNameMaxLength","10");
47 48
	}
48 49

  
49 50
	public void setFile(File f) {
50
		String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf");
51
		dbfPath = strFichDbf.replaceAll("\\.SHP", ".DBF");
51
		String absolutePath=f.getAbsolutePath();
52
		if (absolutePath.toUpperCase().endsWith("DBF")){
53
			dbfPath=absolutePath;
54
		} else {
55
			dbfPath = SHP.getDbfFile(f).getAbsolutePath();
56
		}
52 57
	}
53 58

  
54 59
	private WritableByteChannel getWriteChannel(String path) throws IOException {
......
221 226
	public void renameField(String antName, String newName) {
222 227
		RenameFieldCommand c = new RenameFieldCommand(antName, newName);
223 228
		fieldCommands.add(c);
224
		
229

  
225 230
	}
226 231

  
227 232
	public FieldDescription[] getFields() {
......
261 266
					}
262 267
				}
263 268

  
264
			}			
265
			
269
			}
270

  
266 271
		}
267 272
		return (FieldDescription[]) aux.toArray(new FieldDescription[0]);
268 273
	}
......
272 277
	}
273 278

  
274 279
	public boolean canSaveEdits() {
275
		File aux = new File(dbfPath);		
280
		File aux = new File(dbfPath);
276 281
		if (aux.canWrite()) return true;
277 282
		return false;
278 283
	}

Also available in: Unified diff