Project

General

Profile

« Previous | Next » 

Revision 2720ea2c

Added by Andreas Müller over 3 years ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/csv/redlist/out/CsvRecordBaseRedlist.java
1 1
/**
2 2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
45 45

  
46 46
/**
47 47
 * @author a.mueller
48
 * @since 20.04.2011
49
 *
50
 */
51
/**
52 48
 * @author alex
53
 *
49
 * @since 20.04.2011
54 50
 */
55 51
public abstract class CsvRecordBaseRedlist {
52

  
56 53
	private static final Logger logger = Logger.getLogger(CsvRecordBaseRedlist.class);
57 54

  
58 55
	//TODO Collection_SEPARATOR
......
61 58
	protected static final boolean IS_FIRST = false;
62 59
	protected static final boolean IS_NOT_FIRST = true;
63 60
//	protected static final String SEP = ",";
64
	
61

  
65 62
	protected Map<String, URI> knownFields = new HashMap<String, URI>();
66 63
	protected Set<TermUri> knownTermFields = new HashSet<TermUri>();
67
	
64

  
68 65
	public abstract void write(PrintWriter writer);
69 66
	protected abstract void registerKnownFields();
70
	
67

  
71 68
	protected int count;
72 69
	private CsvMetaDataRecordRedlist metaDataRecord;
73 70
	protected CsvTaxExportConfiguratorRedlist config;
......
75 72
	private Integer id;
76 73
	private UUID uuid;
77 74

  
78
	
79 75
	protected CsvRecordBaseRedlist(CsvMetaDataRecordRedlist metaDataRecord, CsvTaxExportConfiguratorRedlist config){
80 76
		this.metaDataRecord = metaDataRecord;
81 77
		this.count = metaDataRecord.inc();
82 78
		this.config = config;
83 79
	}
84
	
85
	
80

  
86 81
	public void setId(Integer id) {
87 82
		this.id = id;
88 83
	}
......
107 102
		String value = null;
108 103
		print(value, writer, addSeparator, fieldKey);
109 104
	}
110
	
105

  
111 106
//	protected void print(Object object, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
112 107
//		print(object == null ? null : object.toString(), writer, addSeparator, fieldKey);
113 108
//	}
......
124 119
		print(agent == null ? null : getAgent(agent), writer, addSeparator, fieldKey);
125 120
	}
126 121

  
127
	
128 122
	protected void print(Language language, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
129 123
		print(language, writer, addSeparator, fieldKey.getUriString());
130 124
	}
......
137 131
	protected void print(LSID lsid, PrintWriter writer, boolean addSeparator, String fieldKey) {
138 132
		print(lsid == null ? null : String.valueOf(lsid.toString()), writer, addSeparator, fieldKey);
139 133
	}
140
	
134

  
141 135
	protected void print(Set<Rights> rights, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
142 136
		print(rights, writer, addSeparator, fieldKey.getUriString());
143 137
	}
......
151 145
	protected void print(URI uri, PrintWriter writer, boolean addSeparator, String fieldKey) {
152 146
		print(uri == null ? null : String.valueOf(uri), writer, addSeparator, fieldKey);
153 147
	}
154
	
148

  
155 149
	protected void print(Point point, PrintWriter writer, boolean addSeparator, TermUri latitudeKey, TermUri longitudeKey) {
156 150
		print(point, writer, addSeparator, latitudeKey.getUriString(), longitudeKey.getUriString());
157 151
	}
158
	
152

  
159 153
	protected void print(Point point, PrintWriter writer, boolean addSeparator, String latitudeKey, String longitudeKey) {
160 154
		if (point == null){
161 155
			String toPrint = null;
......
170 164
	}
171 165
	protected void print(Boolean boolValue, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
172 166
		print(boolValue, writer, addSeparator, fieldKey.getUriString());
173
	}	
167
	}
174 168
	protected void print(Boolean boolValue, PrintWriter writer, boolean addSeparator, String fieldKey) {
175 169
		print(boolValue == null ? null : String.valueOf(boolValue), writer, addSeparator, fieldKey);
176 170
	}
......
181 175
	protected void print(Integer intValue, PrintWriter writer, boolean addSeparator, String fieldKey) {
182 176
		print(intValue == null ? null : String.valueOf(intValue), writer, addSeparator, fieldKey);
183 177
	}
184
	
178

  
185 179
	protected void printId(Integer intValue, PrintWriter writer, boolean addSeparator, String fieldKey) {
186 180
		print(intValue == null ? null : String.valueOf(intValue), writer, addSeparator, fieldKey);
187 181
	}
......
196 190
	protected void print(String value, PrintWriter writer, boolean addSeparator, TermUri fieldKey, String defaultValue) {
197 191
		print(value, writer, addSeparator, fieldKey.getUriString(), defaultValue);
198 192
	}
