Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions dspace-oai/src/main/java/org/dspace/utils/LangUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

/* Created for LINDAT/CLARIAH-CZ (UFAL) */
package org.dspace.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

/**
* Class is copied from the LINDAT/CLARIAH-CZ (This class is taken from UFAL-clarin.
* <a href="https://github.com/ufal/clarin-dspace/blob/clarin
* /dspace-oai/src/main/java/cz/cuni/mff/ufal/utils/LangUtil.java">...</a>) and modified by
*
* @author Marian Berger (dspace at dataquest.sk)
*/
public class LangUtil {

private LangUtil() {}
private static org.apache.log4j.Logger log = org.apache.log4j.Logger
.getLogger(LangUtil.class);

static final HashMap<String, Lang> idToLang;

static {
idToLang = new HashMap<>();
final InputStream langCodesInputStream = LangUtil.class.getClassLoader()
.getResourceAsStream("iso-639-3.tab");
if (langCodesInputStream != null) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(langCodesInputStream,
StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
Lang lang = new Lang(line);
idToLang.put(lang.getId(), lang);
if (lang.getPart2B() != null) {
idToLang.put(lang.getPart2B(), lang);
}
}
} catch (IOException e) {
log.error(e);
}
}
}

public static String getShortestId(String id) {
Lang lang = idToLang.get(id);
if (lang != null) {
if (lang.getPart1() != null) {
return lang.getPart1();
} else {
return lang.getId();
}
}
return id;
}

public static void main(String[] args) {
System.out.println(getShortestId("eng"));
System.out.println(getShortestId("deu"));
System.out.println(getShortestId("ger"));
System.out.println(getShortestId("wtf"));
}

private static class Lang {
private final String id;
private final String part2B;
//private final String part2T;
private final String part1;
/*private final String scope;
private final String languageType;
private final String refName;
private final String comment;*/

public Lang(String line) {
String[] parts = line.split("\t", 8);
id = parts[0];
part2B = parts[1].isEmpty() ? null : parts[1];
//part2T = parts[2];
part1 = parts[3].isEmpty() ? null : parts[3];
}

public String getId() {
return id;
}

public String getPart1() {
return part1;
}

public String getPart2B() {
return part2B;
}
}
}
4 changes: 2 additions & 2 deletions dspace-oai/src/main/java/org/dspace/utils/LicenseUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* https://github.com/ufal/clarin-dspace/blob
* * /si-master-origin/dspace-oai/src/main/java/cz/cuni/mff/ufal/utils/LicenseUtil.java) and modified by
*
* @author Marian Berger (marian.berger at dataquest.sk)
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
* @author Marian Berger (dspace at dataquest.sk)
* @author Milan Majchrak (dspace at dataquest.sk)
*/
public class LicenseUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.dspace.xoai.services.impl.resources.functions.GetUploadedMetadataFn;
import org.dspace.xoai.services.impl.resources.functions.LogMissingFn;
import org.dspace.xoai.services.impl.resources.functions.LogMissingMsgFn;
import org.dspace.xoai.services.impl.resources.functions.ShortestIdFn;
import org.dspace.xoai.services.impl.resources.functions.StringReplaceFn;
import org.dspace.xoai.services.impl.resources.functions.UriToLicenseFn;
import org.dspace.xoai.services.impl.resources.functions.UriToMetaShareFn;
Expand All @@ -50,7 +51,7 @@ public class DSpaceResourceResolver implements ResourceResolver {
*/
List<ExtensionFunction> extensionFunctionList = List.of(
new GetPropertyFn(), new StringReplaceFn(), new UriToMetaShareFn(),
new UriToLicenseFn(), new LogMissingMsgFn(), new UriToRestrictionsFn(),
new UriToLicenseFn(), new LogMissingMsgFn(), new UriToRestrictionsFn(), new ShortestIdFn(),
new GetContactFn(), new GetAuthorFn(), new GetFundingFn(), new GetLangForCodeFn(),
new GetPropertyFn(), new GetSizeFn(), new GetUploadedMetadataFn(), new LogMissingFn(),
new BibtexifyFn(), new FormatFn()
Expand All @@ -62,6 +63,7 @@ public class DSpaceResourceResolver implements ResourceResolver {
saxonTransformerFactory.getProcessor().registerExtensionFunction(en);
}
}

private final String basePath;

public DSpaceResourceResolver() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.xoai.services.impl.resources.functions;

import org.dspace.utils.LangUtil;

/**
* Serves as proxy for call from XSL engine. Calls LicenseUtil
* @author Marian Berger (marian.berger at dataquest.sk)
*/
public class ShortestIdFn extends StringXSLFunction {
@Override
protected String getFnName() {
return "shortestIdFn";
}

@Override
protected String getStringResult(String param) {
return LangUtil.getShortestId(param);
}
}
2 changes: 2 additions & 0 deletions dspace/config/clarin-dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,5 @@ download.all.limit.min.file.count = 1
download.all.limit.max.file.size = 1073741824
# minimum total size of files for enabling download alert:
download.all.alert.min.file.size = 10485760
# used in elg crosswalk exposing download locations
elg.download-location.exposed = 0
Loading