Project

General

Profile

« Previous | Next » 

Revision 531fc7bc

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib (except for cdmlib-model) #5830

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaEmlExport.java
1 1
/**
2 2
* Copyright (C) 2007 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
*/
......
39 39
	private static final Logger logger = Logger.getLogger(DwcaEmlExport.class);
40 40

  
41 41
	private static final String fileName = "eml.xml";
42
	
42

  
43 43
	String emlNamespace = "eml://ecoinformatics.org/eml-2.1.1";
44 44
	String mdNamespace="eml://ecoinformatics.org/methods-2.1.0";
45 45
	String projNamespace="eml://ecoinformatics.org/project-2.1.0";
......
70 70
		metaRecord.setMetaData(true);
71 71
		state.addMetaRecord(metaRecord);
72 72

  
73
		
73

  
74 74
		DwcaEmlRecord emlRecord = config.getEmlRecord();
75 75
		if (emlRecord == null){
76 76
			return;
77 77
		}
78
		
78

  
79 79
		XMLStreamWriter writer = null;
80 80
		try {
81 81
			writer = createXmlStreamWriter(state, fileName);
82
			
82

  
83 83
			String rootName = "eml";
84
			
85
			// create header 
84

  
85
			// create header
86 86
			//TODO encoding
87
			writer.writeStartDocument(); 
87
			writer.writeStartDocument();
88 88
//			writer.setDefaultNamespace(rootNamespace);
89
			
90
				// create root element 
89

  
90
				// create root element
91 91
//				writer.setPrefix("eml",emlNamespace);
92 92
				writer.writeStartElement("eml", rootName, emlNamespace);
93 93
				writer.writeNamespace("eml", emlNamespace);
......
97 97
				writer.writeNamespace("res", resNamespace);
98 98
				writer.writeNamespace("dc", dcNamespace);
99 99
				writer.writeNamespace("xsi", xsiNamespace);
100
				
100

  
101 101
				writer.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", schemaLocation);
102 102
				writer.writeAttribute("packageId", emlRecord.getIdentifier());
103 103
				writer.writeAttribute("system", "CDM Library Darwin Core Archive Exporter");
104 104
				writer.writeAttribute("scope", "system");
105
				
105

  
106 106
				if (emlRecord.getMetaDataLanguage() != null ){
107 107
					writer.writeAttribute("xml", "lang", emlRecord.getMetaDataLanguage().getIso639_2()); //TODO needed ?
108 108
				}
109
				
109

  
110 110
				writeDataSet(writer, config, emlRecord);
111 111
				writeAdditionalMetadata(writer, config, emlRecord);
112 112
				writer.flush();
113
				writer.writeEndElement(); 
114
			writer.writeEndDocument(); 
113
				writer.writeEndElement();
114
			writer.writeEndDocument();
115 115
			writer.flush();
116 116
			writer.close();
117 117
		} catch (FileNotFoundException e) {
......
127 127
		}  finally{
128 128
			closeWriter(writer, state);
129 129
		}
130
		
130

  
131 131
		return;
132 132
	}
133 133

  
......
136 136
		writer.writeStartElement("additionalMetadata");
137 137
		writer.writeStartElement("metadata");
138 138
		writer.writeStartElement("gbif");
139
		
139

  
140 140
			String elementName;
141 141
			String text;
142
			
142

  
143 143
			elementName = "dateStamp";
144 144
			text = new DateTime().toString();
145 145
			writeTextElement(writer, elementName, text);
146
			
146

  
147 147
			elementName = "citation";
148 148
			text = emlRecord.getExpectedCitation();
149 149
			writeTextElement(writer, elementName, text);
150
			
150

  
151 151
			writer.writeStartElement("bibliography");
152
			for (Reference<?> ref: emlRecord.getReferences()){
152
			for (Reference ref: emlRecord.getReferences()){
153 153
				elementName = "citation";
154 154
				text = ref.getTitleCache();
155 155
				writeTextElement(writer, elementName, text);
156 156
			}
157 157
			writer.writeEndElement();
158
			
159
			
160
		writer.writeEndElement();	//gbif	
158

  
159

  
160
		writer.writeEndElement();	//gbif
161 161
		writer.writeEndElement();	//metadata
162 162
		writer.writeEndElement();	//additionalMetadata
163
		
163

  
164 164
	}
