Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.xmp

public Class XmpUtilWriter

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .UnsupportedEncodingException, java.nio.charset.StandardCharsets, java.nio.file.Path, java.util.Arrays, .List, java.util.function.Predicate, java.util.stream.Collectors, javax.xml.transform.TransformerException, org.jabref.logic.exporter.AtomicFileOutputStream, org.jabref.logic.formatter.casechanger.UnprotectTermsFormatter, org.jabref.model.database.BibDatabase, org.jabref.model.entry.BibEntry, org.jabref.model.entry.field.Field, .StandardField, org.jabref.model.schema.DublinCoreSchemaCustom, org.apache.pdfbox.Loader, org.apache.pdfbox.pdmodel.PDDocument, .PDDocumentCatalog, .PDDocumentInformation, org.apache.pdfbox.pdmodel.common.PDMetadata, org.apache.xmpbox.XMPMetadata, org.apache.xmpbox.schema.DublinCoreSchema, org.apache.xmpbox.xml.XmpSerializer, org.slf4j.Logger, .LoggerFactory

Writes given BibEntries into the XMP part of a PDF file.

The conversion of a BibEntry to the XMP data (using Dublin Core) is done at DublinCoreExtractor#fillDublinCoreSchema()

Field Summary

Modifier and TypeField and Description
private static final Logger
private final UnprotectTermsFormatter
private static final String
private static final XmpUtilShared
private final XmpPreferences

Constructor Summary

AccessConstructor and Description
public
XmpUtilWriter(XmpPreferences xmpPreferences)

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

If something goes wrong (e.g. an exception is thrown), the method returns an empty string, otherwise it returns the xmp metadata without metadata description as a string in dublin core format.
generateXmpStringWithoutXmpDeclaration
(List<BibEntry>
A list of entries, which are added to the dublin core metadata.
entries
)

This method generates an xmp metadata string in dublin core format without the metadata section <?xpacket begin=...

private String

Returns:

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.
generateXmpStringWithXmpDeclaration
(List<BibEntry>
A list of entries, which are added to the dublin core metadata.
entries
)

This method generates an xmp metadata string in dublin core format.

private BibEntry
public static void
removeXmpMetadata(Path
The file from which metadata has to be removed.
path
)

Removes all XMP metadata associated with the given PDF file.

private void
writeDocumentInformation(PDDocument
The pdf document to write to.
document
,
BibEntry
The BibEntry that is written into the PDF properties.
entry
,
BibDatabase
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.
database
)

Try to write the given BibTexEntry in the Document Information (the properties of the pdf).

private void
writeDublinCore(PDDocument
The pdf document to write to.
document
,
List<BibEntry>
The BibTeX entries that are written as schemas
entries
,
BibDatabase
An optional database which the given BibTeX entries belong to, which will be used to esolve strings. If the database is null the strings will not be resolved.
database
)

Try to write the given BibTexEntries as DublinCore XMP Schemas

Existing DublinCore schemas in the document are removed

private void
writeToDCSchema(DublinCoreSchema
Dublin core schema, which is filled with the bib entry.
dcSchema
,
BibEntry
The entry, which is added to the dublin core metadata.
entry
)

Writes the information of the bib entry to the dublin core schema using a custom extractor.

public void
writeXmp(Path
The path to write to.
file
,
BibEntry
The entry to write.
entry
,
BibDatabase
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.
database
)

Try to write the given BibTexEntry in the XMP-stream of the given PDF-file.

public void
writeXmp(Path
The file to write the entries to.
path
,
List<BibEntry>
The entries to write to the file. *
bibtexEntries
,
BibDatabase
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.
database
)

Try to write the given BibTexEntry in the XMP-stream of the given PDF-file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER
unprotectTermsFormatterback to summary
private final UnprotectTermsFormatter unprotectTermsFormatter
XMP_BEGIN_END_TAGback to summary
private static final String XMP_BEGIN_END_TAG
XMP_UTIL_SHAREDback to summary
private static final XmpUtilShared XMP_UTIL_SHARED
xmpPreferencesback to summary
private final XmpPreferences xmpPreferences

Constructor Detail

XmpUtilWriterback to summary
public XmpUtilWriter(XmpPreferences xmpPreferences)