199
	
193

  
200 194
	protected void print(String value, PrintWriter writer, boolean addSeparator, String fieldKey) {
201 195
		print(value, writer, addSeparator, fieldKey, null);
202 196
	}
203
	
197

  
204 198
	protected void print(String value, PrintWriter writer, boolean addSeparator, String fieldKey, String defaultValue) {
205 199
		if (count == 1 && addSeparator == IS_NOT_FIRST){
206 200
			registerFieldKey(URI.create(fieldKey), defaultValue);
......
210 204
			if (StringUtils.isNotBlank(value)){
211 205
				//Replace quotes by double quotes
212 206
				value = value.replace("\"", "\"\"");
213
				
207

  
214 208
				value = value.replace(config.getLinesTerminatedBy(), "\\r");
215
				
209

  
216 210
				//replace all line brakes according to best practices: http://code.google.com/p/gbif-ecat/wiki/BestPractices
217 211
				value = value.replace("\r\n", "\\r");
218 212
				value = value.replace("\r", "\\r");
219 213
				value = value.replace("\n", "\\r");
220
				
214

  
221 215
				strToPrint += config.getFieldsEnclosedBy() + value + config.getFieldsEnclosedBy();
222 216
			}
223 217
			writer.print(strToPrint);
224 218
		}
225 219
	}
226
	
220

  
227 221
	/**
228 222
	 * @param writer
229 223
	 * @param list
......
245 239
	 * @param list
246 240
	 * @param termUri
247 241
	 * @param writer
248
	 * 
242
	 *
249 243
	 * Method for concatenating strings, especially for the red list use case
250 244
	 */
251 245
	protected void print(ArrayList<String> list, TermUri termUri, PrintWriter writer){
......
266 260
					print(element, writer, IS_FIRST, termUri);
267 261
					writer.write(",");
268 262
					logger.info(element);
269
					
263

  
270 264
				}
271 265
			}
272 266
		}
273 267
	}
274
	
275
	
268

  
269

  
276 270
	private void registerFieldKey(URI key, String defaultValue) {
277 271
		this.metaDataRecord.addFieldEntry(key, defaultValue);
278 272
	}
279 273

  
280
	
274

  
281 275
	protected String getRights(Rights rights) {
282 276
		if (rights == null){
283 277
			return "";
......
339 333
			return result;
340 334
		}
341 335
	}
342
	
336

  
343 337
	protected String getSex(DefinedTerm sex) {
344 338
		String result = CsvTaxExportTransformerRedlist.transformToGbifSex(sex);
345 339
		if (result == null){
......
352 346
			return result;
353 347
		}
354 348
	}
355
	
349

  
356 350
	protected String getLifeStage(DefinedTerm stage) {
357 351
		String result = CsvTaxExportTransformerRedlist.transformToGbifLifeStage(stage);
358 352
		if (result == null){
......
378 372
			return result;
379 373
		}
380 374
	}
381
	
375

  
382 376
	protected String getEstablishmentMeans(PresenceAbsenceTerm status) {
383 377
		String result = CsvTaxExportTransformerRedlist.transformToGbifEstablishmentMeans(status);
384 378
		if (result == null){
......
392 386
		}
393 387
	}
394 388

  
395
	
396
	
389

  
390

  
397 391
	protected String getAgent(AgentBase<?> agent) {
398 392
		if (agent == null){
399 393
			return "";
......
402 396
			return agent.getTitleCache();
403 397
		}
404 398
	}
405
	
399

  
406 400

  
407 401
	protected String getFeature(Feature feature) {
408 402
		if (feature == null){
......
413 407
		}
414 408
	}
415 409

  
416
	
410

  
417 411
	protected String getTimePeriod(TimePeriod period) {
418 412
		if (period == null){
419 413
			return "";
......
422 416
			return period.toString();
423 417
		}
424 418
	}
425
	
419

  
426 420
	protected String getTimePeriodPart(TimePeriod period, boolean useEnd) {
427 421
		if (period == null){
428 422
			return "";
......
451 445
			return result;
452 446
		}
453 447
	}
454
	
448

  
455 449

  
456 450
	protected String getDesignationType(TypeDesignationStatusBase<?> status) {
457 451
		if (status == null){
......
471 465
			return result;
472 466
		}
473 467
	}
474
	
475
	
468

  
476 469
	protected void addKnownField(String string, String uri) throws URISyntaxException {
477 470
		this.knownFields.put(string, new URI(uri));
478 471
	}
479
	
480
	protected void addKnownField(TermUri term) throws URISyntaxException {
472

  
473
	protected void addKnownField(TermUri term) {
481 474
		this.knownTermFields.add(term);
482 475
	}
483
}

476
}

Also available in: Unified diff