165 165

  
166 166
	private void writeDataSet(XMLStreamWriter writer,
167 167
			DwcaTaxExportConfigurator config, DwcaEmlRecord emlRecord) throws XMLStreamException {
168
		
169
		
168

  
169

  
170 170
		writer.writeStartElement("dataset");
171
			
171

  
172 172
			String elementName;
173 173
			String text;
174
			
174

  
175 175
			elementName = "alternateIdentifier";
176 176
			text = null;
177 177
			writeTextElement(writer, elementName, text);
178 178

  
179
		
179

  
180 180
			elementName = "title";
181 181
			text = emlRecord.getTitle();
182 182
			//TODO language attribute
183 183
			writeTextElement(writer, elementName, text);
184
			
184

  
185 185
			//creator
186 186
			writer.writeStartElement("creator");
187 187
				writePerson(writer, emlRecord.getResourceCreator());
188 188
			writer.writeEndElement();
189
			
189

  
190 190
			//metadataProvider
191 191
			writer.writeStartElement("metadataProvider");
192 192
				writePerson(writer, emlRecord.getResourceCreator());
193 193
			writer.writeEndElement();
194
			
194

  
195 195
			//associatedParty
196 196
			for (InstitutionalMembership author : emlRecord.getAuthors()){
197 197
				writer.writeStartElement("associatedParty");
198 198
					writePerson(writer, author);
199 199
				writer.writeEndElement();
200
				
200

  
201 201
			}
202
			
202

  
203 203
			DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("YYYY-MM-dd");
204 204
			elementName = "pubDate";
205 205
			text = emlRecord.getPublicationDate().toString(dateFormatter);
206 206
			writeTextElement(writer, elementName, text);
207
			
207

  
208 208
			elementName = "language";
209 209
			//TODO
210 210
			text = emlRecord.getResourceLanguage()== null? null:emlRecord.getResourceLanguage().getLabel() ;
......
225 225
				text = emlRecord.getKeywordThesaurus();
226 226
				writeTextElement(writer, elementName, text);
227 227
			writer.writeEndElement();
228
			
228

  
229 229
			//TODO taxonomic keywords
230
			
230

  
231 231
			//additional Info //TODO para ?
232 232
			elementName = "additionalInfo";
233 233
			text = emlRecord.getAdditionalInformation();
234 234
			writeTextElement(writer, elementName, text);
235
			
235

  
236 236
			//TODO intellectualRights
237 237
//			elementName = "intellectualRights";
238 238
//			text = emlRecord.getRights(rights);
239 239
//			writeParaTextElement
240
			
240

  
241 241
			//TODO distribution //TODO online
242 242
			writer.writeStartElement("distribution");
243 243
				writer.writeAttribute("scope", "document");
......
248 248
					writer.writeEndElement();
249 249
				writer.writeEndElement(); //online
250 250
			writer.writeEndElement(); //distribution
251
			
251

  
252 252
			//TODO coverage
253 253
			writeCoverage(writer, emlRecord);
254
			
254

  
255 255
			//contact
256 256
			writer.writeStartElement("contact");
257 257
				writePerson(writer, emlRecord.getContact());
......
274 274
					elementName = "role";
275 275
					text = "Distributor";
276 276
					writeTextElement(writer, elementName, text);
277
				
277

  
278 278
				writer.writeEndElement();
279 279

  
280
				
280

  
281 281
				writer.writeStartElement("funding");
282 282
				writer.writeEndElement();
283
				
283

  
284 284
				writer.writeStartElement("studyAreaDescription");
285 285
					writer.writeStartElement("descriptor");
286
					
286

  
287 287
					elementName = "descriptorValue";
288 288
					text = emlRecord.getProjectDescription();
289 289
					writeTextElement(writer, elementName, text);
290
					
290

  
291 291
					writer.writeEndElement();
292 292
				writer.writeEndElement();
293
				
293

  
294 294
				writer.writeStartElement("designDescription");
295 295
				writer.writeEndElement();
296
			
296

  
297 297
		writer.writeEndElement();
298 298
	}
299 299

  
......
322 322
		String elementName;
323 323
		String text;
324 324
		writer.writeStartElement("geographicCoverage");
325
		
325

  
326 326
			//geographic description
327 327
			elementName = "geographicDescription";
328 328
			text = emlRecord.getRegionalScope();
329 329
			writeTextElement(writer, elementName, text);
330
			
330

  
331 331
			//boundingCoordinates
332 332
			writer.writeStartElement("boundingCoordinates");
333 333
				if (emlRecord.getUpperLeftCorner() != null){
......
336 336
					text = emlRecord.getUpperLeftCorner().getLatitude().toString();
337 337
					writeTextElement(writer, elementName, text);
338 338
				}
339
				
339

  
340 340
				if (emlRecord.getLowerRightCorner() != null){
341 341
					//east
342 342
					elementName = "eastBoundingCoordinate";
343 343
					text = emlRecord.getLowerRightCorner().getLatitude().toString();
344 344
					writeTextElement(writer, elementName, text);
345 345
				}
346
				
