Revision 41059 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreParameters.java
CSVStoreParameters.java | ||
---|---|---|
36 | 36 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
37 | 37 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
38 | 38 |
import org.gvsig.tools.dynobject.DynObject; |
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
39 | 41 |
import org.supercsv.prefs.CsvPreference; |
40 | 42 |
import org.supercsv.quote.AlwaysQuoteMode; |
41 | 43 |
import org.supercsv.quote.NormalQuoteMode; |
... | ... | |
44 | 46 |
public class CSVStoreParameters extends AbstractDataParameters implements |
45 | 47 |
DataStoreParameters, FilesystemStoreParameters { |
46 | 48 |
|
49 |
private static final Logger logger = LoggerFactory.getLogger(CSVStoreParameters.class); |
|
50 |
|
|
47 | 51 |
public static final String PARAMETERS_DEFINITION_NAME = "CSVStoreParameters"; |
48 | 52 |
|
49 | 53 |
private static final String FILE = "file"; |
54 |
private static final String IGNOREERRORS = "ignoreErrors"; |
|
50 | 55 |
private static final String PROFILE = "profile"; |
51 | 56 |
private static final String QUOTEPOLICY = "quotePolicy"; |
52 | 57 |
private static final String QUOTECHAR = "quoteCharacter"; |
... | ... | |
222 | 227 |
|
223 | 228 |
private static String getDelimiter(String line) { |
224 | 229 |
String sep = null; |
225 |
String seps = ",;:-|@#/+$%&!"; |
|
230 |
// Cuiaddo con los ":", los he puesto al final a proposito |
|
231 |
// ya que podian estar en la cadena para separar el size |
|
232 |
// size de cada tipo. |
|
233 |
String seps = ",;-|@#/+$%&!:"; |
|
226 | 234 |
for( int i=0; i<seps.length(); i ++) { |
227 | 235 |
sep = seps.substring(i, 1); |
228 | 236 |
if( line.contains(seps.substring(i, 1))) { |
... | ... | |
258 | 266 |
return b.booleanValue(); |
259 | 267 |
} |
260 | 268 |
|
269 |
static boolean getIgnoreErrors(DynObject dynobj) { |
|
270 |
Boolean b = (Boolean) dynobj.getDynValue(IGNOREERRORS); |
|
271 |
if( b==null ) { |
|
272 |
return false; |
|
273 |
} |
|
274 |
return b.booleanValue(); |
|
275 |
} |
|
276 |
|
|
261 | 277 |
// static boolean getIgnoreEmptyLines(DynObject dynobj) { |
262 | 278 |
// Boolean b = (Boolean) dynobj.getDynValue(IGNOREEMPTYLINES); |
263 | 279 |
// return b.booleanValue(); |
... | ... | |
276 | 292 |
String fieldTypeNames[] = s.split("["+sep+"]"); |
277 | 293 |
int fieldTypes[] = new int[fieldTypeNames.length]; |
278 | 294 |
for( int i=0; i<fieldTypeNames.length; i++ ) { |
279 |
fieldTypes[i] = dataTypeManager.getType(fieldTypeNames[i].trim()); |
|
295 |
s = fieldTypeNames[i].trim(); |
|
296 |
if( s.contains(":") ) { |
|
297 |
s = s.split(":")[0]; |
|
298 |
} |
|
299 |
fieldTypes[i] = dataTypeManager.getType(s); |
|
280 | 300 |
} |
281 | 301 |
return fieldTypes; |
282 | 302 |
} |
283 | 303 |
|
304 |
static int[] getFieldSizes(DynObject dynobj) { |
|
305 |
String s = (String) dynobj.getDynValue(FIELDTYPES); |
|
306 |
if( isEmpty(s) ) { |
|
307 |
return null; |
|
308 |
} |
|
309 |
String sep = getDelimiter(s); |
|
310 |
if( sep == null ) { |
|
311 |
return null; |
|
312 |
} |
|
313 |
String fieldTypeNames[] = s.split("["+sep+"]"); |
|
314 |
int fieldSizes[] = new int[fieldTypeNames.length]; |
|
315 |
for( int i=0; i<fieldTypeNames.length; i++ ) { |
|
316 |
String fieldtype = fieldTypeNames[i].trim(); |
|
317 |
if( fieldtype .contains(":") ) { |
|
318 |
try { |
|
319 |
s = fieldtype .split(":")[1]; |
|
320 |
fieldSizes[i] = Integer.parseInt(s); |
|
321 |
} catch(Exception ex) { |
|
322 |
logger.warn("Can't get size of field "+i+" ("+fieldtype +").",ex); |
|
323 |
} |
|
324 |
} else { |
|
325 |
fieldSizes[i] = 0; |
|
326 |
} |
|
327 |
} |
|
328 |
return fieldSizes; |
|
329 |
} |
|
330 |
|
|
284 | 331 |
static private boolean isEmpty(String s) { |
285 | 332 |
if( s == null ) { |
286 | 333 |
return true; |
Also available in: Unified diff