diff --git a/jabgui/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java b/jabgui/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java index fc12e9670e8..145c2b266b9 100644 --- a/jabgui/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java +++ b/jabgui/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java @@ -28,7 +28,7 @@ public enum StandardExternalFileType implements ExternalFileType { TIFF(Localization.lang("%0 image", "TIFF"), "tiff", "image/tiff", "gimp", "picture", IconTheme.JabRefIcons.PICTURE), URL("URL", "html", "text/html", "firefox", "www", IconTheme.JabRefIcons.WWW), MHT("MHT", "mht", "multipart/related", "firefox", "www", IconTheme.JabRefIcons.WWW), - ePUB("ePUB", "epub", "application/epub+zip", "firefox", "www", IconTheme.JabRefIcons.WWW), + ePUB("ePUB", "epub", "application/epub+zip", "firefox", "www", IconTheme.JabRefIcons.BOOK), MARKDOWN("Markdown", "md", "text/markdown", "emacs", "emacs", IconTheme.JabRefIcons.FILE_TEXT); private final String name; private final String extension; diff --git a/jablib/build.gradle.kts b/jablib/build.gradle.kts index ac953ee912d..6995c258e3d 100644 --- a/jablib/build.gradle.kts +++ b/jablib/build.gradle.kts @@ -181,6 +181,33 @@ dependencies { implementation("de.rototor.snuggletex:snuggletex-jeuclid") + // region for document importing + implementation("org.apache.tika:tika-core:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.tika:tika-parsers:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.tika:tika-parser-xml-module:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.tika:tika-parser-image-module:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.tika:tika-parser-microsoft-module:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.tika:tika-parser-text-module:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.tika:tika-parser-miscoffice-module:3.2.0") { + exclude(group = "commons-logging") + } + implementation("org.apache.poi:poi:5.4.1") + // TODO: Remove this mail dependency. + implementation("com.sun.mail:jakarta.mail:2.0.1") + // endregion + // Even if("compileOnly") is used, IntelliJ always adds to module-info.java. To avoid issues during committing, we use("implementation") instead of("compileOnly") implementation("io.github.adr:e-adr") @@ -412,6 +439,10 @@ tasks.test { useJUnitPlatform { excludeTags("DatabaseTest", "FetcherTest") } + + jvmArgs( + "--add-exports=org.apache.poi.ooxml/org.apache.poi.xslf.extractor=org.apache.tika.parser.microsoft" + ) } jmh { diff --git a/jablib/src/main/java/module-info.java b/jablib/src/main/java/module-info.java index ba63449bb8a..c92ae905263 100644 --- a/jablib/src/main/java/module-info.java +++ b/jablib/src/main/java/module-info.java @@ -106,8 +106,7 @@ exports org.jabref.logic.git; exports org.jabref.logic.pseudonymization; exports org.jabref.logic.citation.repository; - - requires java.base; + exports org.jabref.logic.importer.fileformat.misc; requires javafx.base; requires javafx.graphics; // because of javafx.scene.paint.Color @@ -115,7 +114,6 @@ requires com.tobiasdiez.easybind; // for java.awt.geom.Rectangle2D required by org.jabref.logic.pdf.TextExtractor - requires java.desktop; // SQL requires java.sql; @@ -252,5 +250,7 @@ requires mslinks; requires org.antlr.antlr4.runtime; requires org.libreoffice.uno; + requires org.apache.tika.core; + requires org.jetbrains.annotations; // endregion } diff --git a/jablib/src/main/java/org/jabref/logic/importer/Importer.java b/jablib/src/main/java/org/jabref/logic/importer/Importer.java index ca54f38da9e..2bb98734ed3 100644 --- a/jablib/src/main/java/org/jabref/logic/importer/Importer.java +++ b/jablib/src/main/java/org/jabref/logic/importer/Importer.java @@ -49,6 +49,10 @@ public abstract class Importer implements Comparable { * @throws IOException Signals that an I/O exception has occurred. */ public boolean isRecognizedFormat(Path filePath) throws IOException { + if (!Files.exists(filePath) || !Files.isRegularFile(filePath)) { + return false; + } + try (BufferedReader bufferedReader = getReader(filePath)) { return isRecognizedFormat(bufferedReader); } diff --git a/jablib/src/main/java/org/jabref/logic/importer/ParserResult.java b/jablib/src/main/java/org/jabref/logic/importer/ParserResult.java index c0a75bc4903..fd4a573cff5 100644 --- a/jablib/src/main/java/org/jabref/logic/importer/ParserResult.java +++ b/jablib/src/main/java/org/jabref/logic/importer/ParserResult.java @@ -50,6 +50,10 @@ public static ParserResult fromErrorMessage(String message) { return parserResult; } + public static ParserResult fromEntry(BibEntry entry) { + return new ParserResult(List.of(entry)); + } + private static String getErrorMessage(Exception exception) { String errorMessage = exception.getLocalizedMessage(); if (exception.getCause() != null) { diff --git a/jablib/src/main/java/org/jabref/logic/importer/TikaImporter.java b/jablib/src/main/java/org/jabref/logic/importer/TikaImporter.java new file mode 100644 index 00000000000..d164f201da9 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/TikaImporter.java @@ -0,0 +1,94 @@ +package org.jabref.logic.importer; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +import org.jabref.logic.importer.util.TikaMetadataParser; +import org.jabref.logic.util.io.FileUtil; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; + +import org.apache.tika.exception.TikaException; +import org.apache.tika.metadata.Metadata; +import org.apache.tika.parser.AutoDetectParser; +import org.apache.tika.parser.ParseContext; +import org.apache.tika.parser.Parser; +import org.apache.tika.sax.BodyContentHandler; +import org.xml.sax.SAXException; + +/** + * Common class for all file importers that use Apache Tika to extract metadata from files. + *

+ * Child classes should implement the rest of {@link Importer} and method {@link #extractMetadata(TikaMetadataParser, String)} to extract the {@link BibEntry} from the Tika metadata. + *

+ * In case you need to use a specific Tika parser, you can override {@link #getTikaParser()} to return a different parser instance. + */ +public abstract class TikaImporter extends Importer { + @Override + public ParserResult importDatabase(BufferedReader input) throws IOException { + throw new UnsupportedOperationException("TikaImporter (and descendants) do not support importDatabase(BufferedReader reader)." + + "Instead use importDatabase(Path filePath)."); + } + + @Override + public ParserResult importDatabase(Path filePath) throws IOException { + try (InputStream inputStream = new FileInputStream(filePath.toFile())) { + Parser parser = getTikaParser(); + Metadata metadata = new Metadata(); + BodyContentHandler handler = new BodyContentHandler(); + + ParseContext parseContext = new ParseContext(); + parseContext.set(Parser.class, parser); + + parser.parse(inputStream, handler, metadata, parseContext); + + String fileName = FileUtil.getBaseName(filePath); + BibEntry entry = extractMetadata(new TikaMetadataParser(metadata)); + + if (!entry.hasField(StandardField.TITLE)) { + entry.setField(StandardField.TITLE, fileName); + } + + return ParserResult.fromEntry(entry); + } catch (SAXException | TikaException e) { + throw new IOException("Error parsing file: " + filePath, e); + } + } + + protected Parser getTikaParser() { + return new AutoDetectParser(); + } + + /** + * Extracts common metadata from the given Tika metadata object and returns a {@link BibEntry}. + *

+ * This function will add fields that are most standard and common across different file types. Inheritors are + * recommended to override {@link TikaImporter#extractAdditionalMetadata(BibEntry, TikaMetadataParser)} + * process additional metadata that is specific to the file type they are importing. + */ + protected final BibEntry extractMetadata(Metadata metadata) { + TikaMetadataParser metadataParser = new TikaMetadataParser(metadata); + + BibEntry entry = new BibEntry(StandardEntryType.Misc) + .withField(StandardField.TITLE, metadataParser.getDcTitle()) + .withField(StandardField.AUTHOR, TikaMetadataParser.formatBibtexAuthors(metadataParser.getDcCreators())); + + metadataParser.getDcTermsCreated().ifPresent(date -> TikaMetadataParser.addDateCreated(entry, date)); + + extractAdditionalMetadata(entry, metadataParser); + + return entry; + } + + /** + * Extracts additional metadata that is specific to the file type being imported. Inheritors are allowed to mutate + * the given {@link BibEntry} to add more fields or modify existing ones. + */ + protected void extractAdditionalMetadata(BibEntry entry, TikaMetadataParser metadataParser) { + + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/DjvuImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/DjvuImporter.java new file mode 100644 index 00000000000..78f79622dd0 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/DjvuImporter.java @@ -0,0 +1,42 @@ +package org.jabref.logic.importer.fileformat.books; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +public class DjvuImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + // DJVU start with "AT&TFORM" and then "DJVU" some time after that. + + char[] buffer = new char[64]; + int read = input.read(buffer, 0, buffer.length); + input.reset(); + String header = new String(buffer, 0, read); + return header.startsWith("AT&TFORM") && header.contains("DJVU"); + } + + @Override + public String getId() { + return "djvu"; + } + + @Override + public String getName() { + return "DjVu"; + } + + @Override + public String getDescription() { + return Localization.lang("Import DjVu files"); + } + + @Override + public FileType getFileType() { + return StandardFileType.DJVU; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/EpubImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/EpubImporter.java new file mode 100644 index 00000000000..5dbb48e8b55 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/EpubImporter.java @@ -0,0 +1,39 @@ +package org.jabref.logic.importer.fileformat.books; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +public class EpubImporter extends TikaImporter { + private static final char[] EPUB_HEADER_MAGIC_NUMBER = {0x50, 0x4b, 0x03, 0x04}; + + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.hasMagicNumber(input, EPUB_HEADER_MAGIC_NUMBER); + } + + @Override + public String getId() { + return "epub"; + } + + @Override + public String getName() { + return "ePUB"; + } + + @Override + public String getDescription() { + return Localization.lang("Import the popular e-book file format ePUB"); + } + + @Override + public FileType getFileType() { + return StandardFileType.EPUB; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/Fb2Importer.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/Fb2Importer.java new file mode 100644 index 00000000000..1aa02c0f577 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/books/Fb2Importer.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.books; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +public class Fb2Importer extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return input.lines() + .map(String::trim) + .anyMatch(line -> line.startsWith(" TikaMetadataParser.addDateCreated(entry, date)); + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/DocImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/DocImporter.java new file mode 100644 index 00000000000..a3baff9f9e0 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/DocImporter.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Imports old Microsoft Word 97-2003 files (`.doc`). + */ +public class DocImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isOleCompound(input); + } + + @Override + public String getId() { + return "doc"; + } + + @Override + public String getName() { + return "Microsoft Word 97-2003"; + } + + @Override + public String getDescription() { + return Localization.lang("Import Microsoft Word 97-2003 files (doc)"); + } + + @Override + public FileType getFileType() { + return StandardFileType.DOC; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporter.java new file mode 100644 index 00000000000..6f8054a1a0c --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporter.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Imports Microsoft Word 2007-365 files (`.docx`). + */ +public class DocxImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isZip(input); + } + + @Override + public String getId() { + return "docx"; + } + + @Override + public String getName() { + return "Microsoft Word 2007-365"; + } + + @Override + public String getDescription() { + return Localization.lang("Import Microsoft Word 2007-365 files (docx)"); + } + + @Override + public FileType getFileType() { + return StandardFileType.DOCX; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/PptImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/PptImporter.java new file mode 100644 index 00000000000..8bc3cc3b428 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/PptImporter.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Imports old Microsoft PowerPoint 97-2003 files (`.ppt`). + */ +public class PptImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isOleCompound(input); + } + + @Override + public String getId() { + return "ppt"; + } + + @Override + public String getName() { + return "Microsoft PowerPoint 97-2003"; + } + + @Override + public String getDescription() { + return Localization.lang("Import Microsoft PowerPoint 97-2003 files (ppt)"); + } + + @Override + public FileType getFileType() { + return StandardFileType.PPT; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporter.java new file mode 100644 index 00000000000..245e6aeef9b --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporter.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Imports Microsoft PowerPoint 2007-365 files (`.pptx`). + */ +public class PptxImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isZip(input); + } + + @Override + public String getId() { + return "pptx"; + } + + @Override + public String getName() { + return "Microsoft PowerPoint 2007-365"; + } + + @Override + public String getDescription() { + return Localization.lang("Import Microsoft PowerPoint 2007-365 files (pptx)"); + } + + @Override + public FileType getFileType() { + return StandardFileType.PPTX; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporter.java new file mode 100644 index 00000000000..9e8f640e5a1 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporter.java @@ -0,0 +1,39 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +public class RtfImporter extends TikaImporter { + private static final char[] RTF_MAGIC_NUMBER = new char[]{'{', '\\', 'r', 't', 'f', '1'}; + + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.hasMagicNumber(input, RTF_MAGIC_NUMBER); + } + + @Override + public String getId() { + return "rtf"; + } + + @Override + public String getName() { + return "RTF"; + } + + @Override + public String getDescription() { + return Localization.lang("Rich Text File importer"); + } + + @Override + public FileType getFileType() { + return StandardFileType.RTF; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporter.java new file mode 100644 index 00000000000..3204fc87ecc --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporter.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Imports old Microsoft Excel 97-2003 files (`.xls`). + */ +public class XlsImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isOleCompound(input); + } + + @Override + public String getId() { + return "xls"; + } + + @Override + public String getName() { + return "Microsoft Excel 97-2003"; + } + + @Override + public String getDescription() { + return Localization.lang("Import Microsoft Excel 97-2003 files (xls)"); + } + + @Override + public FileType getFileType() { + return StandardFileType.XLS; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporter.java new file mode 100644 index 00000000000..eed034d6650 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporter.java @@ -0,0 +1,40 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Imports Microsoft Excel 2007-365 files (`.xlsx`). + */ +public class XlsxImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isZip(input); + } + + @Override + public String getId() { + return "xlsx"; + } + + @Override + public String getName() { + return "Microsoft Excel 2007-365"; + } + + @Override + public String getDescription() { + return Localization.lang("Import Microsoft Excel 2007-365 files (xlsx)"); + } + + @Override + public FileType getFileType() { + return StandardFileType.XLSX; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/misc/TxtImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/misc/TxtImporter.java new file mode 100644 index 00000000000..cd157b34db9 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/misc/TxtImporter.java @@ -0,0 +1,36 @@ +package org.jabref.logic.importer.fileformat.misc; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +public class TxtImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return true; + } + + @Override + public String getId() { + return "txt"; + } + + @Override + public String getName() { + return "TXT"; + } + + @Override + public String getDescription() { + return Localization.lang("Importer for plain text files"); + } + + @Override + public FileType getFileType() { + return StandardFileType.TXT; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdfImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdfImporter.java new file mode 100644 index 00000000000..8e5fef010b3 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdfImporter.java @@ -0,0 +1,30 @@ +package org.jabref.logic.importer.fileformat.odf; + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.List; + +import org.jabref.logic.importer.TikaImporter; +import org.jabref.logic.importer.util.Constants; +import org.jabref.logic.importer.util.TikaMetadataParser; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.util.ListUtil; + +/** + * General importer for Open Document Format files. + */ +public abstract class OdfImporter extends TikaImporter { + @Override + public boolean isRecognizedFormat(BufferedReader input) throws IOException { + return Constants.isZip(input); + } + + @Override + protected void extractAdditionalMetadata(BibEntry entry, TikaMetadataParser metadataParser) { + List authors = ListUtil.concat(metadataParser.getDcCreators(), metadataParser.getDcContributors()); + + entry.setField(StandardField.AUTHOR, TikaMetadataParser.formatBibtexAuthors(authors)); + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdpImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdpImporter.java new file mode 100644 index 00000000000..7a5e068d4ce --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdpImporter.java @@ -0,0 +1,30 @@ +package org.jabref.logic.importer.fileformat.odf; + +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Importer for OpenDocument Impress (ODP) files. + */ +public class OdpImporter extends OdfImporter { + @Override + public String getId() { + return "odp"; + } + + @Override + public String getName() { + return "OpenDocument Impress"; + } + + @Override + public String getDescription() { + return Localization.lang("Importer for OpenDocument Impress (ODP) files"); + } + + @Override + public FileType getFileType() { + return StandardFileType.ODP; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdsImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdsImporter.java new file mode 100644 index 00000000000..8363107b748 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdsImporter.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.odf; + +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +import org.apache.tika.parser.Parser; + +/** + * Importer for OpenDocument Calc (ODS) files. + */ +public class OdsImporter extends OdfImporter { + @Override + public String getId() { + return "ods"; + } + + @Override + public String getName() { + return "OpenDocument Calc"; + } + + @Override + public String getDescription() { + return Localization.lang("Importer for OpenDocument Calc (ODS) files"); + } + + @Override + public FileType getFileType() { + return StandardFileType.ODS; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdtImporter.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdtImporter.java new file mode 100644 index 00000000000..1b7b2aff3c6 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/odf/OdtImporter.java @@ -0,0 +1,30 @@ +package org.jabref.logic.importer.fileformat.odf; + +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.FileType; +import org.jabref.logic.util.StandardFileType; + +/** + * Importer for OpenDocument Text (ODT) files. + */ +public class OdtImporter extends OdfImporter { + @Override + public String getId() { + return "odt"; + } + + @Override + public String getName() { + return "OpenDocument Writer"; + } + + @Override + public String getDescription() { + return Localization.lang("Importer for OpenDocument Writer (ODT) files"); + } + + @Override + public FileType getFileType() { + return StandardFileType.ODT; + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/util/Constants.java b/jablib/src/main/java/org/jabref/logic/importer/util/Constants.java new file mode 100644 index 00000000000..032bf096a4a --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/util/Constants.java @@ -0,0 +1,44 @@ +package org.jabref.logic.importer.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +public class Constants { + public static final char[] ZIP_HEADER_MAGIC_NUMBER = {0x50, 0x4b, 0x03, 0x04}; + // public static final char[] OLE_COMPOUND_MAGIC_NUMBER = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}; + public static final char[] OLE_COMPOUND_MAGIC_NUMBER = {65533, 65533, 17, 2161, 0x1A, 65533, 0x00, 0x00}; + + public static final List ZIP_FILES_EXTENSIONS = List.of( + ".ctv6bak", + ".zip", + ".epub", + ".odt", + ".docx", + ".xlsx", + ".pptx", + ".ods", + ".odp" + ); + + public static final List OLE_COMPOUND_FILES_EXTENSIONS = List.of( + ".doc", + ".xls", + ".ppt" + ); + + public static boolean isZip(BufferedReader input) throws IOException { + return hasMagicNumber(input, ZIP_HEADER_MAGIC_NUMBER); + } + + public static boolean isOleCompound(BufferedReader input) throws IOException { + return hasMagicNumber(input, OLE_COMPOUND_MAGIC_NUMBER); + } + + public static boolean hasMagicNumber(BufferedReader input, char[] magicNumber) throws IOException { + char[] header = new char[magicNumber.length]; + int nRead = input.read(header); + return nRead == magicNumber.length && Arrays.equals(header, magicNumber); + } +} diff --git a/jablib/src/main/java/org/jabref/logic/importer/util/TikaMetadataParser.java b/jablib/src/main/java/org/jabref/logic/importer/util/TikaMetadataParser.java new file mode 100644 index 00000000000..0b32d911d2b --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/importer/util/TikaMetadataParser.java @@ -0,0 +1,132 @@ +package org.jabref.logic.importer.util; + +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.strings.StringUtil; + +import org.apache.tika.metadata.Metadata; +import org.apache.tika.metadata.Property; + +public class TikaMetadataParser { + private final static Pattern imageDatePattern = Pattern.compile("(year|month|day|hour|minute|second)=(\\d+)"); + + private final Metadata metadata; + + public TikaMetadataParser(Metadata metadata) { + this.metadata = metadata; + } + + public Optional getDcTitle() { + return Optional.ofNullable(metadata.get("dc:title")); + } + + public Optional getDcTermsCreated() { + return Optional.ofNullable( + metadata.getDate( + Property.internalDate("dcterms:created") + ) + ); + } + + public Optional getPngCreationTime() { + return Optional.ofNullable(metadata.get("tIME")) + .or(() -> Optional.ofNullable(metadata.get("Document ImageModificationTime"))) + .map(TikaMetadataParser::parseDateForImages); + } + + private static Date parseDateForImages(String dateString) { + Matcher matcher = imageDatePattern.matcher(dateString); + + int year = 0, month = 1, day = 1, hour = 0, minute = 0, second = 0; + + while (matcher.find()) { + String key = matcher.group(1); + int value = Integer.parseInt(matcher.group(2)); + + switch (key) { + case "year" -> year = value; + case "month" -> month = value; + case "day" -> day = value; + case "hour" -> hour = value; + case "minute" -> minute = value; + case "second" -> second = value; + } + } + + Calendar calendar = Calendar.getInstance(); + calendar.set(year, month, day, hour, minute, second); + + return calendar.getTime(); + } + + public Optional getDcIdentifier() { + return Optional.ofNullable(metadata.get("dc:identifier")); + } + + public List getDcCreators() { + return Arrays.stream(metadata.getValues("dc:creator")) + .filter(StringUtil::isNotBlank) + .toList(); + } + + public List getDcContributors() { + return Arrays.stream(metadata.getValues("dc:creator")) + .filter(StringUtil::isNotBlank) + .toList(); + } + + public static String extractYearFromDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return Integer.toString(cal.get(Calendar.YEAR)); + } + + public static String extractBibtexMonthFromDate(Date date) { + LocalDate localDate = date.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + + String[] bibtexMonths = { + "jan", "feb", "mar", "apr", "may", "jun", + "jul", "aug", "sep", "oct", "nov", "dec" + }; + + return bibtexMonths[localDate.getMonthValue() - 1]; + } + + public static String formatBibtexDate(Date date) { + LocalDate localDate = date.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + + return localDate.format(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE); + } + + public static Optional formatBibtexAuthors(List authors) { + if (authors.isEmpty()) { + return Optional.empty(); + } + + return Optional.of(String.join(" and ", authors)); + } + + /** + * Adds year, month, and date fields to a BibEntry based on the provided date. Mutates the given object. + */ + public static BibEntry addDateCreated(BibEntry entry, Date date) { + return entry + .withField(StandardField.YEAR, extractYearFromDate(date)) + .withField(StandardField.MONTH, extractBibtexMonthFromDate(date)) + .withField(StandardField.DATE, formatBibtexDate(date)); + } +} diff --git a/jablib/src/main/java/org/jabref/logic/util/StandardFileType.java b/jablib/src/main/java/org/jabref/logic/util/StandardFileType.java index 4d0bf1c0412..95a972b19c6 100644 --- a/jablib/src/main/java/org/jabref/logic/util/StandardFileType.java +++ b/jablib/src/main/java/org/jabref/logic/util/StandardFileType.java @@ -22,8 +22,14 @@ public enum StandardFileType implements FileType { CLASS("Class file", "class"), CSS("CSS Styleshet", "css"), CSV("CSV", "csv"), + DJVU("DjVu", "djvu", "djv"), + DOC("Microsoft Word 97-2003", "doc"), + DOCX("Microsoft Word 2007-365", "docx"), ENDNOTE("Endnote", "ref", "enw"), + EPUB("ePUB", "epub"), + FB2("FictionBook 2", "fb2"), HTML("HTML", "html", "htm"), + JPG("JPG", "jpg", "jpeg"), ISI("Isi", "isi", "txt"), JAR("JAR", "jar"), JAVA_KEYSTORE("Java Keystore", "jks"), @@ -33,7 +39,12 @@ public enum StandardFileType implements FileType { MARKDOWN("Markdown", "md"), MEDLINE("Medline", "nbib", "xml"), MEDLINE_PLAIN("Medline Plain", "nbib", "txt"), + ODP("OpenOffice Impress", "odp"), ODS("OpenOffice Calc", "ods"), + ODT("OpenOffice Writer", "odt"), + PNG("PNG", "png"), + PPT("Microsoft PowerPoint 97-2003", "ppt"), + PPTX("Microsoft PowerPoint 2007-365", "pptx"), PDF("PDF", "pdf"), PUBMED("Pubmed", "fcgi"), RDF("RDF", "rdf"), @@ -45,6 +56,8 @@ public enum StandardFileType implements FileType { TXT("Plain Text", "txt"), XML("XML", "xml"), XMP("XMP", "xmp"), + XLS("Microsoft Excel 97-2003", "xsl"), + XLSX("Microsoft Excel 2007-365", "xlsx"), YAML("YAML Markup", "yml", "yaml"), ZIP("Zip Archive", "zip"); diff --git a/jablib/src/main/java/org/jabref/model/entry/BibEntry.java b/jablib/src/main/java/org/jabref/model/entry/BibEntry.java index 221747e5565..c98a66bedec 100644 --- a/jablib/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/jablib/src/main/java/org/jabref/model/entry/BibEntry.java @@ -645,6 +645,17 @@ public Optional setField(Field field, String value) { return setField(field, value, EntriesEventSource.LOCAL); } + /** + * Set a field and notify listeners about the change if the value is present. Otherwise, do nothing. + */ + public Optional setField(Field field, Optional value) { + if (value.isPresent()) { + return setField(field, value.get()); + } + + return Optional.empty(); + } + /** * Remove the mapping for the field name, and notify listeners about the change. * @@ -963,9 +974,23 @@ public void unregisterListener(Object object) { } } + public BibEntry withType(EntryType type) { + setType(type); + this.setChanged(true); + return this; + } + public BibEntry withField(Field field, String value) { setField(field, value); - this.setChanged(false); + this.setChanged(true); + return this; + } + + public BibEntry withField(Field field, Optional value) { + value.ifPresent(v -> { + setField(field, v); + this.setChanged(true); + }); return this; } diff --git a/jablib/src/main/java/org/jabref/model/entry/identifier/Identifier.java b/jablib/src/main/java/org/jabref/model/entry/identifier/Identifier.java index d17ce6270bb..60036677eab 100644 --- a/jablib/src/main/java/org/jabref/model/entry/identifier/Identifier.java +++ b/jablib/src/main/java/org/jabref/model/entry/identifier/Identifier.java @@ -27,7 +27,7 @@ public interface Identifier { Optional getExternalURI(); - public static Optional from(String identifier) { + static Optional from(String identifier) { if (StringUtil.isBlank(identifier)) { return Optional.empty(); } diff --git a/jablib/src/main/java/org/jabref/model/entry/types/BiblatexNonStandardTypes.java b/jablib/src/main/java/org/jabref/model/entry/types/BiblatexNonStandardTypes.java new file mode 100644 index 00000000000..881ccb075f0 --- /dev/null +++ b/jablib/src/main/java/org/jabref/model/entry/types/BiblatexNonStandardTypes.java @@ -0,0 +1,45 @@ +package org.jabref.model.entry.types; + +import java.util.Arrays; +import java.util.Locale; +import java.util.Optional; + +public enum BiblatexNonStandardTypes implements EntryType { + Artwork("artwork"), + Audio("audio"), + Bibnote("bibnote"), + Commentary("commentary"), + Image("image"), + Jurisdiction("jurisdiction"), + Legislation("legislation"), + Legal("legal"), + Letter("letter"), + Movie("movie"), + Music("music"), + Performance("performance"), + Review("review"), + Standard("standard"), + Video("video"); + + private final String displayName; + + BiblatexNonStandardTypes(String displayName) { + this.displayName = displayName; + } + + public static Optional fromName(String name) { + return Arrays.stream(BiblatexNonStandardTypes.values()) + .filter(field -> field.getName().equalsIgnoreCase(name)) + .findAny(); + } + + @Override + public String getName() { + return displayName.toLowerCase(Locale.ENGLISH); + } + + @Override + public String getDisplayName() { + return displayName; + } +} diff --git a/jablib/src/main/java/org/jabref/model/util/ListUtil.java b/jablib/src/main/java/org/jabref/model/util/ListUtil.java index 207fab5c3d1..3eecb1bbb23 100644 --- a/jablib/src/main/java/org/jabref/model/util/ListUtil.java +++ b/jablib/src/main/java/org/jabref/model/util/ListUtil.java @@ -48,4 +48,11 @@ public static Stream getLinkedFiles(Iterable entries) { .flatMap(List::stream) .distinct(); } + + /** + * Concatenate two {@link List}s. Does not modify the original lists. + */ + public static List concat(List first, List second) { + return Stream.concat(first.stream(), second.stream()).toList(); + } } diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/TxtImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/TxtImporterTest.java new file mode 100644 index 00000000000..eeda335061f --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/TxtImporterTest.java @@ -0,0 +1,33 @@ +package org.jabref.logic.importer.fileformat; + +import org.jabref.logic.importer.fileformat.misc.TxtImporter; +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TxtImporterTest { + private TxtImporter importer; + + @BeforeEach + void setUp() { + importer = new TxtImporter(); + } + + @Test + void getFormatName() { + assertEquals("TXT", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("txt", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.TXT, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/JpgImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/JpgImporterFilesTest.java new file mode 100644 index 00000000000..12aa336ccbe --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/JpgImporterFilesTest.java @@ -0,0 +1,51 @@ +package org.jabref.logic.importer.fileformat.img; + +import java.io.IOException; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class JpgImporterFilesTest { + private static final String FILE_ENDING = ".jpg"; + + private JpgImporter importer; + + @BeforeEach + void setUp() { + importer = new JpgImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("JpgImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("JpgImporterTest") && !name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/JpgImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/JpgImporterTest.java new file mode 100644 index 00000000000..78839d27bd9 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/JpgImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.img; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class JpgImporterTest { + private JpgImporter importer; + + @BeforeEach + void setUp() { + importer = new JpgImporter(); + } + + @Test + void getFormatName() { + assertEquals("JPG", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("jpg", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.JPG, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/PngImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/PngImporterFilesTest.java new file mode 100644 index 00000000000..091cd70c4c1 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/PngImporterFilesTest.java @@ -0,0 +1,51 @@ +package org.jabref.logic.importer.fileformat.img; + +import java.io.IOException; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class PngImporterFilesTest { + private static final String FILE_ENDING = ".png"; + + private PngImporter importer; + + @BeforeEach + void setUp() { + importer = new PngImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("PngImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("PngImporterTest") && !name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/PngImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/PngImporterTest.java new file mode 100644 index 00000000000..afb00dbe214 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/img/PngImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.img; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PngImporterTest { + private PngImporter importer; + + @BeforeEach + void setUp() { + importer = new PngImporter(); + } + + @Test + void getFormatName() { + assertEquals("PNG", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("png", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.PNG, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocImporterFilesTest.java new file mode 100644 index 00000000000..56c42d294f7 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class DocImporterFilesTest { + private static final String FILE_ENDING = ".doc"; + private static final List EXCLUDE_EXTENSIONS = Constants.OLE_COMPOUND_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private DocImporter importer; + + @BeforeEach + void setUp() { + importer = new DocImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("DocImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("DocImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocImporterTest.java new file mode 100644 index 00000000000..e1d80064c35 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class DocImporterTest { + private DocImporter importer; + + @BeforeEach + void setUp() { + importer = new DocImporter(); + } + + @Test + void getFormatName() { + assertEquals("Microsoft Word 97-2003", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("doc", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.DOC, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporterFilesTest.java new file mode 100644 index 00000000000..85e426abe46 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class DocxImporterFilesTest { + private static final String FILE_ENDING = ".docx"; + private static final List EXCLUDE_EXTENSIONS = Constants.ZIP_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private DocxImporter importer; + + @BeforeEach + void setUp() { + importer = new DocxImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("DocxImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("DocxImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporterTest.java new file mode 100644 index 00000000000..b6bd526c565 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/DocxImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class DocxImporterTest { + private DocxImporter importer; + + @BeforeEach + void setUp() { + importer = new DocxImporter(); + } + + @Test + void getFormatName() { + assertEquals("Microsoft Word 2007-365", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("docx", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.DOCX, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptImporterFilesTest.java new file mode 100644 index 00000000000..af18f450345 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class PptImporterFilesTest { + private static final String FILE_ENDING = ".ppt"; + private static final List EXCLUDE_EXTENSIONS = Constants.OLE_COMPOUND_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private PptImporter importer; + + @BeforeEach + void setUp() { + importer = new PptImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("PptImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("PptImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptImporterTest.java new file mode 100644 index 00000000000..d75ad18ecbc --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PptImporterTest { + private PptImporter importer; + + @BeforeEach + void setUp() { + importer = new PptImporter(); + } + + @Test + void getFormatName() { + assertEquals("Microsoft PowerPoint 97-2003", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("ppt", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.PPT, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporterFilesTest.java new file mode 100644 index 00000000000..bfa0b0daa41 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class PptxImporterFilesTest { + private static final String FILE_ENDING = ".pptx"; + private static final List EXCLUDE_EXTENSIONS = Constants.ZIP_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private PptxImporter importer; + + @BeforeEach + void setUp() { + importer = new PptxImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("PptxImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("PptxImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporterTest.java new file mode 100644 index 00000000000..8be5537030a --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/PptxImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PptxImporterTest { + private PptxImporter importer; + + @BeforeEach + void setUp() { + importer = new PptxImporter(); + } + + @Test + void getFormatName() { + assertEquals("Microsoft PowerPoint 2007-365", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("pptx", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.PPTX, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporterFilesTest.java new file mode 100644 index 00000000000..372c9353435 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporterFilesTest.java @@ -0,0 +1,53 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class RtfImporterFilesTest { + private static final String FILE_ENDING = ".rtf"; + + private RtfImporter importer; + + @BeforeEach + void setUp() { + importer = new RtfImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("RtfImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("RtfImporterTest") && !name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporterTest.java new file mode 100644 index 00000000000..cb4b540511b --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/RtfImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class RtfImporterTest { + private RtfImporter importer; + + @BeforeEach + void setUp() { + importer = new RtfImporter(); + } + + @Test + void getFormatName() { + assertEquals("RTF", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("rtf", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.RTF, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporterFilesTest.java new file mode 100644 index 00000000000..e0ff00dabdb --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class XlsImporterFilesTest { + private static final String FILE_ENDING = ".xls"; + private static final List EXCLUDE_EXTENSIONS = Constants.OLE_COMPOUND_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private XlsImporter importer; + + @BeforeEach + void setUp() { + importer = new XlsImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("XlsImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("XlsImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporterTest.java new file mode 100644 index 00000000000..4d2c5682f4c --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class XlsImporterTest { + private XlsImporter importer; + + @BeforeEach + void setUp() { + importer = new XlsImporter(); + } + + @Test + void getFormatName() { + assertEquals("Microsoft Excel 97-2003", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("xls", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.XLS, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporterFilesTest.java new file mode 100644 index 00000000000..24e37bc6010 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class XlsxImporterFilesTest { + private static final String FILE_ENDING = ".xlsx"; + private static final List EXCLUDE_EXTENSIONS = Constants.ZIP_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private XlsxImporter importer; + + @BeforeEach + void setUp() { + importer = new XlsxImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("XlsxImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("XlsxImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporterTest.java new file mode 100644 index 00000000000..c736920de35 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/microsoft/XlsxImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.microsoft; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class XlsxImporterTest { + private XlsxImporter importer; + + @BeforeEach + void setUp() { + importer = new XlsxImporter(); + } + + @Test + void getFormatName() { + assertEquals("Microsoft Excel 2007-365", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("xlsx", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.XLSX, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdpImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdpImporterFilesTest.java new file mode 100644 index 00000000000..23329c74f40 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdpImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.odf; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class OdpImporterFilesTest { + private static final String FILE_ENDING = ".odp"; + private static final List EXCLUDE_EXTENSIONS = Constants.ZIP_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private OdpImporter importer; + + @BeforeEach + void setUp() { + importer = new OdpImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("OdpImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("OdpImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdpImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdpImporterTest.java new file mode 100644 index 00000000000..2f1071b1910 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdpImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.odf; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class OdpImporterTest { + private OdpImporter importer; + + @BeforeEach + void setUp() { + importer = new OdpImporter(); + } + + @Test + void getFormatName() { + assertEquals("OpenDocument Impress", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("odp", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.ODP, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdsImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdsImporterFilesTest.java new file mode 100644 index 00000000000..9e218d9a74f --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdsImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.odf; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class OdsImporterFilesTest { + private static final String FILE_ENDING = ".ods"; + private static final List EXCLUDE_EXTENSIONS = Constants.ZIP_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private OdsImporter importer; + + @BeforeEach + void setUp() { + importer = new OdsImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("OdsImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("OdsImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdsImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdsImporterTest.java new file mode 100644 index 00000000000..6badb81a1bc --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdsImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.odf; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class OdsImporterTest { + private OdsImporter importer; + + @BeforeEach + void setUp() { + importer = new OdsImporter(); + } + + @Test + void getFormatName() { + assertEquals("OpenDocument Calc", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("ods", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.ODS, importer.getFileType()); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdtImporterFilesTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdtImporterFilesTest.java new file mode 100644 index 00000000000..61b091ab0c1 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdtImporterFilesTest.java @@ -0,0 +1,57 @@ +package org.jabref.logic.importer.fileformat.odf; + +import java.io.IOException; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.fileformat.ImporterTestEngine; +import org.jabref.logic.importer.util.Constants; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class OdtImporterFilesTest { + private static final String FILE_ENDING = ".odt"; + private static final List EXCLUDE_EXTENSIONS = Constants.ZIP_FILES_EXTENSIONS + .stream() + .filter(ext -> !ext.equals(FILE_ENDING)) + .toList(); + + private OdtImporter importer; + + @BeforeEach + void setUp() { + importer = new OdtImporter(); + } + + private static Stream fileNames() throws IOException { + Predicate fileName = name -> name.startsWith("OdtImporterTest") && name.endsWith(FILE_ENDING); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + private static Stream invalidFileNames() throws IOException { + Predicate fileName = name -> !name.startsWith("OdtImporterTest") && EXCLUDE_EXTENSIONS.stream().noneMatch(name::endsWith); + return ImporterTestEngine.getTestFiles(fileName).stream(); + } + + @ParameterizedTest + @MethodSource("fileNames") + void isRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("invalidFileNames") + void isNotRecognizedFormat(String fileName) throws IOException { + ImporterTestEngine.testIsNotRecognizedFormat(importer, fileName); + } + + @ParameterizedTest + @MethodSource("fileNames") + void importEntries(String fileName) throws ImportException, IOException { + ImporterTestEngine.testImportEntries(importer, fileName, FILE_ENDING); + } +} diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdtImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdtImporterTest.java new file mode 100644 index 00000000000..1ca6425b3c7 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/odf/OdtImporterTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.importer.fileformat.odf; + +import org.jabref.logic.util.StandardFileType; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class OdtImporterTest { + private OdtImporter importer; + + @BeforeEach + void setUp() { + importer = new OdtImporter(); + } + + @Test + void getFormatName() { + assertEquals("OpenDocument Writer", importer.getName()); + } + + @Test + void getCLIId() { + assertEquals("odt", importer.getId()); + } + + @Test + void sGetExtensions() { + assertEquals(StandardFileType.ODT, importer.getFileType()); + } +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest1.bib new file mode 100644 index 00000000000..07e67e9c1fd --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest1.bib @@ -0,0 +1,4 @@ +@misc{, + year = {2025}, + title = {DOC Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest1.doc b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest1.doc new file mode 100644 index 00000000000..2c598fe5da8 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest1.doc differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest2.bib new file mode 100644 index 00000000000..cea00174be1 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {DOC Document from MIcrosoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest2.doc b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest2.doc new file mode 100644 index 00000000000..0c2d3a7240b Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocImporterTest2.doc differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest1.bib new file mode 100644 index 00000000000..b352c379580 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest1.bib @@ -0,0 +1,4 @@ +@misc{, + year = {2025}, + title = {DOCX Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest1.docx b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest1.docx new file mode 100644 index 00000000000..356956ccb4b Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest1.docx differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest2.bib new file mode 100644 index 00000000000..002e76e343f --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {DOCX Document from MIcrosoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest2.docx b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest2.docx new file mode 100644 index 00000000000..9b10ae2592e Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/DocxImporterTest2.docx differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/JpgImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/JpgImporterTest1.bib new file mode 100644 index 00000000000..a52bc6207dd --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/JpgImporterTest1.bib @@ -0,0 +1,6 @@ +@image{, + title = {JpgImporterTest1}, + author = {Falkenpost}, + year = {2025}, + date = {2020-01-01} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/JpgImporterTest1.jpg b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/JpgImporterTest1.jpg new file mode 100644 index 00000000000..89514fe5bf9 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/JpgImporterTest1.jpg differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest1.bib new file mode 100644 index 00000000000..606f556aef0 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest1.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {ODP Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest1.odp b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest1.odp new file mode 100644 index 00000000000..c593b3060e4 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest1.odp differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest2.bib new file mode 100644 index 00000000000..cb4b27eb8e2 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef and ruslan}, + year = {2025}, + title = {ODP Document from Microsoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest2.odp b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest2.odp new file mode 100644 index 00000000000..762cd7aa813 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdpImporterTest2.odp differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest1.bib new file mode 100644 index 00000000000..8940b337809 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest1.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {ODS Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest1.ods b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest1.ods new file mode 100644 index 00000000000..02e126ea634 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest1.ods differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest2.bib new file mode 100644 index 00000000000..eea7ee84b07 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef and ruslan}, + year = {2025}, + title = {ODS Document from Microsoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest2.ods b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest2.ods new file mode 100644 index 00000000000..cee5882368c Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdsImporterTest2.ods differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest1.bib new file mode 100644 index 00000000000..afb4c91d8c6 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest1.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {ODT Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest1.odt b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest1.odt new file mode 100644 index 00000000000..93b42672c80 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest1.odt differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest2.bib new file mode 100644 index 00000000000..22fc748866b --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef and ruslan}, + year = {2025}, + title = {ODT Document from MIcrosoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest2.odt b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest2.odt new file mode 100644 index 00000000000..15c1c20b93b Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/OdtImporterTest2.odt differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PngImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PngImporterTest1.bib new file mode 100644 index 00000000000..8ea30241704 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PngImporterTest1.bib @@ -0,0 +1,6 @@ +@image{, + title = {PngImporterTest1}, + year = {2025}, + month = {feb}, + date = {2025-02-21}, +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PngImporterTest1.png b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PngImporterTest1.png new file mode 100644 index 00000000000..e9f416b2060 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PngImporterTest1.png differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest1.bib new file mode 100644 index 00000000000..85eb4724bed --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest1.bib @@ -0,0 +1,4 @@ +@misc{, + year = {2025}, + title = {PPT Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest1.ppt b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest1.ppt new file mode 100644 index 00000000000..1cc9cb4206b Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest1.ppt differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest2.bib new file mode 100644 index 00000000000..67c2871da10 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {PPT Document from Microsoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest2.ppt b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest2.ppt new file mode 100644 index 00000000000..12f8474f7d5 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptImporterTest2.ppt differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest1.bib new file mode 100644 index 00000000000..978b1e0cc11 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest1.bib @@ -0,0 +1,4 @@ +@misc{, + year = {2025}, + title = {PPTX Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest1.pptx b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest1.pptx new file mode 100644 index 00000000000..53a9b838257 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest1.pptx differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest2.bib new file mode 100644 index 00000000000..98f7f950942 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {PPTX Document from Microsoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest2.pptx b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest2.pptx new file mode 100644 index 00000000000..f9b0190d544 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/PptxImporterTest2.pptx differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/RtfImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/RtfImporterTest1.bib new file mode 100644 index 00000000000..45ba322eb8b --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/RtfImporterTest1.bib @@ -0,0 +1,4 @@ +@misc(, + title = {RTF Document}, + year = {2025} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/RtfImporterTest1.rtf b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/RtfImporterTest1.rtf new file mode 100644 index 00000000000..8a0952e7474 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/RtfImporterTest1.rtf @@ -0,0 +1,14 @@ +{\rtf1\ansi\deff3\adeflang1025 +{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Liberation Serif{\*\falt Times New Roman};}{\f4\froman\fprq2\fcharset0 Liberation Sans{\*\falt Arial};}{\f5\fnil\fprq2\fcharset0 0;}{\f6\fnil\fprq2\fcharset0 Noto Sans CJK SC;}{\f7\fnil\fprq2\fcharset0 FreeSans;}} +{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;} +{\stylesheet{\s0\snext0\rtlch\af7\afs24\alang1081 \ltrch\lang1058\langfe2052\hich\af3\loch\widctlpar\hyphpar0\ltrpar\cf0\f3\fs24\lang1058\kerning1\dbch\af5\langfe2052 Normal;} +{\s15\sbasedon0\snext16\rtlch\af7\afs28 \ltrch\hich\af4\loch\sb240\sa120\keepn\f4\fs28\dbch\af6 Heading;} +{\s16\sbasedon0\snext16\loch\sl276\slmult1\sb0\sa140 Body Text;} +{\s17\sbasedon16\snext17\rtlch\af7 \ltrch\loch\sl240\slmult1\sb0\sa0 List;} +{\s18\sbasedon0\snext18\rtlch\af7\afs24\ai \ltrch\loch\sb120\sa120\fs24\i caption;} +{\s19\sbasedon0\snext19\rtlch\af7 \ltrch Index;} +}{\*\generator LibreOffice/25.2.3.2$Linux_X86_64 LibreOffice_project/520$Build-2}{\info{\title RTF Document}{\creatim\yr2025\mo6\dy15\hr1\min1}{\revtim\yr2025\mo6\dy15\hr1\min10}{\printim\yr0\mo0\dy0\hr0\min0}}{\*\userprops}\deftab709 +\hyphauto1\viewscale160\formshade\nobrkwrptbl\paperh16838\paperw11906\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\sftnnar\saftnnrlc\sectunlocked1\pgwsxn11906\pghsxn16838\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\fet\aftnrstcont\aftnstart1\aftnnrlc +{\*\ftnsep\chftnsep}\pgndec\pard\plain \s0\rtlch\af7\afs24\alang1081 \ltrch\lang1058\langfe2052\hich\af3\loch\widctlpar\hyphpar0\ltrpar\cf0\f3\fs24\lang1058\kerning1\dbch\af5\langfe2052\ql{\loch +Hello, World!} +\par } \ No newline at end of file diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/Test.java b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/Test.java new file mode 100644 index 00000000000..eafe708416a --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/Test.java @@ -0,0 +1,45 @@ +//DEPS org.apache.tika:tika-core:3.2.0 +//DEPS org.apache.tika:tika-parsers-standard-package:3.2.0 + +import org.apache.tika.Tika; +import org.apache.tika.metadata.Metadata; +import org.apache.tika.parser.AutoDetectParser; +import org.apache.tika.parser.Parser; +import org.apache.tika.parser.image.JpegParser; +import org.apache.tika.sax.BodyContentHandler; +import org.apache.tika.parser.ParseContext; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.File; + +public class Test { + + public static void main(String[] args) throws Exception { + if (args.length < 1) { + System.err.println("Usage: jbang PrintMetadata.java "); + System.exit(1); + } + + String filePath = args[0]; + File file = new File(filePath); + if (!file.exists() || !file.isFile()) { + System.err.println("File not found: " + filePath); + System.exit(1); + } + + try (InputStream stream = new FileInputStream(file)) { + JpegParser parser = new JpegParser(); + Metadata metadata = new Metadata(); + BodyContentHandler handler = new BodyContentHandler(); + ParseContext context = new ParseContext(); + context.set(Parser.class, parser); + parser.parse(stream, handler, metadata, context); + + System.out.println("Metadata" + metadata.get(Metadata.ORIGINAL_DATE) + ":"); + for (String name : metadata.names()) { + System.out.printf(" %s: %s%n", name, metadata.get(name)); + } + } + } +} + diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/TxtImporterTest1.txt b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/TxtImporterTest1.txt new file mode 100644 index 00000000000..8ab686eafeb --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/TxtImporterTest1.txt @@ -0,0 +1 @@ +Hello, World! diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest1.bib new file mode 100644 index 00000000000..3a3a953f7d6 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest1.bib @@ -0,0 +1,4 @@ +@misc{, + year = {2025}, + title = {XLS Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest1.xls b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest1.xls new file mode 100644 index 00000000000..069cf1a85ca Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest1.xls differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest2.bib new file mode 100644 index 00000000000..dffa8b8129e --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {XLS Document from Microsoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest2.xls b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest2.xls new file mode 100644 index 00000000000..ce8d26b1e80 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsImporterTest2.xls differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest1.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest1.bib new file mode 100644 index 00000000000..f540f2a6811 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest1.bib @@ -0,0 +1,4 @@ +@misc{, + year = {2025}, + title = {XLSX Document} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest1.xlsx b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest1.xlsx new file mode 100644 index 00000000000..8a1a52c19e6 Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest1.xlsx differ diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest2.bib b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest2.bib new file mode 100644 index 00000000000..f9b3c28d988 --- /dev/null +++ b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest2.bib @@ -0,0 +1,5 @@ +@misc{, + author = {JabRef}, + year = {2025}, + title = {XLSX Document from Microsoft Office} +} diff --git a/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest2.xlsx b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest2.xlsx new file mode 100644 index 00000000000..0e0bfc4763a Binary files /dev/null and b/jablib/src/test/resources/org/jabref/logic/importer/fileformat/XlsxImporterTest2.xlsx differ