Skip to content

Package: MappingFileParser

MappingFileParser

nameinstructionbranchcomplexitylinemethod
MappingFileParser(Map)
M: 4 C: 49
92%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 10
100%
M: 0 C: 1
100%
getMappings()
M: 32 C: 71
69%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 5 C: 14
74%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.ontodriver.owlapi.util;
2:
3: import cz.cvut.kbss.ontodriver.owlapi.config.OwlapiOntoDriverProperties;
4: import cz.cvut.kbss.ontodriver.owlapi.exception.MappingFileParserException;
5:
6: import java.io.BufferedReader;
7: import java.io.File;
8: import java.io.FileReader;
9: import java.io.IOException;
10: import java.net.URI;
11: import java.util.HashMap;
12: import java.util.Map;
13: import java.util.StringTokenizer;
14: import java.util.logging.Logger;
15:
16: public class MappingFileParser {
17:
18: private static final Logger LOG = Logger.getLogger(MappingFileParser.class.getName());
19:
20: private final File mappingFile;
21:
22: private final String delimiter;
23:
24: public MappingFileParser(Map<String, String> properties) {
25: final String mappingFilePath = properties.get(OwlapiOntoDriverProperties.MAPPING_FILE_LOCATION);
26:• assert mappingFilePath != null;
27: this.mappingFile = new File(mappingFilePath);
28:• if (!mappingFile.exists()) {
29: throw new MappingFileParserException("Mapping file " + mappingFilePath + " does not exist.");
30: }
31:• if (properties.containsKey(OwlapiOntoDriverProperties.IRI_MAPPING_DELIMITER)) {
32: this.delimiter = properties.get(OwlapiOntoDriverProperties.IRI_MAPPING_DELIMITER);
33: } else {
34: this.delimiter = OwlapiOntoDriverProperties.DEFAULT_IRI_MAPPING_DELIMITER;
35: }
36: }
37:
38: public Map<URI, URI> getMappings() {
39: final Map<URI, URI> map = new HashMap<>();
40: String line;
41: final File defaultDir = mappingFile.getParentFile();
42: try (final BufferedReader r = new BufferedReader(new FileReader(mappingFile))) {
43:• while ((line = r.readLine()) != null) {
44: final StringTokenizer t = new StringTokenizer(line, delimiter);
45:• if (t.countTokens() != 2) {
46: LOG.warning("Ignoring line '" + line + "' - invalid number of tokens = " + t.countTokens());
47: continue;
48: }
49: final String uriName = t.nextToken().trim();
50: final String fileName = t.nextToken().trim();
51: final File actualFile =
52:• (new File(fileName).isAbsolute()) ? new File(fileName) : new File(defaultDir, fileName);
53:
54: map.put(URI.create(uriName), actualFile.toURI());
55: }
56: } catch (IOException e) {
57: LOG.severe("Unable to parse mapping file." + e);
58: throw new MappingFileParserException(e);
59: }
60: return map;
61: }
62: }