Skip to content

Commit 897c21d

Browse files
committed
Unify URI identification logic for RDF maps. (#229)
1 parent dc9e63d commit 897c21d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void apply(final Metafix metafix, final Record record, final List<String>
9999
final String fileName = params.get(0);
100100
final RdfMap rdfMap = new RdfMap();
101101

102-
rdfMap.setResource(fileName.startsWith("http") ? fileName : metafix.resolvePath(fileName));
102+
rdfMap.setResource(fileName, metafix::resolvePath);
103103

104104
withOption(options, RdfMap.TARGET, rdfMap::setTarget);
105105
withOption(options, RdfMap.TARGET_LANGUAGE, rdfMap::setTargetLanguage);

metafix/src/main/java/org/metafacture/metafix/maps/RdfMap.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.HashMap;
4141
import java.util.Map;
4242
import java.util.NoSuchElementException;
43+
import java.util.function.UnaryOperator;
4344

4445
/**
4546
* Provides a dynamically build {@link Map} based on an RDF resource. Can be one file or a comma separated list of RDF
@@ -78,9 +79,13 @@ public RdfMap() {
7879

7980
}
8081

82+
private boolean isURI(final String name) {
83+
return name.toLowerCase().startsWith("http");
84+
}
85+
8186
private void init() {
8287
loadFiles();
83-
if (!target.toLowerCase().startsWith("http")) {
88+
if (!isURI(target)) {
8489
final String[] nsPrefixAndProperty = target.split(":");
8590
target = nsPrefixAndProperty.length == 2 ? model.getNsPrefixURI(nsPrefixAndProperty[0]) + nsPrefixAndProperty[1] : nsPrefixAndProperty[0];
8691
}
@@ -102,7 +107,17 @@ public void setFiles(final String files) {
102107
* @param file the file
103108
*/
104109
public void setResource(final String file) {
105-
Collections.addAll(filenames, file);
110+
filenames.add(file);
111+
}
112+
113+
/**
114+
* Sets a file or URI which provides the {@link Model}.
115+
*
116+
* @param file the file or URI
117+
* @param operator an operator to apply to the file
118+
*/
119+
public void setResource(final String file, final UnaryOperator<String> operator) {
120+
setResource(isURI(file) ? file : operator.apply(file));
106121
}
107122

108123
private void loadFiles() {
@@ -112,7 +127,7 @@ private void loadFiles() {
112127
private void loadFile(final String file) {
113128
String f = file;
114129
try {
115-
if (file.toLowerCase().startsWith("http")) {
130+
if (isURI(file)) {
116131
f = read(file);
117132
}
118133
if (model == null) {

0 commit comments

Comments
 (0)