346

  
347 347
				if (emlRecord.getUpperLeftCorner() != null){
348 348
					//north
349 349
					elementName = "northBoundingCoordinate";
......
357 357
					writeTextElement(writer, elementName, text);
358 358
				}
359 359
			writer.writeEndElement(); //boundingCoordinates
360
		
360

  
361 361
		writer.writeEndElement(); //geographicCoverage
362 362
	}
363 363

  
......
368 368
	 */
369 369
	private void handleTermporalCoverage(XMLStreamWriter writer,
370 370
			DwcaEmlRecord emlRecord) throws XMLStreamException {
371
		
371

  
372 372
		TimePeriod timePeriod = emlRecord.getDate();
373 373
		if (timePeriod == null){
374 374
			return;
375 375
		}
376
		
376

  
377 377
		writer.writeStartElement("termporalCoverage");
378 378
			if (! timePeriod.isPeriod()){
379 379
				//singleDateTime
......
391 391
					writer.writeEndElement();
392 392
				writer.writeEndElement();
393 393
			}
394
		
395
			
396
			
394

  
395

  
396

  
397 397
		writer.writeEndElement(); //termporalCoverage
398 398
	}
399 399

  
400
	
400

  
401 401
	private void writeCalendarDate(XMLStreamWriter writer, Partial partial) throws XMLStreamException {
402 402
		//calendarDate
403 403
		String elementName = "calendarDate";
404 404
		//FIXME must be something like 37723
405 405
		String text = partial.toDateTime(new DateTime()).toString();
406 406
		writeTextElement(writer, elementName, text);
407
		
407

  
408 408
	}
409 409

  
410 410
	private String nullSafe(Object object) {
......
417 417
		if (member == null){
418 418
			return ;
419 419
		}
420
		
420

  
421 421
		writer.writeStartElement("individualName");
422 422
		if (member.getPerson() != null){
423 423
			Person person = member.getPerson();
424
			
424

  
425 425
			elementName = "givenName";
426 426
			text = person.getFirstname();
427 427
			writeTextElement(writer, elementName, text);
......
429 429
			elementName = "surName";
430 430
			text = person.getLastname();
431 431
			writeTextElement(writer, elementName, text);
432
			
432

  
433 433
		}
434 434
		writer.writeEndElement();
435 435

  
......
437 437
		text = member.getInstitute()== null? null: member.getInstitute().getTitleCache();
438 438
		writeTextElement(writer, elementName, text);
439 439

  
440
		
440

  
441 441
		if (member.getPerson() != null && member.getPerson().getContact()!= null){
442 442
			Contact contact = member.getPerson().getContact();
443
			
443

  
444 444
			if (contact.getAddresses().size() > 0){
445 445
				writer.writeStartElement("address");
446
			
446

  
447 447
				//TODO empty
448 448
				Address address = contact.getAddresses().iterator().next();
449
				
449

  
450 450
				elementName = "deliveryPoint";
451 451
				text = address.getStreet();
452 452
				writeTextElement(writer, elementName, text);
453
	
453

  
454 454
				elementName = "city";
455 455
				text = address.getLocality();
456 456
				writeTextElement(writer, elementName, text);
457
	
457

  
458 458
				elementName = "administrativeArea";
459 459
				text = address.getRegion();
460 460
				writeTextElement(writer, elementName, text);
461
	
461

  
462 462
				elementName = "postalCode";
463 463
				text = address.getPostcode();
464 464
				writeTextElement(writer, elementName, text);
465
				
465

  
466 466
				elementName = "country";
467 467
				text = address.getCountry()== null? null: address.getCountry().getLabel();
468 468
				writeTextElement(writer, elementName, text);
469
				
469

  
470 470
				writer.writeEndElement();   //address
471 471
			}
472 472

  
473 473
			elementName = "phone";
474
			text = firstOfList(contact.getPhoneNumbers()); 
474
			text = firstOfList(contact.getPhoneNumbers());
475 475
			writeTextElement(writer, elementName, text);
476
			
476

  
477 477
			elementName = "electronicMailAddress";
478 478
			text = firstOfList(contact.getEmailAddresses());
479 479
			writeTextElement(writer, elementName, text);
480 480

  
481 481
			elementName = "onlineUrl";
482
			text = firstOfList(contact.getPhoneNumbers()); 
482
			text = firstOfList(contact.getPhoneNumbers());
483 483
			writeTextElement(writer, elementName, text);
484 484

  
485
			
485

  
486 486
		}
487 487
	}
488 488

  
......
522 522
	protected boolean isIgnore(DwcaTaxExportState state) {
523 523
		return ! state.getConfig().isDoEml();
524 524
	}
525
	
525

  
526 526
}

Also available in: Unified diff