forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
add elg format #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add elg format #658
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fbd778d
add elg format
MajoBerger 265e440
add shortestId funtion
MajoBerger e338372
properties, formatting
MajoBerger 815c459
checkstyle fix
MajoBerger 8336b88
elg crosswalk fixes
MajoBerger 9e9b7c5
fixes based on review
MajoBerger bee9e09
remove commented out code
MajoBerger 55f61fa
changed to generic email
MajoBerger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
dspace-oai/src/main/java/org/dspace/utils/LangUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
milanmajchrak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * 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; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
dspace-oai/src/main/java/org/dspace/xoai/services/impl/resources/functions/ShortestIdFn.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.