Revision 43245 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/DBFFeatureWriter.java

View differences:

DBFFeatureWriter.java
37 37
import org.gvsig.fmap.dal.feature.Feature;
38 38
import org.gvsig.fmap.dal.feature.FeatureType;
39 39
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeNotSuportedException;
40
import org.gvsig.fmap.dal.store.dbf.utils.DbaseCodepage;
40 41
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFileHeader;
41 42
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFileWriter;
42 43

  
......
55 56
	public void begin(DBFStoreParameters storeParameters,
56 57
			FeatureType featureType, long numRows) throws DataException {
57 58

  
58
		// TODO if is new set the langID
59
		String charset = storeParameters.getEffectiveEncodingName();	
60
		if (charset==null) {
61
			// set a safe encoding in case none has been defined
62
			charset = "UTF-8";
63
		}
59 64
		try {
60
			myHeader = DbaseFileHeader.createDbaseHeader(featureType);
65
			
66
			myHeader = DbaseFileHeader.createDbaseHeader(featureType, charset);
61 67
		} catch (AttributeFeatureTypeNotSuportedException e1) {
62 68
			throw new WriteException(this.name, e1);
63 69
		}
64 70

  
65 71
		dbfFile = storeParameters.getDBFFile();
72
		
73
		// .cpg will be redundant if LDID was already set, but we still
74
		// want to write it with the hopes of increasing the range of programs
75
		// that will correctly interpret the charset
76
		DbaseCodepage cpWriter = new DbaseCodepage(dbfFile);
77
		cpWriter.write(charset);
66 78

  
67 79
		dbfChannel = null;
68 80

  
......
74 86
		}
75 87
		try{
76 88
			this.dbfWriter = new DbaseFileWriter(myHeader, dbfChannel, true);
77

  
78

  
79
			this.dbfWriter.setCharset(Charset.forName("ISO-8859-1"));
80 89
			} catch (InitializeException e) {
81 90
				throw new WriteException(this.name, e);
82 91
			}
......
108 117
		File f = new File(path);
109 118

  
110 119
		if (!f.exists()) {
111
			//			System.out.println("Creando fichero " + f.getAbsolutePath());
112

  
113 120
			if (!f.createNewFile()) {
114 121
				System.err.print("Error al crear el fichero "
115 122
						+ f.getAbsolutePath());

Also available in: Unified diff