Request.java
18.8 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.provider.DebugInfoEnum
* com.scene7.is.provider.ImageSet
* com.scene7.is.provider.ImageSource
* com.scene7.is.provider.RequestTypeEnum
* com.scene7.is.provider.RequestTypeSpec
* com.scene7.is.provider.TextResponseTypeEnum
* com.scene7.is.provider.UserData
* com.scene7.is.provider.ZoomTargets
* com.scene7.is.provider.catalog.Catalog
* com.scene7.is.provider.catalog.CatalogException
* com.scene7.is.provider.catalog.ObjectRecord
* com.scene7.is.provider.ruleset.RuleSetResults
* com.scene7.is.sleng.Color
* com.scene7.is.sleng.IccProfile
* com.scene7.is.sleng.Text
* com.scene7.is.util.AbstractPath
* com.scene7.is.util.Dimension2D
* com.scene7.is.util.Dimension2D$Double
* com.scene7.is.util.Location
* com.scene7.is.util.Size
* com.scene7.is.util.TextEncodingTypeEnum
* com.scene7.is.util.XMLConvertible
* com.scene7.is.util.callbacks.Option
* com.scene7.is.util.text.Formatter
* org.jetbrains.annotations.NotNull
* org.jetbrains.annotations.Nullable
*/
package com.scene7.is.ps.provider;
import com.scene7.is.provider.DebugInfoEnum;
import com.scene7.is.provider.ImageSet;
import com.scene7.is.provider.ImageSource;
import com.scene7.is.provider.RequestTypeEnum;
import com.scene7.is.provider.RequestTypeSpec;
import com.scene7.is.provider.TextResponseTypeEnum;
import com.scene7.is.provider.UserData;
import com.scene7.is.provider.ZoomTargets;
import com.scene7.is.provider.catalog.Catalog;
import com.scene7.is.provider.catalog.CatalogException;
import com.scene7.is.provider.catalog.ObjectRecord;
import com.scene7.is.provider.ruleset.RuleSetResults;
import com.scene7.is.ps.provider.ModifierSet;
import com.scene7.is.ps.provider.RequestHolder;
import com.scene7.is.ps.provider.defs.LayerSpec;
import com.scene7.is.ps.provider.defs.ModifierEnum;
import com.scene7.is.sleng.Color;
import com.scene7.is.sleng.IccProfile;
import com.scene7.is.sleng.Text;
import com.scene7.is.util.AbstractPath;
import com.scene7.is.util.Dimension2D;
import com.scene7.is.util.Location;
import com.scene7.is.util.Size;
import com.scene7.is.util.TextEncodingTypeEnum;
import com.scene7.is.util.XMLConvertible;
import com.scene7.is.util.callbacks.Option;
import com.scene7.is.util.text.Formatter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class Request
implements Cloneable,
RequestHolder,
XMLConvertible {
public static final Integer ID_LAYER_0 = 0;
private final ModifierSet catalogValues = new ModifierSet();
private final ModifierSet globalAttributes = new ModifierSet();
private final ModifierSet layerComp = new ModifierSet();
private final Map<Integer, ModifierSet> layers = new TreeMap<Integer, ModifierSet>();
private final Map<String, String> substPairs = new HashMap<String, String>();
private ModifierSet currentLayer = this.layerComp;
private ModifierSet parentLayer;
private boolean frozen = false;
@NotNull
private Option<RuleSetResults> ruleSetResults = Option.none();
private static final int SRC_ENTRY = 0;
private static final int DST_ENTRY = 1;
private static final int BOTH_ENTRIES = 2;
private static final int DONE = 3;
public Object clone() {
Request request = new Request();
request.catalogValues.setAll(this.catalogValues);
request.globalAttributes.setAll(this.globalAttributes);
request.layerComp.setAll(this.layerComp);
request.substPairs.putAll(this.substPairs);
for (Map.Entry<Integer, ModifierSet> entry : this.layers.entrySet()) {
request.layers.put(entry.getKey(), new ModifierSet(entry.getValue()));
}
return request;
}
@NotNull
public ObjectRecord getRecord() {
return this.globalAttributes.getOrDie(ModifierEnum.I_DESCRIPTOR);
}
@NotNull
public RequestTypeEnum getType() {
RequestTypeSpec requestTypeSpec = this.globalAttributes.getOrDie(ModifierEnum.REQ);
return requestTypeSpec.type;
}
@NotNull
public String getRootId() {
return this.getRecord().getCatalog().getRootId();
}
@NotNull
public ZoomTargets getTargets() {
return this.getRecord().getTargets();
}
@NotNull
public UserData getUserData() {
return this.getRecord().getUserData();
}
@NotNull
public ImageSet getImageSet() {
return this.getRecord().getImageSet();
}
@NotNull
public Option<String> getAssetType() {
return this.getRecord().getAssetType();
}
@NotNull
public DebugInfoEnum getDebugInfo() {
return this.globalAttributes.get(ModifierEnum.DEBUG_INFO, DebugInfoEnum.NONE);
}
@NotNull
public TextEncodingTypeEnum getResponseEncoding() {
RequestTypeSpec requestTypeSpec = this.globalAttributes.getOrDie(ModifierEnum.REQ);
return requestTypeSpec.encoding == null ? TextEncodingTypeEnum.DEFAULT : requestTypeSpec.encoding;
}
@NotNull
public TextResponseTypeEnum getResponseType() {
RequestTypeSpec requestTypeSpec = this.getGlobalAttributes().getOrDie(ModifierEnum.REQ);
assert (requestTypeSpec.type != RequestTypeEnum.IMG);
assert (requestTypeSpec.type != RequestTypeEnum.TMB);
if (requestTypeSpec.format == null) {
return TextResponseTypeEnum.TEXT;
}
return requestTypeSpec.format;
}
@NotNull
public Color getBgc() {
Color result = this.globalAttributes.get(ModifierEnum.BGC, null);
if (result == null) {
result = this.getType() == RequestTypeEnum.TMB ? this.globalAttributes.getOrDie(ModifierEnum.THUMB_BGC) : this.globalAttributes.getOrDie(ModifierEnum.IMG_BGC);
}
return result;
}
@NotNull
public Location getAlign() {
Location result = this.globalAttributes.get(ModifierEnum.ALIGN, null);
if (result == null) {
result = this.getType() == RequestTypeEnum.TMB ? this.globalAttributes.getOrDie(ModifierEnum.THUMB_ALIGN) : this.globalAttributes.getOrDie(ModifierEnum.IMG_ALIGN);
}
return result;
}
@NotNull
public Size getDefaultSize() {
if (this.getType() == RequestTypeEnum.TMB) {
return this.globalAttributes.getOrDie(ModifierEnum.THUMB_DEFAULT_SIZE);
}
return this.globalAttributes.getOrDie(ModifierEnum.IMG_DEFAULT_SIZE);
}
@Nullable
public String getDefaultImage() {
if (this.globalAttributes.contains(ModifierEnum.DEFAULT_IMAGE)) {
return this.globalAttributes.getOrDie(ModifierEnum.DEFAULT_IMAGE);
}
return this.getRecord().getCatalog().getDefaultImage();
}
@NotNull
public Size getMaxPix() {
return this.globalAttributes.getOrDie(ModifierEnum.I_SIZE_LIMIT);
}
public int getJpegSize() {
return this.globalAttributes.getOrDie(ModifierEnum.JPEGSIZE);
}
public boolean shallEmbedPath() {
return this.globalAttributes.getOrDie(ModifierEnum.PATH_EMBED);
}
public boolean getIccEmbed() {
return this.globalAttributes.getOrDie(ModifierEnum.ICC_EMBED);
}
public boolean getXmpEmbed() {
return this.globalAttributes.getOrDie(ModifierEnum.XMP_EMBED);
}
public <T> void setCatalogValue(ModifierEnum<T> modifier, T value) {
assert (!this.frozen);
this.catalogValues.set(modifier, value);
this.setModifier(modifier, value);
}
public <T> T getCatalogValue(ModifierEnum<T> modifier, T defaultValue) {
return this.catalogValues.get(modifier, defaultValue);
}
public <T> T getCatalogValue(ModifierEnum<T> modifier) {
return this.catalogValues.get(modifier, null);
}
@Override
public <T> void setModifier(ModifierEnum<T> modifier, @Nullable T value) {
assert (!this.frozen);
ModifierSet store = this.getStore(modifier, value);
store.set(modifier, value);
}
public boolean hasSubstPairs() {
return this.substPairs.isEmpty();
}
public Map<String, String> getSubstPairs() {
return Collections.unmodifiableMap(this.substPairs);
}
@Override
public void setSubstPair(String name, String value) {
assert (!this.frozen);
this.substPairs.put(name, value);
}
public void resetToLayerComp() {
assert (!this.frozen);
this.currentLayer = this.layerComp;
}
public void setDefaults(Request src) {
assert (!this.frozen);
this.globalAttributes.merge(src.globalAttributes, 0);
this.layerComp.merge(src.layerComp, 0);
Request.mergeLayers(this.layers, src.layers, false);
for (Map.Entry<String, String> entry : src.substPairs.entrySet()) {
if (this.substPairs.get(entry.getKey()) != null) continue;
this.substPairs.put(entry.getKey(), entry.getValue());
}
}
public void overrideWith(Request src) {
assert (!this.frozen);
this.catalogValues.merge(src.catalogValues, Integer.MAX_VALUE);
this.globalAttributes.merge(src.globalAttributes, Integer.MAX_VALUE);
this.layerComp.merge(src.layerComp, Integer.MAX_VALUE);
Request.mergeLayers(this.layers, src.layers, true);
this.substPairs.putAll(src.substPairs);
}
public void freeze() {
assert (!this.frozen);
this.frozen = true;
this.globalAttributes.freeze();
this.layerComp.freeze();
for (ModifierSet layer : this.getLayers()) {
layer.freeze();
}
}
public ModifierSet getGlobalAttributes() {
return this.globalAttributes;
}
public ModifierSet getLayerComp() {
return this.layerComp;
}
public ModifierSet getLayer0() {
return this.findCreateLayer(LayerSpec.LAYER_0);
}
public int getLayerCount() {
return this.layers.size();
}
public Collection<ModifierSet> getLayers() {
Collection<ModifierSet> layers = this.layers.values();
return Collections.unmodifiableCollection(layers);
}
public void setRuleSetResults(@NotNull RuleSetResults ruleSetResults) {
this.ruleSetResults = Option.some((Object)ruleSetResults);
}
@NotNull
public Option<RuleSetResults> getRuleSetResults() {
return this.ruleSetResults;
}
public boolean isEmptyImageRequest() {
if (this.getLayerCount() == 1) {
ModifierSet modifiers = this.getLayer0();
return !modifiers.contains(ModifierEnum.I_IMAGE_PATH) && !modifiers.contains(ModifierEnum.TEXT) && !modifiers.contains(ModifierEnum.SIZE) && !modifiers.contains(ModifierEnum.SIZEN);
}
return this.getLayerCount() == 0;
}
public String toString() {
StringWriter buf = new StringWriter();
PrintWriter out = new PrintWriter(buf);
out.println("<Request>");
out.println(Formatter.indent((String)"<CatalogValues>", (int)4));
out.println(Formatter.indent((String)this.catalogValues.toString(), (int)8));
out.println(Formatter.indent((String)"</CatalogValues>", (int)4));
out.println(Formatter.indent((String)"<GlobalAttributes>", (int)4));
out.println(Formatter.indent((String)this.globalAttributes.toString(), (int)8));
out.println(Formatter.indent((String)"</GlobalAttributes>", (int)4));
for (Map.Entry<Integer, ModifierSet> entry2 : this.layers.entrySet()) {
out.println(Formatter.indent((String)("<Layer id=\"" + entry2.getKey() + "\">"), (int)4));
out.println(Formatter.indent((String)entry2.getValue().toString(), (int)8));
out.println(Formatter.indent((String)"</Layer>", (int)4));
}
out.println(Formatter.indent((String)"<Layer id=\"comp\">", (int)4));
out.println(Formatter.indent((String)this.layerComp.toString(), (int)8));
out.println(Formatter.indent((String)"</Layer>", (int)4));
for (Map.Entry entry : this.substPairs.entrySet()) {
out.println(Formatter.indent((String)("<SubsPair name=\"" + (String)entry.getKey() + "\" value=\"" + (String)entry.getValue() + "\"/>"), (int)4));
}
out.println("</Request>");
out.close();
return buf.toString();
}
public Element toXMLElement(Document document) {
Element root = document.createElement("request");
Element child = this.catalogValues.toXMLElement(document);
child.setAttribute("name", "catalogValues");
root.appendChild(child);
child = this.globalAttributes.toXMLElement(document);
child.setAttribute("name", "globalAttributes");
root.appendChild(child);
Element layerList = document.createElement("layer-list");
for (Map.Entry<Integer, ModifierSet> entry : this.layers.entrySet()) {
String id = String.valueOf(entry.getKey());
ModifierSet modifiers = entry.getValue();
Element layer = modifiers.toXMLElement(document);
layer.setAttribute("name", "layer");
layer.setAttribute("id", id);
layerList.appendChild(layer);
}
root.appendChild(layerList);
child = this.layerComp.toXMLElement(document);
child.setAttribute("name", "layer");
child.setAttribute("id", "comp");
root.appendChild(child);
Element substList = document.createElement("subst-list");
for (Map.Entry<String, String> entry2 : this.substPairs.entrySet()) {
String name = entry2.getKey();
String value = entry2.getValue();
Element substPair = document.createElement("subst-pair");
substPair.setAttribute("name", name);
substPair.setAttribute("value", value);
substList.appendChild(substPair);
}
root.appendChild(substList);
return root;
}
private ModifierSet getStore(ModifierEnum modifier, Object value) {
switch (modifier.flavor) {
case 0: {
this.currentLayer = this.findCreateLayer((LayerSpec)value);
this.parentLayer = null;
return this.currentLayer;
}
case 1: {
if (this.parentLayer == null) {
this.parentLayer = this.currentLayer;
}
this.currentLayer = this.findCreateEffect(this.parentLayer, value);
return this.currentLayer;
}
case 2: {
return this.globalAttributes;
}
case 3: {
if (this.currentLayer != this.layerComp) {
return this.currentLayer;
}
return this.findCreateLayer(LayerSpec.LAYER_0);
}
case 4: {
return this.currentLayer;
}
case 5: {
if (this.currentLayer != this.layerComp) {
return this.currentLayer;
}
return this.globalAttributes;
}
}
throw new AssertionError();
}
ModifierSet findCreateLayer(LayerSpec layerId) {
if (layerId.getLayerId().toString().equalsIgnoreCase("COMP")) {
return this.layerComp;
}
Integer layerIdInt = (Integer)layerId.getLayerId();
ModifierSet layer = this.layers.get(layerIdInt);
if (layer == null) {
layer = new ModifierSet();
layer.set(ModifierEnum.I_LAYER_ID, layerIdInt);
this.layers.put(layerIdInt, layer);
}
return layer;
}
private ModifierSet findCreateEffect(ModifierSet layer, Object effectId) {
ModifierSet effect;
TreeMap<Object, ModifierSet> effects = layer.get(ModifierEnum.EFFECT, null);
if (effects == null) {
effects = new TreeMap<Object, ModifierSet>();
layer.set(ModifierEnum.EFFECT, effects);
}
if ((effect = (ModifierSet)effects.get(effectId)) == null) {
effect = new ModifierSet();
effects.put(effectId, effect);
}
return effect;
}
private static void mergeLayers(Map<Integer, ModifierSet> dst, Map<Integer, ModifierSet> src, boolean override) {
int level = override ? Integer.MAX_VALUE : 0;
TreeMap<Integer, ModifierSet> newLayers = new TreeMap<Integer, ModifierSet>();
Iterator<Map.Entry<Integer, ModifierSet>> iSrc = src.entrySet().iterator();
Iterator<Map.Entry<Integer, ModifierSet>> iDst = dst.entrySet().iterator();
Map.Entry<Integer, ModifierSet> srcEntry = Request.nextEntry(iSrc);
Map.Entry<Integer, ModifierSet> dstEntry = Request.nextEntry(iDst);
block6 : do {
switch (Request.whoIsNext(dstEntry, srcEntry)) {
case 0: {
assert (srcEntry != null);
newLayers.put(srcEntry.getKey(), new ModifierSet(srcEntry.getValue()));
srcEntry = Request.nextEntry(iSrc);
continue block6;
}
case 1: {
dstEntry = Request.nextEntry(iDst);
continue block6;
}
case 2: {
assert (dstEntry != null);
assert (srcEntry != null);
ModifierSet dstStore = dstEntry.getValue();
ModifierSet srcStore = srcEntry.getValue();
dstStore.merge(srcStore, level);
dstEntry = Request.nextEntry(iDst);
srcEntry = Request.nextEntry(iSrc);
continue block6;
}
case 3: {
dst.putAll(newLayers);
return;
}
}
break;
} while (true);
throw new AssertionError();
}
private static int whoIsNext(Map.Entry<Integer, ModifierSet> dstEntry, Map.Entry<Integer, ModifierSet> srcEntry) {
if (srcEntry == null) {
return dstEntry == null ? 3 : 1;
}
if (dstEntry == null) {
return 0;
}
int cmp = srcEntry.getKey().compareTo(dstEntry.getKey());
if (cmp == 0) {
return 2;
}
return cmp > 0 ? 1 : 0;
}
@Nullable
private static Map.Entry<Integer, ModifierSet> nextEntry(Iterator<Map.Entry<Integer, ModifierSet>> i) {
return i.hasNext() ? i.next() : null;
}
@NotNull
public IccProfile getProfile(@NotNull String profileName) throws CatalogException {
return this.getRecord().getProfile(profileName);
}
@NotNull
public AbstractPath getRootPath() throws CatalogException {
return this.getRecord().getCatalog().getPath();
}
}