diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6799a48c7..e7e82319c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added [oaDOI](https://oadoi.org/) as a fulltext provider, so that JabRef is now able to provide fulltexts for more than 90 million open-access articles. - We changed one default of [Cleanup entries dialog](http://help.jabref.org/en/CleanupEntries): Per default, the PDF are not moved to the default file directory anymore. [#3619](https://github.com/JabRef/jabref/issues/3619) - We added a new type of group that shows all items referenced in a given LaTeX file (actually the generated AUX file). [#1664](https://github.com/JabRef/jabref/issues/1664) +- We added an importer for the EndNote XML format. [Feature request in the forum](http://discourse.jabref.org/t/import-from-bookends-or-endnote/1048) - We added the export of the `translator` field to the according MS-Office XML field. [#1750, comment](https://github.com/JabRef/jabref/issues/1750#issuecomment-357350986) - We changed the import of the MS-Office XML fields `bookauthor` and `translator`. Both are now imported to their corresponding bibtex/biblatex fields. - We improved the export of the `address` and `location` field to the MS-Office XML fields. If the address field does not contain a comma, it is treated as single value and exported to the field `city`. [#1750, comment](https://github.com/JabRef/jabref/issues/1750#issuecomment-357539167) diff --git a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java index 6e7c31415b8..f3d5b9908d5 100644 --- a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java +++ b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java @@ -14,6 +14,7 @@ import org.jabref.logic.importer.fileformat.CopacImporter; import org.jabref.logic.importer.fileformat.CustomImporter; import org.jabref.logic.importer.fileformat.EndnoteImporter; +import org.jabref.logic.importer.fileformat.EndnoteXmlImporter; import org.jabref.logic.importer.fileformat.FreeCiteImporter; import org.jabref.logic.importer.fileformat.InspecImporter; import org.jabref.logic.importer.fileformat.IsiImporter; @@ -56,6 +57,7 @@ public void resetImportFormats(ImportFormatPreferences newImportFormatPreference formats.add(new BibTeXMLImporter()); formats.add(new CopacImporter()); formats.add(new EndnoteImporter(importFormatPreferences)); + formats.add(new EndnoteXmlImporter(importFormatPreferences)); formats.add(new FreeCiteImporter(importFormatPreferences)); formats.add(new InspecImporter()); formats.add(new IsiImporter()); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java new file mode 100644 index 00000000000..34a600321cb --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java @@ -0,0 +1,306 @@ +package org.jabref.logic.importer.fileformat; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.jabref.logic.importer.ImportFormatPreferences; +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.endnote.Abstract; +import org.jabref.logic.importer.fileformat.endnote.Authors; +import org.jabref.logic.importer.fileformat.endnote.Contributors; +import org.jabref.logic.importer.fileformat.endnote.Dates; +import org.jabref.logic.importer.fileformat.endnote.ElectronicResourceNum; +import org.jabref.logic.importer.fileformat.endnote.Isbn; +import org.jabref.logic.importer.fileformat.endnote.Keywords; +import org.jabref.logic.importer.fileformat.endnote.Notes; +import org.jabref.logic.importer.fileformat.endnote.Number; +import org.jabref.logic.importer.fileformat.endnote.Pages; +import org.jabref.logic.importer.fileformat.endnote.PdfUrls; +import org.jabref.logic.importer.fileformat.endnote.Record; +import org.jabref.logic.importer.fileformat.endnote.RefType; +import org.jabref.logic.importer.fileformat.endnote.RelatedUrls; +import org.jabref.logic.importer.fileformat.endnote.SecondaryTitle; +import org.jabref.logic.importer.fileformat.endnote.Style; +import org.jabref.logic.importer.fileformat.endnote.Title; +import org.jabref.logic.importer.fileformat.endnote.Titles; +import org.jabref.logic.importer.fileformat.endnote.Url; +import org.jabref.logic.importer.fileformat.endnote.Urls; +import org.jabref.logic.importer.fileformat.endnote.Volume; +import org.jabref.logic.importer.fileformat.endnote.Xml; +import org.jabref.logic.importer.fileformat.endnote.Year; +import org.jabref.logic.util.FileType; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BiblatexEntryType; +import org.jabref.model.entry.BiblatexEntryTypes; +import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.LinkedFile; +import org.jabref.model.strings.StringUtil; +import org.jabref.model.util.OptionalUtil; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Importer for the Endnote XML format. + * + * Based on dtd scheme downloaded from Article #122577 in http://kbportal.thomson.com. + */ +public class EndnoteXmlImporter extends Importer implements Parser { + + private static final Logger LOGGER = LoggerFactory.getLogger(EndnoteXmlImporter.class); + private final ImportFormatPreferences preferences; + private Unmarshaller unmarshaller; + + public EndnoteXmlImporter(ImportFormatPreferences preferences) { + this.preferences = preferences; + } + + @Override + public String getName() { + return "EndNote XML"; + } + + @Override + public FileType getFileType() { + return FileType.ENDNOTE_XML; + } + + @Override + public String getId() { + return "endnote"; + } + + @Override + public String getDescription() { + return "Importer for the EndNote XML format."; + } + + @Override + public boolean isRecognizedFormat(BufferedReader reader) throws IOException { + String str; + int i = 0; + while (((str = reader.readLine()) != null) && (i < 50)) { + if (str.toLowerCase(Locale.ENGLISH).contains("")) { + return true; + } + + i++; + } + return false; + } + + @Override + public ParserResult importDatabase(BufferedReader reader) throws IOException { + Objects.requireNonNull(reader); + + try { + Object unmarshalledObject = unmarshallRoot(reader); + + if (unmarshalledObject instanceof Xml) { + // Check whether we have an article set, an article, a book article or a book article set + Xml root = (Xml) unmarshalledObject; + List bibEntries = root.getRecords() + .getRecord() + .stream() + .map(this::parseRecord) + .collect(Collectors.toList()); + + return new ParserResult(bibEntries); + } else { + return ParserResult.fromErrorMessage("File does not start with xml tag."); + } + } catch (JAXBException | XMLStreamException e) { + LOGGER.debug("could not parse document", e); + return ParserResult.fromError(e); + } + } + + private Object unmarshallRoot(BufferedReader reader) throws XMLStreamException, JAXBException { + initUnmarshaller(); + + XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); + XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader); + + // Go to the root element + while (!xmlStreamReader.isStartElement()) { + xmlStreamReader.next(); + } + + return unmarshaller.unmarshal(xmlStreamReader); + } + + private void initUnmarshaller() throws JAXBException { + if (unmarshaller == null) { + // Lazy init because this is expensive + JAXBContext context = JAXBContext.newInstance("org.jabref.logic.importer.fileformat.endnote"); + unmarshaller = context.createUnmarshaller(); + } + } + + private static BiblatexEntryType convertRefNameToType(String refName) { + switch (refName.toLowerCase().trim()) { + case "artwork": + return BiblatexEntryTypes.MISC; + case "generic": + return BiblatexEntryTypes.MISC; + case "electronic rticle": + return BiblatexEntryTypes.ELECTRONIC; + case "book section": + return BiblatexEntryTypes.INBOOK; + case "book": + return BiblatexEntryTypes.BOOK; + case "journal article": + return BiblatexEntryTypes.ARTICLE; + + default: + return BiblatexEntryTypes.ARTICLE; + } + } + + private BibEntry parseRecord(Record record) { + BibEntry entry = new BibEntry(); + + entry.setType(getType(record)); + Optional.ofNullable(getAuthors(record)) + .ifPresent(value -> entry.setField(FieldName.AUTHOR, value)); + Optional.ofNullable(record.getTitles()) + .map(Titles::getTitle) + .map(Title::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.TITLE, clean(value))); + Optional.ofNullable(record.getTitles()) + .map(Titles::getSecondaryTitle) + .map(SecondaryTitle::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.JOURNAL, clean(value))); + Optional.ofNullable(record.getPages()) + .map(Pages::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.PAGES, value)); + Optional.ofNullable(record.getNumber()) + .map(Number::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.NUMBER, value)); + Optional.ofNullable(record.getVolume()) + .map(Volume::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.VOLUME, value)); + Optional.ofNullable(record.getDates()) + .map(Dates::getYear) + .map(Year::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.YEAR, value)); + Optional.ofNullable(record.getNotes()) + .map(Notes::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.NOTE, value.trim())); + getUrl(record) + .ifPresent(value -> entry.setField(FieldName.URL, value)); + entry.putKeywords(getKeywords(record), preferences.getKeywordSeparator()); + Optional.ofNullable(record.getAbstract()) + .map(Abstract::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.ABSTRACT, value.trim())); + entry.setFiles(getLinkedFiles(record)); + Optional.ofNullable(record.getIsbn()) + .map(Isbn::getStyle) + .map(Style::getvalue) + .ifPresent(value -> entry.setField(FieldName.ISBN, clean(value))); + Optional.ofNullable(record.getElectronicResourceNum()) + .map(ElectronicResourceNum::getStyle) + .map(Style::getvalue) + .ifPresent(doi -> entry.setField(FieldName.DOI, doi.trim())); + + return entry; + } + + private BiblatexEntryType getType(Record record) { + return Optional.ofNullable(record.getRefType()) + .map(RefType::getName) + .map(EndnoteXmlImporter::convertRefNameToType) + .orElse(BiblatexEntryTypes.ARTICLE); + } + + private List getLinkedFiles(Record record) { + Optional urls = Optional.ofNullable(record.getUrls()) + .map(Urls::getPdfUrls); + return OptionalUtil.toStream(urls) + .flatMap(pdfUrls -> pdfUrls.getUrl().stream()) + .flatMap(url -> OptionalUtil.toStream(getUrlValue(url))) + .map(url -> new LinkedFile("", url, "PDF")) + .collect(Collectors.toList()); + } + + private Optional getUrl(Record record) { + Optional urls = Optional.ofNullable(record.getUrls()) + .map(Urls::getRelatedUrls); + return OptionalUtil.toStream(urls) + .flatMap(url -> url.getUrl().stream()) + .flatMap(url -> OptionalUtil.toStream(getUrlValue(url))) + .findFirst(); + } + + private Optional getUrlValue(Url url) { + return Optional.ofNullable(url) + .map(Url::getStyle) + .map(Style::getvalue) + .map(this::clean); + } + + private List getKeywords(Record record) { + Keywords keywords = record.getKeywords(); + if (keywords != null) { + return keywords.getKeyword() + .stream() + .map(keyword -> keyword.getStyle().getvalue()) + .collect(Collectors.toList()); + } else { + return Collections.emptyList(); + } + } + + private String getAuthors(Record record) { + Optional authors = Optional.ofNullable(record.getContributors()) + .map(Contributors::getAuthors); + return OptionalUtil.toStream(authors) + .flatMap(value -> value.getAuthor().stream()) + .map(author -> author.getStyle().getvalue()) + .collect(Collectors.joining(" and ")); + } + + private String clean(String input) { + return StringUtil.unifyLineBreaks(input, " ") + .trim() + .replaceAll(" +", " "); + } + + @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/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java index c9044ba46ac..b2b362a27da 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java @@ -93,6 +93,7 @@ public class MedlineImporter extends Importer implements Parser { private static final String KEYWORD_SEPARATOR = "; "; private static final Locale ENGLISH = Locale.ENGLISH; + private Unmarshaller unmarshaller; private static String join(List list, String string) { return Joiner.on(string).join(list); @@ -141,17 +142,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { List bibItems = new ArrayList<>(); try { - JAXBContext context = JAXBContext.newInstance("org.jabref.logic.importer.fileformat.medline"); - XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); - XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader); - - //go to the root element - while (!xmlStreamReader.isStartElement()) { - xmlStreamReader.next(); - } - - Unmarshaller unmarshaller = context.createUnmarshaller(); - Object unmarshalledObject = unmarshaller.unmarshal(xmlStreamReader); + Object unmarshalledObject = unmarshallRoot(reader); //check whether we have an article set, an article, a book article or a book article set if (unmarshalledObject instanceof PubmedArticleSet) { @@ -185,6 +176,28 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { return new ParserResult(bibItems); } + private Object unmarshallRoot(BufferedReader reader) throws JAXBException, XMLStreamException { + initUmarshaller(); + + XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); + XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader); + + //go to the root element + while (!xmlStreamReader.isStartElement()) { + xmlStreamReader.next(); + } + + return unmarshaller.unmarshal(xmlStreamReader); + } + + private void initUmarshaller() throws JAXBException { + if (unmarshaller == null) { + // Lazy init because this is expensive + JAXBContext context = JAXBContext.newInstance("org.jabref.logic.importer.fileformat.medline"); + unmarshaller = context.createUnmarshaller(); + } + } + private void parseBookArticle(PubmedBookArticle currentArticle, List bibItems) { Map fields = new HashMap<>(); if (currentArticle.getBookDocument() != null) { diff --git a/src/main/java/org/jabref/logic/util/FileType.java b/src/main/java/org/jabref/logic/util/FileType.java index fc17bb887f6..cb1de601dc0 100644 --- a/src/main/java/org/jabref/logic/util/FileType.java +++ b/src/main/java/org/jabref/logic/util/FileType.java @@ -24,8 +24,9 @@ public enum FileType { CITATION_STYLE(Localization.lang("%0 file", "CSL"), "csl"), DOCBOOK(Localization.lang("%0 file", "Docbook 4.4"), "xml"), DIN_1505(Localization.lang("%0 file", "DIN 1505"), "rtf"), - ENDNOTE(Localization.lang("%0 file", "Endnote/Refer"), "ref", "enw"), - ENDNOTE_TXT(Localization.lang("%0 file", "Endnote"), "txt"), //for export + ENDNOTE(Localization.lang("%0 file", "EndNote/Refer"), "ref", "enw"), + ENDNOTE_XML(Localization.lang("%0 file", "EndNote XML"), "xml"), + ENDNOTE_TXT(Localization.lang("%0 file", "EndNote"), "txt"), //for export FREECITE(Localization.lang("%0 file", "FreeCite"), "txt", "xml"), HARVARD_RTF(Localization.lang("%0 file", "Harvard"), "rtf"), HTML_LIST(Localization.lang("%0 file", Localization.lang("HTML list")), "html"), diff --git a/src/main/resources/xjc/endnote/RSXML.dtd b/src/main/resources/xjc/endnote/RSXML.dtd new file mode 100644 index 00000000000..32aa229358b --- /dev/null +++ b/src/main/resources/xjc/endnote/RSXML.dtd @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestFiles.java index 0e7fc1627c1..6ab7a54ce7d 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestFiles.java @@ -38,7 +38,7 @@ public void testIsNotRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(new BibTeXMLImporter(), fileName, FILE_ENDING); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTestFiles.java index 4fe1a377fa3..6c598c3c69d 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BiblioscapeImporterTestFiles.java @@ -25,7 +25,7 @@ public void testIsRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(new BiblioscapeImporter(), fileName, FILE_ENDING); } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTestFiles.java index 9947a054380..dd67ddcb7b7 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/CopacImporterTestFiles.java @@ -36,7 +36,7 @@ public void testIsNotRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(new CopacImporter(), fileName, FILE_ENDING); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java new file mode 100644 index 00000000000..3cf39f99291 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java @@ -0,0 +1,54 @@ +package org.jabref.logic.importer.fileformat; + +import java.io.IOException; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportFormatPreferences; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class EndnoteXmlImporterTestFiles { + + private static final String FILE_ENDING = ".xml"; + private ImportFormatPreferences preferences; + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("EndnoteXmlImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("EndnoteXmlImporterTest"); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @BeforeEach + void setUp() { + preferences = mock(ImportFormatPreferences.class); + when(preferences.getKeywordSeparator()).thenReturn(';'); + } + + @ParameterizedTest + @MethodSource("fileNames") + void testIsRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(new EndnoteXmlImporter(preferences), fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void testIsNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(new EndnoteXmlImporter(preferences), fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void testImportEntries(String fileName) throws Exception { + ImporterTestEngine.testImportEntries(new EndnoteXmlImporter(preferences), fileName, FILE_ENDING); + } +} diff --git a/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java b/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java index 94d32a28b06..c2eaa089a38 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/ImporterTestEngine.java @@ -14,7 +14,9 @@ import java.util.stream.Stream; import org.jabref.logic.bibtex.BibEntryAssert; +import org.jabref.logic.importer.ImportException; import org.jabref.logic.importer.Importer; +import org.jabref.logic.importer.ParserResult; import org.jabref.model.entry.BibEntry; import org.junit.jupiter.api.Assertions; @@ -47,9 +49,13 @@ public static void testIsNotRecognizedFormat(Importer importer, String fileName) Assertions.assertFalse(importer.isRecognizedFormat(getPath(fileName), StandardCharsets.UTF_8)); } - public static void testImportEntries(Importer importer, String fileName, String fileType) throws IOException { - List entries = importer.importDatabase(getPath(fileName), StandardCharsets.UTF_8).getDatabase() - .getEntries(); + public static void testImportEntries(Importer importer, String fileName, String fileType) throws IOException, ImportException { + ParserResult parserResult = importer.importDatabase(getPath(fileName), StandardCharsets.UTF_8); + if (parserResult.isInvalid()) { + throw new ImportException(parserResult.getErrorMessage()); + } + List entries = parserResult.getDatabase() + .getEntries(); BibEntryAssert.assertEquals(ImporterTestEngine.class, fileName.replaceAll(fileType, ".bib"), entries); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MedlineImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/MedlineImporterTestFiles.java index a3ce1127b6b..91c49fd3d9b 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MedlineImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MedlineImporterTestFiles.java @@ -38,7 +38,7 @@ public void testIsNotRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(new MedlineImporter(), fileName, FILE_ENDING); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTestFiles.java index 952664e9475..74b84bc6a3d 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfContentImporterTestFiles.java @@ -29,7 +29,7 @@ public void testIsRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(new PdfContentImporter(mock(ImportFormatPreferences.class)), fileName, FILE_ENDING); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTestFiles.java index 9fe87753c63..5f7782d02c7 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/RISImporterTestFiles.java @@ -24,7 +24,7 @@ public void testIsRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(new RisImporter(), fileName, FILE_ENDING); } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java index eac60285cb3..6b031262d3c 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java @@ -49,7 +49,7 @@ public void testIsNotRecognizedFormat(String fileName) throws IOException { @ParameterizedTest @MethodSource("fileNames") - public void testImportEntries(String fileName) throws IOException { + public void testImportEntries(String fileName) throws Exception { ImporterTestEngine.testImportEntries(testImporter, fileName, FILE_ENDING); } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle.bib b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle.bib new file mode 100644 index 00000000000..f93199db1af --- /dev/null +++ b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle.bib @@ -0,0 +1,16 @@ +@article{, + abstract = {test abstract}, + author = {Ahmad, AS and Ormiston-Smith, N and Sasieni, PD}, + doi = {10.1038/bjc.2014.606}, + file = {:file\://localhost/Users/user/Documents/Bookends/Attachments/Ahmad%20et%20al%202015.pdf:PDF}, + isbn = {1532-1827 (Electronic) 0007-0920 (Linking)}, + keywords = {Age Factors; Aged; Aged, 80 and over; Female; Great Britain/epidemiology; Humans; Male; Middle Aged; Models, Statistical; Neoplasms/*epidemiology; Risk Assessment; Risk Factors; Sex Characteristics}, + number = {5}, + pages = {943-7}, + title = {Trends in the lifetime risk of developing cancer in Great Britain: comparison of risk for those born from 1930 to 1960}, + volume = {112}, + year = {2015}, + journal = {Br J Cancer}, + note = {some notes}, + url = {http://www.ncbi.nlm.nih.gov/pubmed/25647015}, +} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle.xml b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle.xml new file mode 100644 index 00000000000..c3a8bb5de98 --- /dev/null +++ b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle.xml @@ -0,0 +1,131 @@ + + + + + Library1.bdb + Bookends + 2954 + 17 + + + + + + + + + + + + + + + + + + + <style face="normal" size="100%">Trends in the lifetime risk of developing cancer in Great Britain: + comparison of risk for those born from 1930 to 1960 + </style> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle2.bib b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle2.bib new file mode 100644 index 00000000000..a7293b79f14 --- /dev/null +++ b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle2.bib @@ -0,0 +1,24 @@ +@article{, + author = {Chapman, A. G.}, + isbn = {0012-9658}, + number = {1}, + pages = {93-105}, + title = {An ecological basis for reforestation of submariginal lands in the Central Hardwood Region}, + volume = {18}, + year = {1937}, + journal = {Ecology}, + note = {some notes}, + url = {://000200148800007} +} +@book{, + author = {Strohecker, H. F.}, + isbn = {0012-9658}, + number = {1}, + journal = {Ecology}, + note = {some other notes}, + pages = {162-168}, + title = {A survey of soil temperatures in the Chicago area}, + volume = {18}, + url = {://000200148800014}, + year = {1937} +} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle2.xml b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle2.xml new file mode 100644 index 00000000000..e2ff36845c1 --- /dev/null +++ b/src/test/resources/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestArticle2.xml @@ -0,0 +1,184 @@ + + + + + EndNote + Ecology.enl + + EndNote + 13264 + + 13264 + + 17 + + + + + + + + + + + + + <style face="normal" font="default" size="100%">An ecological basis for reforestation of + submariginal lands in the Central Hardwood Region + </style> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + EndNote + Ecology.enl + + EndNote + 13265 + + 13265 + + 6 + + + + + + + + + + + + + <style face="normal" font="default" size="100%">A survey of soil temperatures in the Chicago area + </style> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xjc.gradle b/xjc.gradle index 3285a93ba3e..d1d54fb5197 100644 --- a/xjc.gradle +++ b/xjc.gradle @@ -10,9 +10,11 @@ dependencies { task xjc { inputs.dir "src/main/resources/xjc/medline/" inputs.dir "src/main/resources/xjc/bibtexml/" + inputs.dir "src/main/resources/xjc/endnote/" inputs.dir "src/main/resources/xjc/mods/" outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/medline" outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/bibtexml" + outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/endnote" outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/mods" ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.xjc.asPath) @@ -24,6 +26,10 @@ task xjc { ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.bibtexml') { schema(dir: 'src/main/resources/xjc/bibtexml', includes: 'bibtexml.xsd') } + ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.endnote') { + arg(value: '-dtd') + schema(dir: 'src/main/resources/xjc/endnote', includes: 'RSXML.dtd') + } ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.mods') { arg(value: '-npa') //don't create package-info.java because it was manually added in src/main/java to ensure the namespace prefix mapping schema(dir: 'src/main/resources/xjc/mods', includes: 'mods-3-6.xsd')