Skip to content

Commit

Permalink
Pdf exporter - delete xmp actions in the menu bar and the cli option (#…
Browse files Browse the repository at this point in the history
…3947)

* Add Xmp GUI Export

Adding a new exporter for xmp export in a .xmp file.

* updated code with the requested changes

* XMP export works now for single elements

* Changed the xmp preference distribution, added a split functionality for generating a single .xmp for every bib entry

* Added exporter tests for XmpExporter

* Writing another exporter for xmp in pdf files to get xmp in production

* Delete -xmp cli functionality

Deleted the -xmp cli option, because the pdf exporter has now the same functionality and is embedded within the common cli exporter infrastructure.

* Rename PdfExporter to XmpPdfExporter

* Changed FileType XMP to PDF_XMP

* Fixed tests
  • Loading branch information
johannes-manner authored and Siedlerchr committed Apr 13, 2018
1 parent 68b3797 commit 1d9ce25
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 147 deletions.
5 changes: 0 additions & 5 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ private List<ParserResult> processArguments() {
doAuxImport(loaded);
}

if (cli.isXmpFacilities()) {
XmpUtilMain.executeXmpConsoleApplicaton();
System.exit(0);
}

return loaded;
}

Expand Down
9 changes: 0 additions & 9 deletions src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ public String getExportMatches() {
return cl.getOptionValue("exportMatches");
}

public boolean isXmpFacilities() {
return cl.hasOption("readAndWriteXmpMetadata");
}

public boolean isGenerateBibtexKeys() { return cl.hasOption("generateBibtexKeys"); }

public boolean isAutomaticallySetFileLinks() { return cl.hasOption("automaticallySetFileLinks"); }
Expand Down Expand Up @@ -236,11 +232,6 @@ private Options getOptions() {
desc(Localization.lang("Automatically set file links")).
build());

options.addOption(Option.builder("xmp").
longOpt("readAndWriteXmpMetadata").
desc("Read and write xmp metadata from/to pdf files").
build());

return options;
}

Expand Down
129 changes: 0 additions & 129 deletions src/main/java/org/jabref/cli/XmpUtilMain.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static ExporterFactory create(Map<String, TemplateExporter> customFormats
exporters.add(new MSBibExporter());
exporters.add(new ModsExporter());
exporters.add(new XmpExporter(xmpPreferences));
exporters.add(new XmpPdfExporter(xmpPreferences));

// Now add custom export formats
exporters.addAll(customFormats.values());
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/jabref/logic/exporter/XmpPdfExporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jabref.logic.exporter;

import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

import org.jabref.logic.util.FileType;
import org.jabref.logic.xmp.XmpPreferences;
import org.jabref.logic.xmp.XmpUtilWriter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

public class XmpPdfExporter extends Exporter {

private final XmpPreferences xmpPreferences;

public XmpPdfExporter(XmpPreferences xmpPreferences) {
super("pdf", FileType.PDF_XMP.getDescription(), FileType.PDF_XMP);
this.xmpPreferences = xmpPreferences;
}

@Override
public void export(BibDatabaseContext databaseContext, Path pdfFile, Charset encoding, List<BibEntry> entries) throws Exception {

Objects.requireNonNull(databaseContext);
Objects.requireNonNull(pdfFile);
Objects.requireNonNull(entries);

if (pdfFile.toString().endsWith(".pdf")) {
XmpUtilWriter.writeXmp(pdfFile, entries, databaseContext.getDatabase(), xmpPreferences);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getName() {

@Override
public FileType getFileType() {
return FileType.XMP;
return FileType.PDF_XMP;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/util/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum FileType {
RIS(Localization.lang("%0 file", "RIS"), "ris"),
SILVER_PLATTER(Localization.lang("%0 file", "SilverPlatter"), "dat", "txt"),
SIMPLE_HTML(Localization.lang("%0 file", Localization.lang("Simple HTML")), "html"),
XMP(Localization.lang("XMP-annotated PDF"), "pdf"),
PDF_XMP(Localization.lang("XMP-annotated PDF"), "pdf"),
PLAIN_XMP(Localization.lang("%0 file", "XMP"), "xmp"),

AUX(Localization.lang("%0 file", "AUX"), "aux"),
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ private static void writeDublinCore(PDDocument document,
if (metaRaw == null) {
meta = XMPMetadata.createXMPMetadata();
} else {
meta = XmpUtilShared.parseXmpMetadata(metaRaw.createInputStream());
try {
meta = XmpUtilShared.parseXmpMetadata(metaRaw.createInputStream());
// In case, that the pdf file has no namespace definition for xmp,
// but metadata in a different format, the parser throws an exception
// Creating an empty xmp metadata element solves this problem
} catch (IOException e) {
meta = XMPMetadata.createXMPMetadata();
}
}

// Remove all current Dublin-Core schemas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testGetFormatName() {

@Test
public void testsGetExtensions() {
assertEquals(FileType.XMP, importer.getFileType());
assertEquals(FileType.PDF_XMP, importer.getFileType());
}

@Test
Expand Down

0 comments on commit 1d9ce25

Please sign in to comment.