Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to extended enums for fields and entry types #5148

Merged
merged 22 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public TemplateExporter(String displayName, String consoleName, String lfFileNam
*
* @param name to display to the user and to call this format in the console.
* @param lfFileName Name of the main layout file.
* @param directory Directory in which to find the layout file.
* @param extension May or may not contain the . (for instance .txt).
* @param layoutPreferences Preferences for the layout
* @param savePreferences Preferences for saving
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/exporter/XmpExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -56,7 +56,7 @@ public void export(BibDatabaseContext databaseContext, Path file, Charset encodi
entryFile = Paths.get(file.getParent().toString() + "/" + suffix);
}

this.writeBibToXmp(entryFile, Arrays.asList(entry), encoding);
this.writeBibToXmp(entryFile, Collections.singletonList(entry), encoding);
}
} else {
this.writeBibToXmp(file, entries, encoding);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.Calendar;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
Expand Down Expand Up @@ -344,13 +345,14 @@ private void fillCustomField(Field field, String value) {
}

public void fillDublinCoreSchema() {

// Query privacy filter settings
boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter();
// Fields for which not to write XMP data later on:
Set<Field> filters = new TreeSet<>(xmpPreferences.getXmpPrivacyFilter());

for (Entry<Field, String> field : bibEntry.getFieldMap().entrySet()) {
Set<Entry<Field, String>> fieldValues = new TreeSet<>(Comparator.comparing(fieldStringEntry -> fieldStringEntry.getKey().getName()));
fieldValues.addAll(bibEntry.getFieldMap().entrySet());
for (Entry<Field, String> field : fieldValues) {
if (useXmpPrivacyFilter && filters.contains(field.getKey())) {
continue;
}
Expand Down
33 changes: 5 additions & 28 deletions src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,11 @@ private static void writeToDCSchema(DublinCoreSchema dcSchema, BibEntry entry, B
* @param entry The entry, which is added to the dublin core metadata.
* @param xmpPreferences The user's xmp preferences.
*/
private static void writeToDCSchema(DublinCoreSchema dcSchema, BibEntry entry,
XmpPreferences xmpPreferences) {

private static void writeToDCSchema(DublinCoreSchema dcSchema, BibEntry entry, XmpPreferences xmpPreferences) {
DublinCoreExtractor dcExtractor = new DublinCoreExtractor(dcSchema, xmpPreferences, entry);
dcExtractor.fillDublinCoreSchema();
}

/**
* Try to write the given BibTexEntry as a DublinCore XMP Schema
*
* Existing DublinCore schemas in the document are not modified.
*
* @param document The pdf document to write to.
* @param entry The BibTeX entry that is written as a schema.
* @param database maybenull An optional database which the given BibTeX entries belong to, which will be used to
* resolve strings. If the database is null the strings will not be resolved.
*/
public static void writeDublinCore(PDDocument document, BibEntry entry,
BibDatabase database, XmpPreferences xmpPreferences) throws IOException, TransformerException {

List<BibEntry> entries = new ArrayList<>();
entries.add(entry);

XmpUtilWriter.writeDublinCore(document, entries, database, xmpPreferences);
}

/**
* Try to write the given BibTexEntries as DublinCore XMP Schemas
*
Expand Down Expand Up @@ -206,7 +185,7 @@ private static void writeDublinCore(PDDocument document,
* @return If something goes wrong (e.g. an exception is thrown), the method returns an empty string,
* otherwise it returns the xmp metadata as a string in dublin core format.
*/
public static String generateXmpStringWithXmpDeclaration(List<BibEntry> entries, XmpPreferences xmpPreferences) {
private static String generateXmpStringWithXmpDeclaration(List<BibEntry> entries, XmpPreferences xmpPreferences) {
XMPMetadata meta = XMPMetadata.createXMPMetadata();
for (BibEntry entry : entries) {
DublinCoreSchema dcSchema = meta.createAndAddDublinCoreSchema();
Expand Down Expand Up @@ -243,12 +222,10 @@ public static String generateXmpStringWithoutXmpDeclaration(List<BibEntry> entri
String xmpContent = XmpUtilWriter.generateXmpStringWithXmpDeclaration(entries, xmpPreferences);
// remove the <?xpacket *> tags to enable the usage of the CTAN package xmpincl
Predicate<String> isBeginOrEndTag = s -> s.contains(XMP_BEGIN_END_TAG);
String updatedXmpContent = Arrays.stream(xmpContent.split(System.lineSeparator()))
.filter(isBeginOrEndTag.negate())
.map(line -> line)
.collect(Collectors.joining(System.lineSeparator()));

return updatedXmpContent;
return Arrays.stream(xmpContent.split(System.lineSeparator()))
.filter(isBeginOrEndTag.negate())
.collect(Collectors.joining(System.lineSeparator()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception {
"@Customizedtype{," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE
+ "@Comment{jabref-meta: databaseType:bibtex;}"
+ OS.NEWLINE + OS.NEWLINE
+ "@Comment{jabref-entrytype: customizedType: req[title] opt[year]}" + OS.NEWLINE,
+ "@Comment{jabref-entrytype: customizedtype: req[title] opt[year]}" + OS.NEWLINE,
stringWriter.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DocBook5ExporterTest {
public List<BibEntry> entries;

private Path xmlFile;
private Exporter exportFormat;
private Exporter exporter;

@BeforeEach
void setUp() throws URISyntaxException {
Expand All @@ -50,7 +50,7 @@ void setUp() throws URISyntaxException {
XmpPreferences xmpPreferences = mock(XmpPreferences.class);
ExporterFactory exporterFactory = ExporterFactory.create(customFormats, layoutPreferences, savePreferences, xmpPreferences);

exportFormat = exporterFactory.getExporterByName("docbook5").get();
exporter = exporterFactory.getExporterByName("docbook5").get();

LocalDate myDate = LocalDate.of(2018, 1, 1);

Expand All @@ -69,7 +69,7 @@ void setUp() throws URISyntaxException {
void testPerformExportForSingleEntry(@TempDir Path testFolder) throws Exception {
Path path = testFolder.resolve("ThisIsARandomlyNamedFile");

exportFormat.export(databaseContext, path, charset, entries);
exporter.export(databaseContext, path, charset, entries);

Builder control = Input.from(Files.newInputStream(xmlFile));
Builder test = Input.from(Files.newInputStream(path));
Expand Down
10 changes: 1 addition & 9 deletions src/test/java/org/jabref/logic/exporter/XmpExporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.xmp.XmpPreferences;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -19,7 +17,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Answers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
Expand All @@ -34,12 +31,7 @@ public class XmpExporterTest {

@BeforeEach
public void setUp() {
List<TemplateExporter> customFormats = new ArrayList<>();
LayoutFormatterPreferences layoutPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);
SavePreferences savePreferences = mock(SavePreferences.class);
ExporterFactory exporterFactory = ExporterFactory.create(customFormats, layoutPreferences, savePreferences, xmpPreferences);

exporter = exporterFactory.getExporterByName("xmp").get();
exporter = new XmpExporter(xmpPreferences);

databaseContext = new BibDatabaseContext();
encoding = StandardCharsets.UTF_8;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
<mods:mods>
<mods:genre>article</mods:genre>
<mods:abstract>abstract</mods:abstract>
Expand All @@ -11,7 +11,7 @@
<mods:namePart type="given">know</mods:namePart>
</mods:name>
<mods:name type="personal">
<mods:namePart type="family">Realy</mods:namePart>
<mods:namePart type="family"> Realy</mods:namePart>
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
<mods:namePart type="given">don't</mods:namePart>
<mods:namePart type="given">know</mods:namePart>
</mods:name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
<mods:mods>
<mods:genre>book</mods:genre>
<mods:identifier type="isbn">123456789</mods:identifier>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
<mods:mods>
<mods:genre>article</mods:genre>
<mods:name type="personal">
Expand All @@ -8,11 +8,11 @@
<mods:namePart type="given">Sahukar</mods:namePart>
</mods:name>
<mods:name type="personal">
<mods:namePart type="family">Vinodhkumar</mods:namePart>
<mods:namePart type="family"> Vinodhkumar</mods:namePart>
<mods:namePart type="given">Palani</mods:namePart>
</mods:name>
<mods:name type="personal">
<mods:namePart type="family">Selvamani</mods:namePart>
<mods:namePart type="family"> Selvamani</mods:namePart>
</mods:name>
<mods:subject>
<mods:topic>Biomarkers</mods:topic>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
<mods:mods ID="ShruthiVinodhkumarSelvamani2016">
<mods:identifier type="citekey">ShruthiVinodhkumarSelvamani2016</mods:identifier>
<mods:genre>article</mods:genre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mods:modsCollection xmlns:mods="http://www.loc.gov/mods/v3" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/standards/mods/v3/mods-3-6.xsd">
<mods:mods ID="test">
<mods:identifier type="citekey">test</mods:identifier>
<mods:genre>inbook</mods:genre>
Expand Down