[
https://issues.apache.org/jira/browse/TIKA-4773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18093916#comment-18093916
]
ASF GitHub Bot commented on TIKA-4773:
--------------------------------------
dschmidt commented on code in PR #2927:
URL: https://github.com/apache/tika/pull/2927#discussion_r3527094878
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/main/java/org/apache/tika/parser/image/ImageMetadataExtractor.java:
##########
@@ -306,6 +310,51 @@ public void handle(Directory directory, Metadata metadata)
throws MetadataExcept
}
}
+ /**
+ * Copies the XMP properties parsed by Metadata Extractor into the
metadata,
+ * keyed by their {@code prefix:name} path. The other handlers copy a
+ * directory's tags, but XMP keeps its properties in a separate map
+ * ({@link XmpDirectory#getXmpProperties()}), so without this they are
lost.
+ * Keys matching a known Tika field are skipped.
+ */
+ static class XmpHandler implements DirectoryHandler {
+
+ static {
+ // XMPCore's namespace registry is process-global and keeps the
first
+ // prefix it sees for a URI. Pin canonical prefixes so keys stay
stable
+ // (files use both Camera and GCamera for the Google photo
namespace).
+ // https://developer.android.com/media/platform/motion-photo-format
+ try {
+ XMPMetaFactory.getSchemaRegistry()
+
.registerNamespace("http://ns.google.com/photos/1.0/camera/", "Camera");
+ XMPMetaFactory.getSchemaRegistry()
+
.registerNamespace("http://ns.google.com/photos/1.0/container/", "Container");
+ XMPMetaFactory.getSchemaRegistry()
+
.registerNamespace("http://ns.google.com/photos/1.0/container/item/", "Item");
+ } catch (XMPException e) {
+ // non-fatal: only affects prefix stability
+ }
+ }
+
+ public boolean supports(Class<? extends Directory> directoryType) {
+ return XmpDirectory.class.isAssignableFrom(directoryType);
+ }
+
+ public void handle(Directory directory, Metadata metadata) throws
MetadataException {
+ Map<String, String> properties = ((XmpDirectory)
directory).getXmpProperties();
+ if (properties == null) {
+ return;
+ }
+ for (Map.Entry<String, String> property : properties.entrySet()) {
+ String name = property.getKey();
+ String value = property.getValue();
+ if (value != null && !MetadataFields.isMetadataField(name)) {
+ metadata.set(name, value);
+ }
Review Comment:
Good point, fixed. It now also skips a key that already has a value, so it
won't overwrite what other extractors set.
> Expose all parsed XMP properties from images
> --------------------------------------------
>
> Key: TIKA-4773
> URL: https://issues.apache.org/jira/browse/TIKA-4773
> Project: Tika
> Issue Type: Improvement
> Components: parser
> Affects Versions: 3.3.0
> Reporter: Dominik Schmidt
> Priority: Major
>
> The image parser uses Metadata Extractor, which parses the complete XMP
> packet,
> but ImageMetadataExtractor only copies the Dublin Core and XMP-MM schemas into
> the metadata (via JempboxExtractor). Properties from any other XMP namespace
> are
> parsed and then dropped, including vendor namespaces such as the ones Google
> Motion Photos use (Camera / Container / Item).
> As a result XMP that Tika already parsed is not exposed for image files.
> Proposal: copy the XMP properties that Metadata Extractor exposes via
> XmpDirectory.getXmpProperties() into the metadata, keyed by their prefix:name
> path, skipping keys that are already set or that match a known Tika field so
> normalized values are not overwritten.
> Also pre-register canonical prefixes for the Google photo namespaces, because
> XMPCore keeps a process-global URI to prefix registry and adopts whichever
> prefix
> the first parsed file declares; without pinning, the same namespace can
> surface
> as either "Camera" or "GCamera" depending on parse order.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)