| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.xmp; |
| 22 |
|
| 23 |
import com.adobe.internal.xmp.XMPException; |
| 24 |
import com.adobe.internal.xmp.XMPIterator; |
| 25 |
import com.adobe.internal.xmp.XMPMeta; |
| 26 |
import com.adobe.internal.xmp.impl.XMPMetaImpl; |
| 27 |
import com.adobe.internal.xmp.options.IteratorOptions; |
| 28 |
import com.adobe.internal.xmp.properties.XMPPropertyInfo; |
| 29 |
import com.drew.lang.annotations.NotNull; |
| 30 |
import com.drew.lang.annotations.Nullable; |
| 31 |
import com.drew.metadata.Directory; |
| 32 |
|
| 33 |
import java.util.Collections; |
| 34 |
import java.util.HashMap; |
| 35 |
import java.util.Map; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
@SuppressWarnings("WeakerAccess") |
| 48 |
public class XmpDirectory extends Directory |
| 49 |
{ |
| 50 |
public static final int TAG_XMP_VALUE_COUNT = 0xFFFF; |
| 51 |
|
| 52 |
@NotNull |
| 53 |
private static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>(); |
| 54 |
|
| 55 |
static { |
| 56 |
_tagNameMap.put(TAG_XMP_VALUE_COUNT, "XMP Value Count"); |
| 57 |
} |
| 58 |
|
| 59 |
@Nullable |
| 60 |
private XMPMeta _xmpMeta; |
| 61 |
|
| 62 |
public XmpDirectory() |
| 63 |
{ |
| 64 |
this.setDescriptor(new XmpDescriptor(this)); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
@NotNull |
| 69 |
public String getName() |
| 70 |
{ |
| 71 |
return "XMP"; |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
@NotNull |
| 76 |
protected HashMap<Integer, String> getTagNameMap() |
| 77 |
{ |
| 78 |
return _tagNameMap; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
@NotNull |
| 88 |
public Map<String, String> getXmpProperties() |
| 89 |
{ |
| 90 |
Map<String, String> propertyValueByPath = new HashMap<String, String>(); |
| 91 |
|
| 92 |
if (_xmpMeta != null) |
| 93 |
{ |
| 94 |
try { |
| 95 |
IteratorOptions options = new IteratorOptions().setJustLeafnodes(true); |
| 96 |
for (XMPIterator i = _xmpMeta.iterator(options); i.hasNext(); ) { |
| 97 |
XMPPropertyInfo prop = (XMPPropertyInfo)i.next(); |
| 98 |
String path = prop.getPath(); |
| 99 |
String value = prop.getValue(); |
| 100 |
if (path != null && value != null) { |
| 101 |
propertyValueByPath.put(path, value); |
| 102 |
} |
| 103 |
} |
| 104 |
} catch (XMPException ignored) { |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
return Collections.unmodifiableMap(propertyValueByPath); |
| 109 |
} |
| 110 |
|
| 111 |
public void setXMPMeta(@NotNull XMPMeta xmpMeta) |
| 112 |
{ |
| 113 |
_xmpMeta = xmpMeta; |
| 114 |
|
| 115 |
try { |
| 116 |
int valueCount = 0; |
| 117 |
IteratorOptions options = new IteratorOptions().setJustLeafnodes(true); |
| 118 |
for (XMPIterator i = _xmpMeta.iterator(options); i.hasNext(); ) { |
| 119 |
XMPPropertyInfo prop = (XMPPropertyInfo)i.next(); |
| 120 |
if (prop.getPath() != null) { |
| 121 |
valueCount++; |
| 122 |
} |
| 123 |
} |
| 124 |
setInt(TAG_XMP_VALUE_COUNT, valueCount); |
| 125 |
} catch (XMPException ignored) { |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
@NotNull |
| 134 |
public XMPMeta getXMPMeta() |
| 135 |
{ |
| 136 |
if (_xmpMeta == null) |
| 137 |
_xmpMeta = new XMPMetaImpl(); |
| 138 |
return _xmpMeta; |
| 139 |
} |
| 140 |
} |