-
-
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
Add XMP Exporter #3895
Add XMP Exporter #3895
Conversation
Adding a new exporter for xmp export in a .xmp file.
DublinCoreSchema dcSchema = meta.createAndAddDublinCoreSchema(); | ||
XmpUtilWriter.writeToDCSchema(dcSchema, entry, null, Globals.prefs.getXMPPreferences()); | ||
} | ||
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
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.
You should always wrap those Input and Output stream in the try with resources construct, that ensures that the streams are autoclosed:
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
* Writes the information of the bib entry to the dublin core schema using | ||
* a custom extractor. | ||
* | ||
* @param dcSchema |
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.
Remove non-commented parameters - This should automatically be done in IntelliJ if you use autoformat (ctrl+alt+l)
serializer.serialize(meta, os, true); | ||
return os.toString(StandardCharsets.UTF_8.name()); | ||
} catch (TransformerException e) { | ||
LOGGER.warn("Tranformation into xmp not possible: " + e.getMessage()); |
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.
Why not logging the exception itself, too?
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.
Do you mean the stack trace of the exception?
Is there a smart solution in JabRef to print the stack trace with the logger (maybe an utility method)?
Otherwise, I would use something like this:
Arrays.asList(exception.getStackTrace())
.stream()
.map(Objects::toString)
.collect(Collectors.joining("\n"))
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.
The logger methods have a second parameter which accepts a throwable /exception.
The stack trace will then automatically be printed (handled by the logger itself)
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.
The code usually looks something like LOGGER.warn("Transformation in xmp not possible", e)
.
@@ -159,6 +171,26 @@ private static void writeDublinCore(PDDocument document, | |||
catalog.setMetadata(metadataStream); | |||
} | |||
|
|||
public static String generateXmpString(List<BibEntry> entries) { |
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.
Please comment that it returns an empty string if something goes wrong.
@@ -26,6 +26,7 @@ | |||
DIN_1505(Localization.lang("%0 file", "DIN 1505"), "rtf"), | |||
ENDNOTE(Localization.lang("%0 file", "EndNote/Refer"), "ref", "enw"), | |||
ENDNOTE_XML(Localization.lang("%0 file", "EndNote XML"), "xml"), | |||
ENDNOTE_XMP(Localization.lang("%0 file", "EndNote Xmp"), "xmp"), |
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.
Why "Endnote XMP"? What has "Endnote" todo with XMP? I would just use "XMP", because it is an ISO Standard, not something from Endnote.
XMPMetadata meta = XMPMetadata.createXMPMetadata(); | ||
for (BibEntry entry : entries) { | ||
DublinCoreSchema dcSchema = meta.createAndAddDublinCoreSchema(); | ||
XmpUtilWriter.writeToDCSchema(dcSchema, entry, null, Globals.prefs.getXMPPreferences()); |
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.
Globals should never be asked. The XMPPreferences should be passed to the method, not taken from globals!
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.
Is it possible to add a test case?
XMPMetadata meta = XMPMetadata.createXMPMetadata(); | ||
for (BibEntry entry : entries) { | ||
DublinCoreSchema dcSchema = meta.createAndAddDublinCoreSchema(); | ||
XmpUtilWriter.writeToDCSchema(dcSchema, entry, null, xmpPreferences); |
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.
Is it possible to add an additional method writeToDCSchema
with 3 parameters. We should avoid null
parameters.
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.
The code looks good to me.
The cli support is planned for the next days :)
If you add an exporter, then you can automatically use the cli to call it. http://help.jabref.org/en/CommandLine
} | ||
|
||
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { | ||
writer.write(XmpUtilWriter.generateXmpString(entries, Globals.prefs.getXMPPreferences())); |
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.
Can you please pass the Globals.prefs.getXMPPreferences()
dependency as a constructor argument. We are currently trying to reduce the number of calls to Globals
.
} | ||
|
||
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { | ||
writer.write(XmpUtilWriter.generateXmpString(entries, Globals.prefs.getXMPPreferences())); |
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.
Can you please pass the Globals.prefs.getXMPPreferences()
dependency as a constructor argument. We are currently trying to reduce the number of calls to Globals
.
serializer.serialize(meta, os, true); | ||
return os.toString(StandardCharsets.UTF_8.name()); | ||
} catch (TransformerException e) { | ||
LOGGER.warn("Tranformation into xmp not possible: " + e.getMessage()); |
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.
Personally, I would wrap these Exceptions in an IOException and then rethrow.
I have a few question to the cli exporter. So there is a xmp importer for the import of the metadata in pdf files. Another question is, if the discussed cli option is possible under the -o option (or if it is only possible under the -xmp tag) to generate a plain xmp file from a bib file? Or to generate multiple xmp files for every single entry in the bib file. In this PR, there is an exporter, but this exporter is only accessible via the GUI. Is this sufficient? |
Doesn't |
"If only filename is specified, it will be exported in BibTeX format. If the filename is followed by a comma and an export format, the given export filter will be used." (JabRef Help) The functionality is an exporter, but only to .bib files and importes the exported entries from different sources (in my case reads the xmp metadata from a .pdf file and writes it to the .bib file) -o export.bib import.pdf, xmp I think, the requested option is not possible with the current architectuer under the -o option, if I didn't overlooked something. |
Is it possible, that the help page is not up-to-date? |
Now, it worked for: There were a few strings and options, I configured the wrong way. |
@johannes-manner Feel free to update the help page accordingly |
@johannes-manner
Edit// You just need to pass the XMP Preferences here: |
|
||
private final XmpPreferences xmpPreferences; | ||
|
||
public XmpExporter(XmpPreferences xmpPreferences) { |
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.
How do the other exporters get their preferences? Shouldn't they have the same issue with the Globals dependency?
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.
They get their prefs in the Exporter Factory. In this case it must only be expanded to pass the xmp prefs from the existing pref object
…for generating a single .xmp for every bib entry
Ready for final review. There is now also an option to generate single .xmp files for every entry in a .bib file. Commented in the help page - command line options :) (https://github.com/JabRef/help.jabref.org/pull/181) |
Also wikipedia writes it with capital M and P. A would suggest to merge the changes here and to merge the other pull request and fixing these issues later on. Maybe @koppor you can open a issue @jabref/koppor? |
@johannes-manner Class Prefixes Xmp, but I think @koppor is refering to the extension description |
Yeah, the class is fine with "Xmp", because of Google Style Guide. The interface to the user should use the offical term. Same with URI, ... |
I will update the description with the fix for the mentioned issues :) |
Just one more question, what exactly does the dialog Tools -> Writing XMP Data to Entry display? |
@Siedlerchr You mean Tools->Write XMP metadata to PDFs? |
I'll merge. The JavaFX thing and my XMP wishes can be done in a separate PR. 😇 . Thank you for the continuous work on that. Reading http://dublincore.org/documents/dc-xml-guidelines/ and https://github.com/CrossRef/pdfmark/blob/master/test-data/random-xmp-example.xmp and https://www.pdflib.com/de/knowledge-base/xmp-metadaten/kostenloser-xmp-validator/, this topic is not easy.
|
Yes, I wondered what there is displayed when I checked the dialogs |
* upstream/master: Pdf exporter - delete xmp actions in the menu bar and the cli option (#3947) Improve search performance (#3950) New Crowdin translations (#3949) Update dependencies for junit, mockito and checkstyle (#3951) Add XMP Exporter (#3895) Switch colors of search icon for the two search modes (#3871) # Conflicts: # src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Refs koppor#319.
Adds the first functionality to export the bib entries in a single .xmp file.
@koppor For a first review: Please check the output format of the new .xmp file.
There is also a tag included. Should I remove this tag?
The cli support is planned for the next days :)