/** * Determine if there is an extended XMP section based on the standard XMP part. * The xmpNote:HasExtendedXMP attribute contains the GUID of the Extended XMP chunks. */ @Nullable private static String getExtendedXMPGUID(@NotNull Metadata metadata) { final Collection<XmpDirectory> xmpDirectories = metadata.getDirectoriesOfType(XmpDirectory.class); for (XmpDirectory directory : xmpDirectories) { final XMPMeta xmpMeta = directory.getXMPMeta(); try { final XMPIterator itr = xmpMeta.iterator(SCHEMA_XMP_NOTES, null, null); if (itr == null) continue; while (itr.hasNext()) { final XMPPropertyInfo pi = (XMPPropertyInfo) itr.next(); if (ATTRIBUTE_EXTENDED_XMP.equals(pi.getPath())) { return pi.getValue(); } } } catch (XMPException e) { // Fail silently here: we had a reading issue, not a decoding issue. } } return null; }
List<Directory> dirs = metadata.getDirectoriesOfType(JpegDirectory.class).stream().collect(Collectors.toList()); images.add(new Image(E.getFileName().toString(), FilenameUtils.getExtension(E.toFile().toString()), dirs)); } else { List<Directory> dirs = metadata.getDirectoriesOfType(PngDirectory.class).stream().collect(Collectors.toList()); images.add(new Image(E.getFileName().toString(), FilenameUtils.getExtension(E.toFile().toString()), dirs));
// Extract metadata from the image Metadata metadata = ImageMetadataReader.readMetadata(image); // Iterate through any XMP directories we may have received for (XmpDirectory xmpDirectory : metadata.getDirectoriesOfType(XmpDirectory.class)) { // Usually with metadata-extractor, you iterate a directory's tags. However XMP has // a complex structure with many potentially unknown properties. This doesn't map // well to metadata-extractor's directory-and-tag model. // // If you need to use XMP data, access the XMPMeta object directly. XMPMeta xmpMeta = xmpDirectory.getXMPMeta(); // Iterate XMP properties XMPIterator itr = xmpMeta.iterator(); while (itr.hasNext()) { XMPPropertyInfo property = (XMPPropertyInfo) itr.next(); // Print details of the property System.out.println(property.getPath() + ": " + property.getValue()); } }
/** * Determine if there is an extended XMP section based on the standard XMP part. * The xmpNote:HasExtendedXMP attribute contains the GUID of the Extended XMP chunks. */ @Nullable private static String getExtendedXMPGUID(@NotNull Metadata metadata) { final Collection<XmpDirectory> xmpDirectories = metadata.getDirectoriesOfType(XmpDirectory.class); for (XmpDirectory directory : xmpDirectories) { final XMPMeta xmpMeta = directory.getXMPMeta(); try { final XMPIterator itr = xmpMeta.iterator(SCHEMA_XMP_NOTES, null, null); if (itr == null) continue; while (itr.hasNext()) { final XMPPropertyInfo pi = (XMPPropertyInfo) itr.next(); if (ATTRIBUTE_EXTENDED_XMP.equals(pi.getPath())) { return pi.getValue(); } } } catch (XMPException e) { // Fail silently here: we had a reading issue, not a decoding issue. } } return null; }