From 7a30b523d3514b85663345ccc8e0d97676685730 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 24 May 2017 13:17:31 +0200 Subject: [PATCH 1/3] Add Library of Congress as ID-fetcher --- CHANGELOG.md | 1 + .../jabref/logic/importer/WebFetchers.java | 2 + .../importer/fetcher/LibraryOfCongress.java | 38 +++++++++++++++++++ .../importer/fileformat/ModsImporter.java | 17 ++++++++- .../fetcher/LibraryOfCongressTest.java | 34 +++++++++++++++++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java create mode 100644 src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af03547d66..5e4a18b7e17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Removed the hidden feature that a double click in the editor inserted the current date. - All authors and editors are separated using semicolons when exporting to csv. [#2762](https://github.com/JabRef/jabref/issues/2762) - Improved wording of "Show recommendations: into "Show 'Related Articles' tab" in the preferences +- We added integration of the Library of Congress catalog as a fetcher based on the [LCCN identifier](https://en.wikipedia.org/wiki/Library_of_Congress_Control_Number). [Feature request 636 in the forum](http://discourse.jabref.org/t/loc-marc-mods-connection/636) ### Fixed - We fixed the IEEE Xplore web search functionality [#2789](https://github.com/JabRef/jabref/issues/2789) diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index a0ca5f0cfd3..628ebb41953 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -14,6 +14,7 @@ import org.jabref.logic.importer.fetcher.GoogleScholar; import org.jabref.logic.importer.fetcher.GvkFetcher; import org.jabref.logic.importer.fetcher.IsbnFetcher; +import org.jabref.logic.importer.fetcher.LibraryOfCongress; import org.jabref.logic.importer.fetcher.MathSciNet; import org.jabref.logic.importer.fetcher.MedlineFetcher; import org.jabref.logic.importer.fetcher.TitleFetcher; @@ -88,6 +89,7 @@ public static List getIdBasedFetchers(ImportFormatPreferences im list.add(new TitleFetcher(importFormatPreferences)); list.add(new MathSciNet(importFormatPreferences)); list.add(new CrossRef()); + list.add(new LibraryOfCongress()); list.sort(Comparator.comparing(WebFetcher::getName)); return list; } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java b/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java new file mode 100644 index 00000000000..63546f87d66 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java @@ -0,0 +1,38 @@ +package org.jabref.logic.importer.fetcher; + +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.IdBasedParserFetcher; +import org.jabref.logic.importer.Parser; +import org.jabref.logic.importer.fileformat.ModsImporter; + +import org.apache.http.client.utils.URIBuilder; + +/** + * Fetcher for the Library of Congress Control Number (LCCN) using https://lccn.loc.gov/ + */ +public class LibraryOfCongress implements IdBasedParserFetcher { + + public LibraryOfCongress() { + + } + + @Override + public String getName() { + return "Library of Congress"; + } + + @Override + public URL getURLForID(String identifier) throws URISyntaxException, MalformedURLException, FetcherException { + URIBuilder uriBuilder = new URIBuilder("https://lccn.loc.gov/" + identifier + "/mods"); + return uriBuilder.build().toURL(); + } + + @Override + public Parser getParser() { + return new ModsImporter(); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java index 2708b05ae20..325683a2326 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java @@ -2,7 +2,11 @@ import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,6 +21,8 @@ import javax.xml.bind.Unmarshaller; import org.jabref.logic.importer.Importer; +import org.jabref.logic.importer.ParseException; +import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.mods.AbstractDefinition; import org.jabref.logic.importer.fileformat.mods.DateDefinition; @@ -61,7 +67,7 @@ * More details about the format can be found here http://www.loc.gov/standards/mods/.
* The newest xml schema can also be found here www.loc.gov/standards/mods/mods-schemas.html.. */ -public class ModsImporter extends Importer { +public class ModsImporter extends Importer implements Parser { private static final Log LOGGER = LogFactory.getLog(ModsImporter.class); private static final String KEYWORD_SEPARATOR = JabRefPreferences.getInstance().getImportFormatPreferences() @@ -476,4 +482,13 @@ public String getDescription() { return "Importer for the MODS format"; } + @Override + public List parseEntries(InputStream inputStream) throws ParseException { + try { + return importDatabase(new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))).getDatabase().getEntries(); + } catch (IOException e) { + LOGGER.error(e.getLocalizedMessage(), e); + } + return Collections.emptyList(); + } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java new file mode 100644 index 00000000000..403f8522f22 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java @@ -0,0 +1,34 @@ +package org.jabref.logic.importer.fetcher; + +import java.util.Optional; + +import org.jabref.model.entry.BibEntry; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class LibraryOfCongressTest { + + LibraryOfCongress fetcher = new LibraryOfCongress(); + + @Test + public void performSearchById() throws Exception { + BibEntry expected = new BibEntry(); + expected.setField("address", "Burlington, MA"); + expected.setField("author", "West, Matthew"); + expected.setField("isbn", "0123751063 (pbk.)"); + expected.setField("issuance", "monographic"); + expected.setField("keywords", "Database design, Data structures (Computer science)"); + expected.setField("language", "eng"); + expected.setField("lccn", "2010045158"); + expected.setField("note", "Matthew West., Includes index."); + expected.setField("oclc", "ocn665135773"); + expected.setField("publisher", "Morgan Kaufmann"); + expected.setField("source", "DLC"); + expected.setField("title", "Developing high quality data models"); + expected.setField("year", "2011"); + + assertEquals(Optional.of(expected), fetcher.performSearchById("2010045158")); + } +} From a3db1066883f54a3d70c64b46642c222c8d1e9a4 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 24 May 2017 15:37:22 +0200 Subject: [PATCH 2/3] Update LibraryOfCongress.java --- .../org/jabref/logic/importer/fetcher/LibraryOfCongress.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java b/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java index 63546f87d66..60ca3bc13d8 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/LibraryOfCongress.java @@ -16,10 +16,6 @@ */ public class LibraryOfCongress implements IdBasedParserFetcher { - public LibraryOfCongress() { - - } - @Override public String getName() { return "Library of Congress"; From bfc9ccc7b37aee141fcf002a4a8d376f6eaa65c0 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 24 May 2017 15:37:48 +0200 Subject: [PATCH 3/3] Update LibraryOfCongressTest.java --- .../jabref/logic/importer/fetcher/LibraryOfCongressTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java index 403f8522f22..4ee2dca2d8c 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java @@ -10,7 +10,7 @@ public class LibraryOfCongressTest { - LibraryOfCongress fetcher = new LibraryOfCongress(); + private LibraryOfCongress fetcher = new LibraryOfCongress(); @Test public void performSearchById() throws Exception {