-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[WIP] Dublin Core #3710
[WIP] Dublin Core #3710
Changes from 14 commits
282f066
b88c1c8
3e0dd1d
20d4c8a
c593f2b
cddba9d
06fbcba
69b712f
ae26532
9cc529f
366aeed
8c2b446
79f1134
be7db0f
d32e8d7
d5dd993
523a1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package org.jabref.cli; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Paths; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
@@ -18,13 +17,14 @@ | |
import org.jabref.logic.importer.ParserResult; | ||
import org.jabref.logic.importer.fileformat.BibtexParser; | ||
import org.jabref.logic.xmp.XMPPreferences; | ||
import org.jabref.logic.xmp.XMPUtil; | ||
import org.jabref.logic.xmp.XMPUtilReader; | ||
import org.jabref.logic.xmp.XMPUtilWriter; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
import org.apache.jempbox.impl.XMLUtil; | ||
import org.apache.jempbox.xmp.XMPMetadata; | ||
import org.apache.xmpbox.XMPMetadata; | ||
import org.apache.xmpbox.xml.XmpSerializer; | ||
|
||
public class XMPUtilMain { | ||
|
||
|
@@ -65,15 +65,13 @@ public static void main(String[] args) throws IOException, TransformerException | |
XMPPreferences xmpPreferences = Globals.prefs.getXMPPreferences(); | ||
ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences(); | ||
|
||
switch (args.length) { | ||
case 0: | ||
int argsLength = args.length; | ||
if (argsLength == 0) { | ||
usage(); | ||
break; | ||
case 1: | ||
|
||
} else if (argsLength == 1) { | ||
if (args[0].endsWith(".pdf")) { | ||
// Read from pdf and write as BibTex | ||
List<BibEntry> l = XMPUtil.readXMP(new File(args[0]), xmpPreferences); | ||
List<BibEntry> l = XMPUtilReader.readXMP(args[0], xmpPreferences); | ||
|
||
BibEntryWriter bibtexEntryWriter = new BibEntryWriter( | ||
new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), false); | ||
|
@@ -92,63 +90,62 @@ public static void main(String[] args) throws IOException, TransformerException | |
|
||
if (entries.isEmpty()) { | ||
System.err.println("Could not find BibEntry in " + args[0]); | ||
} else { | ||
System.out.println(XMPUtil.toXMP(entries, result.getDatabase(), xmpPreferences)); | ||
} | ||
} | ||
} else { | ||
usage(); | ||
} | ||
break; | ||
case 2: | ||
} else if (argsLength == 2) { | ||
if ("-x".equals(args[0]) && args[1].endsWith(".pdf")) { | ||
// Read from pdf and write as BibTex | ||
Optional<XMPMetadata> meta = XMPUtil.readRawXMP(new File(args[1])); | ||
Optional<List<XMPMetadata>> meta = XMPUtilReader.readRawXMP(Paths.get(args[1])); | ||
|
||
if (meta.isPresent()) { | ||
XMLUtil.save(meta.get().getXMPDocument(), System.out, StandardCharsets.UTF_8.name()); | ||
XmpSerializer serializer = new XmpSerializer(); | ||
serializer.serialize(meta.get().get(0), System.out, true); | ||
} else { | ||
System.err.println("The given pdf does not contain any XMP-metadata."); | ||
} | ||
break; | ||
return; | ||
} | ||
|
||
if (args[0].endsWith(".bib") && args[1].endsWith(".pdf")) { | ||
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(new FileReader(args[0])); | ||
try (FileReader reader = new FileReader(args[0])) { | ||
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(reader); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, but does the parser accepts an inputStream? Then you could use Files.newInputStream... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No overloaded parse method, which would accept an InputStream. |
||
|
||
Collection<BibEntry> entries = result.getDatabase().getEntries(); | ||
List<BibEntry> entries = result.getDatabase().getEntries(); | ||
|
||
if (entries.isEmpty()) { | ||
System.err.println("Could not find BibEntry in " + args[0]); | ||
} else { | ||
XMPUtil.writeXMP(new File(args[1]), entries, result.getDatabase(), false, xmpPreferences); | ||
System.out.println("XMP written."); | ||
if (entries.isEmpty()) { | ||
System.err.println("Could not find BibEntry in " + args[0]); | ||
} else { | ||
XMPUtilWriter.writeXMP(Paths.get(args[1]), entries, result.getDatabase(), xmpPreferences); | ||
System.out.println("XMP written."); | ||
} | ||
} | ||
break; | ||
return; | ||
} | ||
|
||
usage(); | ||
break; | ||
case 3: | ||
} else if (argsLength == 3) { | ||
if (!args[1].endsWith(".bib") && !args[2].endsWith(".pdf")) { | ||
usage(); | ||
break; | ||
return; | ||
} | ||
|
||
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(new FileReader(args[1])); | ||
try (FileReader reader = new FileReader(args[1])) { | ||
ParserResult result = new BibtexParser(importFormatPreferences, Globals.getFileUpdateMonitor()).parse(reader); | ||
|
||
Optional<BibEntry> bibEntry = result.getDatabase().getEntryByKey(args[0]); | ||
Optional<BibEntry> bibEntry = result.getDatabase().getEntryByKey(args[0]); | ||
|
||
if (bibEntry.isPresent()) { | ||
XMPUtil.writeXMP(new File(args[2]), bibEntry.get(), result.getDatabase(), xmpPreferences); | ||
if (bibEntry.isPresent()) { | ||
XMPUtilWriter.writeXMP(Paths.get(args[2]), bibEntry.get(), result.getDatabase(), xmpPreferences); | ||
|
||
System.out.println("XMP written."); | ||
} else { | ||
System.err.println("Could not find BibEntry " + args[0] + " in " + args[0]); | ||
System.out.println("XMP written."); | ||
} else { | ||
System.err.println("Could not find BibEntry " + args[0] + " in " + args[0]); | ||
} | ||
} | ||
break; | ||
|
||
default: | ||
} else { | ||
usage(); | ||
} | ||
} | ||
|
@@ -167,13 +164,13 @@ private static void usage() { | |
System.out.println("Read from PDF and print raw XMP:"); | ||
System.out.println(" xmpUtil -x <pdf>"); | ||
System.out | ||
.println("Write the entry in <bib> given by <key> to the PDF:"); | ||
.println("Write the entry in <bib> given by <key> to the PDF:"); | ||
System.out.println(" xmpUtil <key> <bib> <pdf>"); | ||
System.out.println("Write all entries in <bib> to the PDF:"); | ||
System.out.println(" xmpUtil <bib> <pdf>"); | ||
System.out.println(""); | ||
System.out | ||
.println("To report bugs visit https://issues.jabref.org"); | ||
.println("To report bugs visit https://issues.jabref.org"); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further below (starting at line 218), we added exceptions for the update dependencies task. These are now invalid and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE