JOValidator.java
12.1 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.pdfg.exception.ErrorCode
* com.adobe.pdfg.exception.JobOptionsValidateException
* com.adobe.pdfg.logging.PDFGLogger
*/
package com.adobe.pdfg.joboptions.parser;
import com.adobe.pdfg.exception.ErrorCode;
import com.adobe.pdfg.exception.JobOptionsValidateException;
import com.adobe.pdfg.joboptions.parser.ParamSpecs;
import com.adobe.pdfg.logging.PDFGLogger;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
public class JOValidator {
private static PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(JOValidator.class);
private String currentKey = null;
public void validate(Map paramMap) throws JobOptionsValidateException {
if (paramMap == null) {
return;
}
for (String this.currentKey : paramMap.keySet()) {
Object value = paramMap.get(this.currentKey);
if (value instanceof Map) {
this.validate((Map)value);
continue;
}
if (value instanceof List) {
this.validate(this.currentKey, value, true);
continue;
}
paramMap.put(this.currentKey, this.validate(this.currentKey, value, false));
}
}
private Object validate(String key, Object value, boolean array) throws JobOptionsValidateException {
try {
Object retVal = null;
ParamValidator pv = this.getValidatorClassInstance(key, value);
if (pv != null) {
if (array) {
Object firstVal;
ListIterator<Object> liter = ((List)value).listIterator();
if ((key.equals("AlwaysEmbed") || key.equals("NeverEmbed")) && liter.hasNext() && !((firstVal = liter.next()) instanceof Boolean)) {
pv.setValue(firstVal);
liter.set(pv.validate());
}
while (liter.hasNext()) {
pv.setValue(liter.next());
liter.set(pv.validate());
}
} else {
retVal = pv.validate();
}
}
return retVal;
}
catch (Exception e) {
pdfgLogger.debug(e.getMessage(), null, (Throwable)e);
throw new JobOptionsValidateException(key, value.toString());
}
}
private ParamValidator getValidatorClassInstance(String key, Object value) {
if (ParamSpecs.isBoolParam(key)) {
return new BooleanValidator(value);
}
if (ParamSpecs.isStringParam(key) || ParamSpecs.isNameParam(key)) {
return new StringValidator(value);
}
Object pspec = null;
pspec = ParamSpecs.getIntParamSpec(key);
if (pspec != null) {
return new IntegerValidator(value, (ParamSpecs.IntParamSpec)pspec);
}
pspec = ParamSpecs.getIntSetParamSpec(key);
if (pspec != null) {
return new IntSetValidator(value, (ParamSpecs.IntSetParamSpec)pspec);
}
pspec = ParamSpecs.getStringSetParamSpec(key);
if (pspec != null) {
return new StringSetValidator(value, (ParamSpecs.StringSetParamSpec)pspec);
}
pspec = ParamSpecs.getNumParamSpec(key);
if (pspec != null) {
return new NumberValidator(value, (ParamSpecs.NumParamSpec)pspec);
}
for (int i = 0; i < ParamSpecs.NUMSETPARAMS.length; ++i) {
if (!key.equals(ParamSpecs.NUMSETPARAMS[i].getKeyName())) continue;
return new NumberSetValidator(value, ParamSpecs.NUMSETPARAMS[i]);
}
return null;
}
private class BooleanValidator
extends ParamValidator {
public BooleanValidator(Object val) {
super();
this.value = val;
}
public Object validate() throws JobOptionsValidateException {
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof Boolean)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)"", this.value.getClass(), (Object)"Boolean");
}
return this.value;
}
}
private class IntegerValidator
extends ParamValidator {
ParamSpecs.IntParamSpec intSpec;
public IntegerValidator(Object val, ParamSpecs.IntParamSpec ispc) {
super();
this.intSpec = null;
this.value = val;
this.intSpec = ispc;
}
public Object validate() throws JobOptionsValidateException {
int intValue;
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof Double) && !(this.value instanceof Integer)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)JOValidator.this.currentKey, this.value.getClass(), (Object)"Double or Integer");
}
if (this.value instanceof Double) {
Double bdval = (Double)this.value;
if (bdval.compareTo(new Double(bdval.intValue())) != 0) {
throw new JobOptionsValidateException(ErrorCode.IntegerValueRequiredInJobOption, (Object)JOValidator.this.currentKey);
}
double d = (Double)this.value;
intValue = d >= 0.0 ? (int)(d + 0.49) : (int)(d - 0.49);
} else {
intValue = (Integer)this.value;
}
if (intValue < this.intSpec.getMinLimit()) {
return new Integer(this.intSpec.getMinLimit());
}
if (intValue > this.intSpec.getMaxLimit()) {
return new Integer(this.intSpec.getMaxLimit());
}
return this.value;
}
}
private class IntSetValidator
extends ParamValidator {
ParamSpecs.IntSetParamSpec isSpec;
public IntSetValidator(Object val, ParamSpecs.IntSetParamSpec is) {
super();
this.isSpec = null;
this.value = val;
this.isSpec = is;
}
public Object validate() throws JobOptionsValidateException {
double d;
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof Double) && !(this.value instanceof Integer)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)JOValidator.this.currentKey, this.value.getClass(), (Object)"Double or Integer");
}
int intValue = this.value instanceof Double ? ((d = ((Double)this.value).doubleValue()) >= 0.0 ? (int)(d + 0.49) : (int)(d - 0.49)) : (Integer)this.value;
int[] vset = this.isSpec.getValueSet();
for (int i = 0; i < vset.length; ++i) {
if (intValue != vset[i]) continue;
return this.value;
}
throw new JobOptionsValidateException(ErrorCode.InvalidValueInJobOption2, (Object)JOValidator.this.currentKey);
}
}
private class NumberSetValidator
extends ParamValidator {
ParamSpecs.StringSetParamSpec strsetSpec;
public NumberSetValidator(Object val, ParamSpecs.StringSetParamSpec sspc) {
super();
this.strsetSpec = null;
this.value = val;
this.strsetSpec = sspc;
}
public Object validate() throws JobOptionsValidateException {
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof Double)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)JOValidator.this.currentKey, this.value.getClass(), (Object)"Double");
}
Double bdval = (Double)this.value;
String[] vset = this.strsetSpec.getValueSet();
for (int i = 0; i < vset.length; ++i) {
if (bdval.compareTo(new Double(vset[i])) != 0) continue;
return this.value;
}
throw new JobOptionsValidateException(ErrorCode.InvalidValueInJobOption, (Object)JOValidator.this.currentKey, (Object)bdval);
}
}
private class StringSetValidator
extends ParamValidator {
ParamSpecs.StringSetParamSpec strsetSpec;
public StringSetValidator(Object val, ParamSpecs.StringSetParamSpec sspc) {
super();
this.strsetSpec = null;
this.value = val;
this.strsetSpec = sspc;
}
public Object validate() throws JobOptionsValidateException {
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof String)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)JOValidator.this.currentKey, this.value.getClass(), (Object)"Double");
}
String strval = (String)this.value;
String[] vset = this.strsetSpec.getValueSet();
for (int i = 0; i < vset.length; ++i) {
if (!strval.equals(vset[i])) continue;
return this.value;
}
throw new JobOptionsValidateException(ErrorCode.InvalidValueInJobOption, (Object)JOValidator.this.currentKey, (Object)strval);
}
}
private class NumberValidator
extends ParamValidator {
ParamSpecs.NumParamSpec numSpec;
public NumberValidator(Object val, ParamSpecs.NumParamSpec nSpec) {
super();
this.numSpec = null;
this.value = val;
this.numSpec = nSpec;
}
public Object validate() throws JobOptionsValidateException {
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof Double)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)JOValidator.this.currentKey, this.value.getClass(), (Object)"Double");
}
Double bdval = (Double)this.value;
if (bdval.compareTo(new Double(this.numSpec.getMinLimit())) < 0) {
return new Double(this.numSpec.getMinLimit());
}
if (bdval.compareTo(new Double(this.numSpec.getMaxLimit())) > 0) {
return new Double(this.numSpec.getMaxLimit());
}
return this.value;
}
}
private class StringValidator
extends ParamValidator {
public StringValidator(Object val) {
super();
this.value = val;
}
public Object validate() throws JobOptionsValidateException {
if (this.value == null) {
throw new JobOptionsValidateException(ErrorCode.NullJobOptionValidatorKey, (Object)JOValidator.this.currentKey);
}
if (!(this.value instanceof String)) {
throw new JobOptionsValidateException(ErrorCode.InvalidKeyClassInJobOption, (Object)JOValidator.this.currentKey, this.value.getClass(), (Object)"String");
}
return this.value;
}
}
private abstract class ParamValidator {
Object value;
private ParamValidator() {
this.value = null;
}
public abstract Object validate() throws JobOptionsValidateException;
public Object getValue() {
return this.value;
}
public void setValue(Object value) {
this.value = value;
}
}
}