Skip to content

Commit

Permalink
Merge pull request #439 from bennofs/fix-rdf-commons-url
Browse files Browse the repository at this point in the history
Encode URIs in RDF serialization of commons media
  • Loading branch information
Tpt committed Sep 4, 2019
2 parents b1bd154 + e4e281f commit 1a895fc
Showing 1 changed file with 17 additions and 4 deletions.
Expand Up @@ -28,6 +28,10 @@
import org.wikidata.wdtk.rdf.PropertyRegister;
import org.wikidata.wdtk.rdf.RdfWriter;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class StringValueConverter extends AbstractValueConverter<StringValue> {

public StringValueConverter(RdfWriter rdfWriter,
Expand Down Expand Up @@ -97,13 +101,22 @@ public Value getRdfValue(StringValue value,
* @return URL of the page
*/
static String getCommonsFileUrl(String pageName) {
return "http://commons.wikimedia.org/wiki/File:"
+ pageName.replace(' ', '_');
try {
return "http://commons.wikimedia.org/wiki/File:"
+ URLEncoder.encode(pageName.replace(' ', '_'), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
// can't happen
throw new IllegalStateException(e);
}
}

static String getCommonsDataUrl(String pageName) {
return "http://commons.wikimedia.org/data/main/"
+ pageName.replace(' ', '_');
try {
return "http://commons.wikimedia.org/data/main/"
+ URLEncoder.encode(pageName.replace(' ', '_'), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}

}

0 comments on commit 1a895fc

Please sign in to comment.