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

Fix xmp import #8311

Merged
merged 3 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where selecting a citation style in the preferences would sometimes produce an exception [#7860](https://github.com/JabRef/jabref/issues/7860)
- We fixed an issue where an exception would occur when clicking on a DOI link in the preview pane [#7706](https://github.com/JabRef/jabref/issues/7706)
- We fixed an issue where XMP and embedded BibTeX export would not work [#8278](https://github.com/JabRef/jabref/issues/8278)
- We fixed an issue where the XMP and embedded BibTeX import of a file containing multiple schemas failed [#8278](https://github.com/JabRef/jabref/issues/8278)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ private List<BibEntry> getEmbeddedBibFileEntries(PDDocument document) throws IOE
allParsedEntries.addAll(extractAndParseFiles(names));
} else {
List<PDNameTreeNode<PDComplexFileSpecification>> kids = efTree.getKids();
for (PDNameTreeNode<PDComplexFileSpecification> node : kids) {
names = node.getNames();
allParsedEntries.addAll(extractAndParseFiles(names));
if (kids != null) {
for (PDNameTreeNode<PDComplexFileSpecification> node : kids) {
names = node.getNames();
allParsedEntries.addAll(extractAndParseFiles(names));
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/jabref/logic/xmp/XmpUtilReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
import org.apache.pdfbox.pdmodel.common.PDMetadata;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.schema.DublinCoreSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class XmpUtilReader {

private static final Logger LOGGER = LoggerFactory.getLogger(XmpUtilReader.class);

private static final String START_TAG = "<rdf:Description";
private static final String END_TAG = "</rdf:Description>";

Expand Down Expand Up @@ -120,7 +124,7 @@ private static List<XMPMetadata> getXmpMetadata(PDDocument document) throws IOEx
int startDescriptionSection = xmp.indexOf(START_TAG);
int endDescriptionSection = xmp.lastIndexOf(END_TAG) + END_TAG.length();

if (startDescriptionSection < 0 || startDescriptionSection > endDescriptionSection || endDescriptionSection == END_TAG.length() - 1) {
if ((startDescriptionSection < 0) || (startDescriptionSection > endDescriptionSection) || (endDescriptionSection == (END_TAG.length() - 1))) {
return metaList;
}

Expand All @@ -134,7 +138,11 @@ private static List<XMPMetadata> getXmpMetadata(PDDocument document) throws IOEx
for (String s : descriptionsArray) {
// END_TAG is appended, because of the split operation above
String xmpMetaString = start + s + END_TAG + end;
metaList.add(XmpUtilShared.parseXmpMetadata(new ByteArrayInputStream(xmpMetaString.getBytes())));
try {
metaList.add(XmpUtilShared.parseXmpMetadata(new ByteArrayInputStream(xmpMetaString.getBytes())));
} catch (IOException ex) {
LOGGER.error("Problem parsing XMP schema. Continuing with other schemas.", ex);
}
}
return metaList;
}
Expand Down