XMPMetaFactory.java
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.xmp;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMeta;
import com.adobe.internal.xmp.XMPSchemaRegistry;
import com.adobe.internal.xmp.XMPVersionInfo;
import com.adobe.internal.xmp.impl.XMPMetaImpl;
import com.adobe.internal.xmp.impl.XMPMetaParser;
import com.adobe.internal.xmp.impl.XMPSchemaRegistryImpl;
import com.adobe.internal.xmp.impl.XMPSerializerHelper;
import com.adobe.internal.xmp.options.ParseOptions;
import com.adobe.internal.xmp.options.SerializeOptions;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class XMPMetaFactory {
private static XMPSchemaRegistry schema = new XMPSchemaRegistryImpl();
private static XMPVersionInfo versionInfo = null;
private XMPMetaFactory() {
}
public static XMPSchemaRegistry getSchemaRegistry() {
return schema;
}
public static XMPMeta create() {
return new XMPMetaImpl();
}
public static XMPMeta parse(InputStream in) throws XMPException {
return XMPMetaFactory.parse(in, null);
}
public static XMPMeta parse(InputStream in, ParseOptions options) throws XMPException {
return XMPMetaParser.parse(in, options);
}
public static XMPMeta parseFromString(String packet) throws XMPException {
return XMPMetaFactory.parseFromString(packet, null);
}
public static XMPMeta parseFromString(String packet, ParseOptions options) throws XMPException {
return XMPMetaParser.parse(packet, options);
}
public static XMPMeta parseFromBuffer(byte[] buffer) throws XMPException {
return XMPMetaFactory.parseFromBuffer(buffer, null);
}
public static XMPMeta parseFromBuffer(byte[] buffer, ParseOptions options) throws XMPException {
return XMPMetaParser.parse(buffer, options);
}
public static void serialize(XMPMeta xmp, OutputStream out) throws XMPException {
XMPMetaFactory.serialize(xmp, out, null);
}
public static void serialize(XMPMeta xmp, OutputStream out, SerializeOptions options) throws XMPException {
XMPMetaFactory.assertImplementation(xmp);
XMPSerializerHelper.serialize((XMPMetaImpl)xmp, out, options);
}
public static byte[] serializeToBuffer(XMPMeta xmp, SerializeOptions options) throws XMPException {
XMPMetaFactory.assertImplementation(xmp);
return XMPSerializerHelper.serializeToBuffer((XMPMetaImpl)xmp, options);
}
public static String serializeToString(XMPMeta xmp, SerializeOptions options) throws XMPException {
XMPMetaFactory.assertImplementation(xmp);
return XMPSerializerHelper.serializeToString((XMPMetaImpl)xmp, options);
}
private static void assertImplementation(XMPMeta xmp) {
if (!(xmp instanceof XMPMetaImpl)) {
throw new UnsupportedOperationException("The serializing service works onlywith the XMPMeta implementation of this library");
}
}
public static void reset() {
schema = new XMPSchemaRegistryImpl();
}
public static synchronized XMPVersionInfo getVersionInfo() {
if (versionInfo == null) {
String bundleVersion;
int minor;
int major;
int micro;
bundleVersion = "Test.SNAPSHOT";
major = 5;
minor = 0;
micro = 0;
try {
Enumeration<URL> resources = XMPMetaFactory.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
Attributes attrs = manifest.getMainAttributes();
if (!"com.adobe.xmp.xmpcore".equals(attrs.getValue("Bundle-SymbolicName")) || attrs.getValue("Bundle-Version") == null) continue;
bundleVersion = attrs.getValue("Bundle-Version");
Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+).*");
Matcher matcher = pattern.matcher(bundleVersion);
if (!matcher.find()) continue;
major = Integer.parseInt(matcher.group(1));
minor = Integer.parseInt(matcher.group(2));
micro = Integer.parseInt(matcher.group(3));
break;
}
}
catch (IOException E) {
// empty catch block
}
final String message = "Adobe XMP Core " + bundleVersion;
final int majorVersion = major;
final int minorVersion = minor;
final int microVersion = micro;
versionInfo = new XMPVersionInfo(){
public int getMajor() {
return majorVersion;
}
public int getMinor() {
return minorVersion;
}
public int getMicro() {
return microVersion;
}
public boolean isDebug() {
return true;
}
public int getBuild() {
return 0;
}
public String getMessage() {
return message;
}
public String toString() {
return message;
}
};
}
return versionInfo;
}
}