XMPUtils.java
4.87 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.xmp;
import com.adobe.internal.xmp.XMPDateTime;
import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMeta;
import com.adobe.internal.xmp.impl.Base64;
import com.adobe.internal.xmp.impl.ISO8601Converter;
import com.adobe.internal.xmp.impl.XMPUtilsImpl;
import com.adobe.internal.xmp.options.PropertyOptions;
public class XMPUtils {
private XMPUtils() {
}
public static String catenateArrayItems(XMPMeta xmp, String schemaNS, String arrayName, String separator, String quotes, boolean allowCommas) throws XMPException {
return XMPUtilsImpl.catenateArrayItems(xmp, schemaNS, arrayName, separator, quotes, allowCommas);
}
public static void separateArrayItems(XMPMeta xmp, String schemaNS, String arrayName, String catedStr, PropertyOptions arrayOptions, boolean preserveCommas) throws XMPException {
XMPUtilsImpl.separateArrayItems(xmp, schemaNS, arrayName, catedStr, arrayOptions, preserveCommas);
}
public static void removeProperties(XMPMeta xmp, String schemaNS, String propName, boolean doAllProperties, boolean includeAliases) throws XMPException {
XMPUtilsImpl.removeProperties(xmp, schemaNS, propName, doAllProperties, includeAliases);
}
public static void appendProperties(XMPMeta source, XMPMeta dest, boolean doAllProperties, boolean replaceOldValues) throws XMPException {
XMPUtils.appendProperties(source, dest, doAllProperties, replaceOldValues, false);
}
public static void appendProperties(XMPMeta source, XMPMeta dest, boolean doAllProperties, boolean replaceOldValues, boolean deleteEmptyValues) throws XMPException {
XMPUtilsImpl.appendProperties(source, dest, doAllProperties, replaceOldValues, deleteEmptyValues);
}
public static boolean convertToBoolean(String value) throws XMPException {
if (value == null || value.length() == 0) {
throw new XMPException("Empty convert-string", 5);
}
value = value.toLowerCase();
try {
return Integer.parseInt(value) != 0;
}
catch (NumberFormatException e) {
return "true".equals(value) || "t".equals(value) || "on".equals(value) || "yes".equals(value);
}
}
public static String convertFromBoolean(boolean value) {
return value ? "True" : "False";
}
public static int convertToInteger(String rawValue) throws XMPException {
try {
if (rawValue == null || rawValue.length() == 0) {
throw new XMPException("Empty convert-string", 5);
}
if (rawValue.startsWith("0x")) {
return Integer.parseInt(rawValue.substring(2), 16);
}
return Integer.parseInt(rawValue);
}
catch (NumberFormatException e) {
throw new XMPException("Invalid integer string", 5);
}
}
public static String convertFromInteger(int value) {
return String.valueOf(value);
}
public static long convertToLong(String rawValue) throws XMPException {
try {
if (rawValue == null || rawValue.length() == 0) {
throw new XMPException("Empty convert-string", 5);
}
if (rawValue.startsWith("0x")) {
return Long.parseLong(rawValue.substring(2), 16);
}
return Long.parseLong(rawValue);
}
catch (NumberFormatException e) {
throw new XMPException("Invalid long string", 5);
}
}
public static String convertFromLong(long value) {
return String.valueOf(value);
}
public static double convertToDouble(String rawValue) throws XMPException {
try {
if (rawValue == null || rawValue.length() == 0) {
throw new XMPException("Empty convert-string", 5);
}
return Double.parseDouble(rawValue);
}
catch (NumberFormatException e) {
throw new XMPException("Invalid double string", 5);
}
}
public static String convertFromDouble(double value) {
return String.valueOf(value);
}
public static XMPDateTime convertToDate(String rawValue) throws XMPException {
if (rawValue == null || rawValue.length() == 0) {
throw new XMPException("Empty convert-string", 5);
}
return ISO8601Converter.parse(rawValue);
}
public static String convertFromDate(XMPDateTime value) {
return ISO8601Converter.render(value);
}
public static String encodeBase64(byte[] buffer) {
return new String(Base64.encode(buffer));
}
public static byte[] decodeBase64(String base64String) throws XMPException {
try {
return Base64.decode(base64String.getBytes());
}
catch (Throwable e) {
throw new XMPException("Invalid base64 string", 5, e);
}
}
}