Project

General

Profile

Download (2.17 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.dwca.out;
10

    
11
import java.io.IOException;
12
import java.io.InputStreamReader;
13
import java.net.URI;
14
import java.util.HashMap;
15
import java.util.Map;
16
import java.util.UUID;
17

    
18
import org.apache.log4j.Logger;
19

    
20
import au.com.bytecode.opencsv.CSVReader;
21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.config.ConfigFileUtil;
23

    
24
/**
25
 * @author a.mueller
26
 * @since 03.05.2011
27
 *
28
 */
29
public class TermMapping {
30
	@SuppressWarnings("unused")
31
	private static Logger logger = Logger.getLogger(TermMapping.class);
32

    
33
	private static final String COMMENT = "//";
34

    
35
	private UUID uuidCdmVoc;
36
	private URI externalVoc;
37
	private char separator = '\t'; //'\u0009';  //horizontal tab
38

    
39
	private Map<UUID, String> mappingMap = new HashMap<>();
40

    
41

    
42
	public TermMapping(String filename) throws IOException{
43
		readMapping(filename);
44
	}
45

    
46

    
47
	private void readMapping(String filename) throws IOException {
48
		String strResourceFileName = "mapping" + ConfigFileUtil.getFolderSeperator() + filename;
49
		InputStreamReader isr = CdmUtils.getUtf8ResourceReader(strResourceFileName);
50
		CSVReader reader = new CSVReader(isr, separator);
51

    
52
		String [] nextLine = reader.readNext();
53
		uuidCdmVoc = UUID.fromString(nextLine[0]);
54
		externalVoc = URI.create(nextLine[1]);
55

    
56
		while ((nextLine = reader.readNext()) != null) {
57
			// nextLine[] is an array of values from the line
58
			if (nextLine.length == 0){
59
				continue;
60
			}
61
			readMappingLine(nextLine);
62

    
63
		}
64
	}
65

    
66
	private void readMappingLine(String[] mappingLine) {
67
		if (! mappingLine[0].startsWith(COMMENT)){
68
			UUID uuidCdm = UUID.fromString(mappingLine[0]);
69
			String externalTerm = mappingLine[1].trim();
70
			mappingMap.put(uuidCdm, externalTerm);
71
		}
72
	}
73

    
74
	public String getTerm(UUID key){
75
		return mappingMap.get(key);
76
	}
77

    
78
	public URI getExternalVoc(){
79
		return externalVoc;
80
	}
81

    
82
	public UUID getCdmVoc(){
83
		return uuidCdmVoc;
84
	}
85
}
(33-33/33)