Skip to content

Commit

Permalink
First approach for implementing PDF Exporter
Browse files Browse the repository at this point in the history
Remove code that produces NPE
  • Loading branch information
Siedlerchr committed Apr 2, 2017
1 parent 9be770c commit bd508ad
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
6 changes: 0 additions & 6 deletions src/main/java/org/jabref/logic/exporter/ExportFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,6 @@ public void performExport(final BibDatabaseContext databaseContext, final String

}

@Override
public void performExport(final BibDatabaseContext databaseContext, Path file, final Charset encoding,
List<BibEntry> entries) throws Exception {
performExport(databaseContext, file.getFileName().toString(), encoding, entries);
}

/**
* See if there is a name formatter file bundled with this export format. If so, read
* all the name formatters so they can be used by the filter layouts.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/logic/exporter/ExportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void initAllExports(Map<String, ExportFormat> customFormats,
ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator());
ExportFormats.putFormat(new MSBibExportFormat());
ExportFormats.putFormat(new ModsExportFormat());
ExportFormats.putFormat(new PdfFileExporter());

// Now add custom export formats
for (IExportFormat format : customFormats.values()) {
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/org/jabref/logic/exporter/IExportFormat.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.logic.exporter;

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

import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -38,18 +37,4 @@ public interface IExportFormat {
void performExport(BibDatabaseContext databaseContext, String file, Charset encoding, List<BibEntry> entries)
throws Exception;

/**
* Perform the Export.
* Gets the path as a java.nio.path instead of a string.
*
* @param databaseContext the database to export from.
* @param file the Path to the file to write to.The path should be an java.nio.Path
* @param encoding The encoding to use.
* @param entries A list containing all entries that
* should be exported. The list of entries must be non null
* @throws Exception
*/
void performExport(BibDatabaseContext databaseContext, Path file, Charset encoding, List<BibEntry> entries)
throws Exception;

}
39 changes: 39 additions & 0 deletions src/main/java/org/jabref/logic/exporter/PdfFileExporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jabref.logic.exporter;

import java.nio.charset.Charset;
import java.util.List;
import org.jabref.logic.TypedBibEntry;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.ParsedFileField;

public class PdfFileExporter extends ExportFormat {

public PdfFileExporter() {
super("PDF files", "PDF", null, null, ".pdf");
}
@Override
public void performExport(final BibDatabaseContext databaseContext, String file, final Charset encoding,
List<BibEntry> entries) throws Exception {

for (BibEntry entry : entries) {
TypedBibEntry typedEntry = new TypedBibEntry(entry, databaseContext);

List<ParsedFileField> files = typedEntry.getFiles();
for (ParsedFileField fileEntry : files) {
String fileName = fileEntry.getLink();

// databaseContext.getFileDirectories(preferences)
// Optional<File> oldFile = FileUtil.expandFilename(fileName,
// databaseContext.getFileDirectories(Globals.prefs.getFileDirectoryPreferences()));

System.out.println("Export pdfs");
// FileUtil.copyFile(oldFile.get().toPath(), file, false);

}

}

}

}

0 comments on commit bd508ad

Please sign in to comment.