MediaSetNodeWriter.java
13.9 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.catalog.util.localization.LocaleMap
* com.scene7.is.catalog.util.localization.LocalizedText
* com.scene7.is.provider.ImageSetColorLabel
* com.scene7.is.provider.UserData
* com.scene7.is.provider.ZoomTargets
* com.scene7.is.sleng.Color
* com.scene7.is.sleng.HotSpot
* com.scene7.is.util.Factory
* com.scene7.is.util.SizeInt
* com.scene7.is.util.callbacks.Option
* com.scene7.is.util.text.coders.NetPathCoder
* org.jetbrains.annotations.NotNull
* org.jetbrains.annotations.Nullable
*/
package com.scene7.is.ps.provider.fvctx;
import com.scene7.is.catalog.util.localization.LocaleMap;
import com.scene7.is.catalog.util.localization.LocalizedText;
import com.scene7.is.provider.ImageSetColorLabel;
import com.scene7.is.provider.UserData;
import com.scene7.is.provider.ZoomTargets;
import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.fvctx.FvctxImageProps;
import com.scene7.is.ps.provider.fvctx.FvctxNode;
import com.scene7.is.ps.provider.fvctx.MediaSetItemType;
import com.scene7.is.ps.provider.fvctx.MediaSetMetaData;
import com.scene7.is.ps.provider.fvctx.MediaSetSetType;
import com.scene7.is.ps.provider.fvctx.MediaSetVideoExtension;
import com.scene7.is.ps.provider.fvctx.MediaSetVideoProps;
import com.scene7.is.sleng.Color;
import com.scene7.is.sleng.HotSpot;
import com.scene7.is.util.Factory;
import com.scene7.is.util.SizeInt;
import com.scene7.is.util.callbacks.Option;
import com.scene7.is.util.text.coders.NetPathCoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class MediaSetNodeWriter<T>
implements FvctxNode,
Factory<T> {
protected static final String E_FRAME = "item";
protected static final String E_FRAMESET = "set";
protected static final String E_MEDIA_SET = "set";
protected static final String E_IMAGE = "i";
protected static final String E_SWATCH = "s";
protected static final String E_VIDEO = "v";
protected static final String E_STATIC_CONTENT = "c";
protected static final String E_ITEM = "item";
protected static final String E_TARGETS = "targets";
protected static final String E_HOT_SPOTS = "map";
protected static final String E_USER_DATA = "userdata";
protected static final String ATTR_WIDTH = "dx";
protected static final String ATTR_HEIGHT = "dy";
protected static final String ATTR_IMAGEVERSION = "iv";
protected static final String ATTR_LABEL = "l";
protected static final String ATTR_NAME = "n";
protected static final String ATTR_PROTOCOLVERSION = "pv";
protected static final String ATTR_SUFFIX = "suffix";
protected static final String ATTR_MEDIA_SET_SET_TYPE = "type";
protected static final String ATTR_MEDIA_SET_ITEM_TYPE = "type";
protected static final String ATTR_IS_DEFAULT_IMAGE = "isDefault";
protected static final String ATTR_LOCALE = "locale";
protected static final String ATTR_MODIFIER = "mod";
protected static final String ATTR_POST_MODIFIER = "pmod";
protected static final String ATTR_SUPPRESSED_MAP = "map";
protected static final String ATTR_SUPPRESSED_USERDATA = "userdata";
protected static final String ATTR_ECAT_NUM_PAGES = "np";
protected static final String ATTR_VIDEO_ID = "id";
protected static final String ATTR_VIDEO_PATH = "path";
protected static final String ATTR_VIDEO_BITRATE = "bitrate";
protected static final String ATTR_VIDEO_FORMAT = "format";
protected static final String ATTR_NAME_ECAT_COMPOSITE_TEMPLATE = "template";
protected static final String ATTR_VALUE_ECAT_COMPOSITE_TEMPLATE = "$image0$?layer=0&extendN=0,0,1,0&originN=0,-0.5&layer=1&src=$image1$&originN=-0.5,-0.5&sizeN=0.5,1";
protected static final double ECAT_PAGE_RATIO = 0.8;
protected final int fvctxVersion;
@NotNull
protected final LocaleMap localeMap;
@NotNull
protected final String locale;
@NotNull
protected final String labelKey;
@NotNull
protected final MediaSetMetaData publicMetaData;
@NotNull
protected MediaSetSetType setType;
@NotNull
protected String netPath;
private final int brochureLimit;
private int brochureCount = 0;
private boolean processingECat = false;
protected MediaSetNodeWriter(int fvctxVersion, @NotNull LocaleMap localeMap, @NotNull String locale, @NotNull String labelKey, @NotNull MediaSetMetaData publicMetaData, @NotNull MediaSetSetType setType, @NotNull String netPath, int brochureLimit) {
this.fvctxVersion = fvctxVersion;
this.localeMap = localeMap;
this.locale = locale;
this.labelKey = labelKey;
this.publicMetaData = publicMetaData;
this.setType = setType;
this.netPath = netPath;
this.brochureLimit = brochureLimit;
}
abstract void postProcess() throws IZoomException;
Map<String, String> getRootAttributes() {
HashMap<String, String> map = new HashMap<String, String>();
StringBuilder pv = new StringBuilder();
pv.append(this.fvctxVersion);
pv.append(".0");
map.put("pv", pv.toString());
map.put("type", this.setType.name().toLowerCase());
if (this.setType == MediaSetSetType.ECAT || this.setType == MediaSetSetType.UNKNOWN) {
this.processingECat = true;
if (this.setType == MediaSetSetType.ECAT) {
map.put("template", "$image0$?layer=0&extendN=0,0,1,0&originN=0,-0.5&layer=1&src=$image1$&originN=-0.5,-0.5&sizeN=0.5,1");
}
}
map.put("n", this.netPath);
if (this.locale.length() > 0) {
map.put("locale", this.locale);
}
return map;
}
Map<String, String> getImageAttributes(@NotNull String netPath, @NotNull String query, @NotNull FvctxImageProps imageProps, boolean isMediaSetItem) {
Map<String, String> map = this.getCommonImageAttributes(netPath, query, imageProps);
if (imageProps.isDefaultImage()) {
map.put("isDefault", "1");
}
if (isMediaSetItem) {
this.processingECat = false;
}
return map;
}
Map<String, String> getCommonImageAttributes(@NotNull String netPath, @NotNull String query, @NotNull FvctxImageProps imageProps) {
String postModifier;
String modifier;
HashMap<String, String> map = new HashMap<String, String>();
StringBuilder name = new StringBuilder(NetPathCoder.netPathCoder().encode(netPath));
if (!query.isEmpty()) {
name.append('?').append(query);
}
map.put("n", name.toString());
LocalizedText label = imageProps.getUserData().getFvctxLabel(this.labelKey);
String labelAsString = label.get(this.localeMap, this.locale);
if (!labelAsString.isEmpty()) {
map.put("l", labelAsString);
}
if (!(modifier = imageProps.getModifier()).isEmpty()) {
map.put("mod", modifier);
}
if (!(postModifier = imageProps.getPostModifier()).isEmpty()) {
map.put("pmod", postModifier);
}
return map;
}
Map<String, String> getCommonVideoAttributes(@NotNull String netPath, @NotNull String query, @NotNull MediaSetVideoProps videoProps) {
HashMap<String, String> map = new HashMap<String, String>();
StringBuilder path = new StringBuilder(NetPathCoder.netPathCoder().encode(netPath));
if (!query.isEmpty()) {
path.append('?').append(query);
}
if (videoProps.isInCatalog()) {
map.put("id", path.toString());
map.put("path", NetPathCoder.netPathCoder().encode(MediaSetNodeWriter.stripDotSlash(videoProps.getFilePath())));
} else {
map.put("path", path.toString());
}
map.put("suffix", videoProps.getFileSuffix());
if (videoProps.getBitRate().isDefined()) {
map.put("bitrate", ((Long)videoProps.getBitRate().get()).toString());
}
if (videoProps.getVideoSize().isDefined()) {
SizeInt videoSize = (SizeInt)videoProps.getVideoSize().get();
map.put("dx", Integer.toString(videoSize.width));
map.put("dy", Integer.toString(videoSize.height));
}
if (videoProps.getVideoFormat().isDefined()) {
map.put("format", (String)videoProps.getVideoFormat().get());
}
this.processingECat = false;
return map;
}
static Map<String, String> getVideoFrameAttributes(@NotNull String version, @NotNull String suffix) {
HashMap<String, String> map = new HashMap<String, String>();
MediaSetItemType itemType = MediaSetItemType.STATIC;
if (MediaSetVideoExtension.isVideoFileExtension(suffix)) {
itemType = MediaSetItemType.VIDEO;
}
map.put("type", itemType.name().toLowerCase());
map.put("iv", version);
return map;
}
Map<String, String> getFrameAttributes(SizeInt size, @NotNull String imageVersion, boolean hasNestedFrame, @NotNull String itemType) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("iv", imageVersion);
if (!hasNestedFrame) {
map.put("dx", MediaSetNodeWriter.stringValueOf(size.width));
map.put("dy", MediaSetNodeWriter.stringValueOf(size.height));
}
if (!itemType.equalsIgnoreCase("img")) {
map.put("type", itemType);
}
return map;
}
static Map<String, String> getSuppressedMetaDataAttributes(@NotNull boolean[] metadataFlags) {
HashMap<String, String> map = new HashMap<String, String>();
if (metadataFlags[3]) {
map.put("map", "1");
}
if (metadataFlags[4]) {
map.put("userdata", "1");
}
return map;
}
Map<String, String> getStartItemAttributes(@NotNull MediaSetItemType itemType) {
HashMap<String, String> map = new HashMap<String, String>();
if (itemType != MediaSetItemType.IMG) {
map.put("type", itemType.name().toLowerCase());
}
if (itemType == MediaSetItemType.ECAT || itemType == MediaSetItemType.UNKNOWN) {
this.processingECat = true;
}
return map;
}
static Map<String, String> getEndItemAttributes(@NotNull String imageVersion) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("iv", imageVersion);
return map;
}
static Map<String, String> getStartSetAttributes(@NotNull String recordName, @NotNull MediaSetSetType setType) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("n", recordName);
map.put("type", setType.name().toLowerCase());
if (setType == MediaSetSetType.ECAT) {
map.put("template", "$image0$?layer=0&extendN=0,0,1,0&originN=0,-0.5&layer=1&src=$image1$&originN=-0.5,-0.5&sizeN=0.5,1");
}
return map;
}
static Map<String, String> getSwatchProps(@NotNull ImageSetColorLabel data, @NotNull LocaleMap localeMap, @NotNull String locale) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("c", data.color.toHexStringNoAlpha());
String swatchLabel = data.label.get(localeMap, locale);
if (!swatchLabel.isEmpty()) {
map.put("l", swatchLabel);
}
return map;
}
boolean[] shouldAppendMetadata(MediaSetMetaData metaData, boolean isPrivate) {
boolean[] appendMetaData = new boolean[5];
ZoomTargets targets = metaData.getTargets();
appendMetaData[0] = !targets.isEmpty();
List<HotSpot> maps = metaData.getMaps();
appendMetaData[1] = !maps.isEmpty();
boolean shouldAppendUserData = false;
for (UserData userData : metaData.getUserData()) {
if (userData.isEmpty(this.labelKey)) continue;
shouldAppendUserData = true;
}
appendMetaData[2] = shouldAppendUserData;
appendMetaData[3] = false;
appendMetaData[4] = false;
if (isPrivate && this.processingECat) {
if (appendMetaData[1] || appendMetaData[2]) {
++this.brochureCount;
}
if (this.brochureCount > this.brochureLimit) {
if (appendMetaData[1]) {
appendMetaData[1] = false;
appendMetaData[3] = true;
}
if (appendMetaData[2]) {
appendMetaData[2] = false;
appendMetaData[4] = true;
}
}
}
return appendMetaData;
}
boolean shouldAppendUserData(UserData userData) {
return !userData.isEmpty(this.labelKey);
}
static boolean shouldSetPagesAttribute(@Nullable String aWidth, @Nullable String aHeight, @Nullable String bWidth, @Nullable String bHeight) {
if (aWidth == null || aHeight == null || bWidth == null || bHeight == null) {
return false;
}
try {
int aWidthAsInt = Integer.parseInt(aWidth);
int aHeightAsInt = Integer.parseInt(aHeight);
int bWidthAsInt = Integer.parseInt(bWidth);
int bHeightAsInt = Integer.parseInt(bHeight);
double aspectRatio1 = (double)aWidthAsInt / (double)aHeightAsInt;
double aspectRatio2 = (double)bWidthAsInt / (double)bHeightAsInt;
return aspectRatio1 < aspectRatio2 * 0.8;
}
catch (NumberFormatException ignore) {
return false;
}
}
@NotNull
private static String stringValueOf(int i) {
return Integer.toString(i);
}
@NotNull
private static String stripDotSlash(@NotNull String s) {
if (s.isEmpty()) {
return s;
}
if (s.length() == 2 && s.equals("./")) {
return s;
}
if (s.length() >= 3 && s.startsWith("./")) {
return s.substring(2);
}
return s;
}
}