Method Detail

generateXmpStringWithoutXmpDeclarationback to summary
public String generateXmpStringWithoutXmpDeclaration(List<BibEntry> entries)

This method generates an xmp metadata string in dublin core format without the metadata section <?xpacket begin=...>.

Parameters
entries:List<BibEntry>

A list of entries, which are added to the dublin core metadata.

Returns:String

If something goes wrong (e.g. an exception is thrown), the method returns an empty string, otherwise it returns the xmp metadata without metadata description as a string in dublin core format.

generateXmpStringWithXmpDeclarationback to summary
private String generateXmpStringWithXmpDeclaration(List<BibEntry> entries)

This method generates an xmp metadata string in dublin core format.

Parameters
entries:List<BibEntry>

A list of entries, which are added to the dublin core metadata.

Returns:String

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.

getDefaultOrDatabaseEntryback to summary
private BibEntry getDefaultOrDatabaseEntry(BibEntry defaultEntry, BibDatabase database)
removeXmpMetadataback to summary
public static void removeXmpMetadata(Path path) throws IOException, TransformerException

Removes all XMP metadata associated with the given PDF file.

Parameters
path:Path

The file from which metadata has to be removed.

Exceptions
IOException:
If the file could not be read from or written to.
TransformerException:
If the XMP metadata could not be removed.
writeDocumentInformationback to summary
private void writeDocumentInformation(PDDocument document, BibEntry entry, BibDatabase database)

Try to write the given BibTexEntry in the Document Information (the properties of the pdf).

Existing fields values are overridden if the bibtex entry has the corresponding value set.

The method to write DublinCore is DublinCoreExtractor#fillDublinCoreSchema()

Parameters
document:PDDocument

The pdf document to write to.

entry:BibEntry

The BibEntry that is written into the PDF properties.

database:BibDatabase

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.

writeDublinCoreback to summary
private void writeDublinCore(PDDocument document, List<BibEntry> entries, BibDatabase database) throws IOException, TransformerException

Try to write the given BibTexEntries as DublinCore XMP Schemas

Existing DublinCore schemas in the document are removed

Parameters
document:PDDocument

The pdf document to write to.

entries:List<BibEntry>

The BibTeX entries that are written as schemas

database:BibDatabase

An optional database which the given BibTeX entries belong to, which will be used to esolve strings. If the database is null the strings will not be resolved.

writeToDCSchemaback to summary
private void writeToDCSchema(DublinCoreSchema dcSchema, BibEntry entry)

Writes the information of the bib entry to the dublin core schema using a custom extractor.

Parameters
dcSchema:DublinCoreSchema

Dublin core schema, which is filled with the bib entry.

entry:BibEntry

The entry, which is added to the dublin core metadata.

writeXmpback to summary
public void writeXmp(Path file, BibEntry entry, BibDatabase database) throws IOException, TransformerException

Try to write the given BibTexEntry in the XMP-stream of the given PDF-file.

Throws an IOException if the file cannot be read or written, so the user can remove a lock or cancel the operation.

The method will overwrite existing BibTeX-XMP-data, but keep other existing metadata.

This is a convenience method for writeXMP(File, Collection).

Parameters
file:Path

The path to write to.

entry:BibEntry

The entry to write.

database:BibDatabase

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.

Exceptions
IOException:
If the file could not be written to or could not be found.
TransformerException:
If the entry was malformed or unsupported.
writeXmpback to summary
public void writeXmp(Path path, List<BibEntry> bibtexEntries, BibDatabase database) throws IOException, TransformerException

Try to write the given BibTexEntry in the XMP-stream of the given PDF-file.

Throws an IOException if the file cannot be read or written, so the user can remove a lock or cancel the operation.

The method will overwrite existing BibTeX-XMP-data, but keep other existing metadata.

The code for using PDFBox is also used at org.jabref.logic.exporter.EmbeddedBibFilePdfExporter#embedBibTex(String, Path).

Parameters
path:Path

The file to write the entries to.

bibtexEntries:List<BibEntry>

The entries to write to the file. *

database:BibDatabase

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.

Exceptions
IOException:
If the file could not be written to or could not be found.
TransformerException:
If the entry was malformed or unsupported.