2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.io
.dwca
.out
;
11 import java
.io
.IOException
;
12 import java
.io
.InputStreamReader
;
13 import eu
.etaxonomy
.cdm
.common
.URI
;
14 import java
.util
.HashMap
;
16 import java
.util
.UUID
;
18 import org
.apache
.logging
.log4j
.LogManager
;import org
.apache
.logging
.log4j
.Logger
;
20 import au
.com
.bytecode
.opencsv
.CSVReader
;
21 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
28 public class TermMapping
{
29 @SuppressWarnings("unused")
30 private static Logger logger
= LogManager
.getLogger(TermMapping
.class);
32 private static final String COMMENT
= "//";
34 private UUID uuidCdmVoc
;
35 private URI externalVoc
;
36 private char separator
= '\t'; //'\u0009'; //horizontal tab
38 private Map
<UUID
, String
> mappingMap
= new HashMap
<>();
41 public TermMapping(String filename
) throws IOException
{
42 readMapping(filename
);
46 private void readMapping(String filename
) throws IOException
{
47 String strResourceFileName
= "mapping/" + filename
;
48 InputStreamReader isr
= CdmUtils
.getUtf8ResourceReader(strResourceFileName
);
49 CSVReader reader
= new CSVReader(isr
, separator
);
51 String
[] nextLine
= reader
.readNext();
52 uuidCdmVoc
= UUID
.fromString(nextLine
[0]);
53 externalVoc
= URI
.create(nextLine
[1]);
55 while ((nextLine
= reader
.readNext()) != null) {
56 // nextLine[] is an array of values from the line
57 if (nextLine
.length
== 0){
60 readMappingLine(nextLine
);
65 private void readMappingLine(String
[] mappingLine
) {
66 if (! mappingLine
[0].startsWith(COMMENT
)){
67 UUID uuidCdm
= UUID
.fromString(mappingLine
[0]);
68 String externalTerm
= mappingLine
[1].trim();
69 mappingMap
.put(uuidCdm
, externalTerm
);
73 public String
getTerm(UUID key
){
74 return mappingMap
.get(key
);
77 public URI
getExternalVoc(){
81 public UUID
getCdmVoc(){