MediaSetPipelineProcessor.java
10.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
/*
* 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.ImageSet
* com.scene7.is.provider.ImageSetColorLabel
* com.scene7.is.provider.ImageSetItem
* com.scene7.is.sleng.Color
* com.scene7.is.util.SizeInt
* com.scene7.is.util.UrlRequest
* com.scene7.is.util.error.ApplicationException
* 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.ImageSet;
import com.scene7.is.provider.ImageSetColorLabel;
import com.scene7.is.provider.ImageSetItem;
import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.ModifierSet;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.defs.ModifierEnum;
import com.scene7.is.ps.provider.fvctx.FvctxImageProps;
import com.scene7.is.ps.provider.fvctx.FvctxNode;
import com.scene7.is.ps.provider.fvctx.FvctxUtil;
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.MediaSetVideoEntry;
import com.scene7.is.ps.provider.fvctx.MediaSetVideoProps;
import com.scene7.is.sleng.Color;
import com.scene7.is.util.SizeInt;
import com.scene7.is.util.UrlRequest;
import com.scene7.is.util.error.ApplicationException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class MediaSetPipelineProcessor {
public static void processImage(@NotNull Request request, @NotNull FvctxNode pipeline, @Nullable ImageSetItem swatch, boolean isMediaSet) throws IZoomException {
try {
ModifierSet attr = request.getGlobalAttributes();
String netPath = "/" + attr.getOrDie(ModifierEnum.I_NET_PATH);
String netQuery = "";
if (isMediaSet) {
netQuery = attr.getOrDie(ModifierEnum.I_NET_QUERY);
}
pipeline.startFrame(netPath, netQuery, request, null, false, isMediaSet);
MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, e.getMessage(), (Throwable)e);
}
}
public static void processSingleVideo(@NotNull MediaSetVideoEntry videoEntry, @NotNull FvctxNode pipeline, @Nullable ImageSetItem swatch) throws IZoomException {
try {
MediaSetVideoProps videoProps = new MediaSetVideoProps(videoEntry);
pipeline.startVideoFrame(videoEntry.getNetPath(), "", videoProps);
String posterImageId = videoEntry.getPosterImage();
if (posterImageId != null) {
pipeline.image(posterImageId, "", null, null);
}
MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
pipeline.endVideoFrame(MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, "", videoEntry.getFileSuffix());
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, e.getMessage(), (Throwable)e);
}
}
public static void processOuterVideoSet(@NotNull List<MediaSetVideoEntry> videoEntries, @NotNull FvctxNode pipeline) throws IZoomException {
for (MediaSetVideoEntry videoEntry : videoEntries) {
MediaSetPipelineProcessor.processSingleVideo(videoEntry, pipeline, null);
}
}
public static void processVideoSetAsMediaSetItem(@NotNull MediaSetItemType videoSetType, @NotNull List<MediaSetVideoEntry> videoEntries, @NotNull FvctxNode pipeline, @NotNull String recordName, @Nullable ImageSetItem swatch, @NotNull MediaSetMetaData mediaSetItemMetaData) throws IZoomException {
try {
pipeline.startItem(videoSetType);
pipeline.startSet(recordName, MediaSetItemType.convertItemToSetType(videoSetType));
MediaSetPipelineProcessor.processOuterVideoSet(videoEntries, pipeline);
pipeline.endSet(mediaSetItemMetaData);
MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
pipeline.endItem("");
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, e.getMessage(), (Throwable)e);
}
}
public static void processImageSet(@NotNull ImageSet imageSet, @NotNull FvctxNode pipeline, @NotNull MediaSetSetType setType, @NotNull MediaSetItemType itemType, @Nullable ImageSetItem swatch, boolean isMediaSet, boolean isNestedSet, @NotNull String recordName, @NotNull MediaSetMetaData mediaSetItemMetaData) throws IZoomException {
try {
if (imageSet.items.isEmpty()) {
return;
}
if (((ImageSetItem)imageSet.items.get((int)0)).separator != ',') {
throw new IZoomException(IZoomException.FVCTX_NO_FRAME_AT_START_IMAGESET, imageSet.generateString(), null);
}
if (isMediaSet) {
pipeline.startItem(itemType);
pipeline.startSet(recordName, setType);
} else if (isNestedSet) {
pipeline.startSet(recordName, setType);
}
int i = 0;
for (ImageSetItem item : imageSet.items) {
switch (item.separator) {
case ',': {
MediaSetPipelineProcessor.processFrame(i, item, pipeline);
break;
}
case ':': {
MediaSetPipelineProcessor.processImage(item, pipeline);
break;
}
case ';': {
MediaSetPipelineProcessor.processSwatch(item, pipeline, mediaSetItemMetaData.getLocaleMap(), mediaSetItemMetaData.getLocale());
break;
}
default: {
throw new IZoomException(IZoomException.FVCTX_INVALID_SEPARATOR, MediaSetPipelineProcessor.errorMessage(item), null);
}
}
++i;
}
pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
if (isMediaSet) {
pipeline.endSet(mediaSetItemMetaData);
MediaSetPipelineProcessor.handleSwatch(swatch, pipeline);
pipeline.endItem("");
} else if (isNestedSet) {
pipeline.endSet(mediaSetItemMetaData);
}
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_SWATCH_ERROR, e.getMessage(), (Throwable)e);
}
}
private MediaSetPipelineProcessor() {
}
private static void processFrame(int i, @NotNull ImageSetItem item, @NotNull FvctxNode pipeline) throws IZoomException {
try {
if (i > 0) {
pipeline.endFrame(null, "", MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA, false);
}
if (item.asset == null || item.asset.isEmpty()) {
throw new IZoomException(IZoomException.FVCTX_IMAGE_EXPECTED, item.generateString(), null);
}
if (FvctxUtil.hasBraces(item.asset)) {
pipeline.startFrame(item.asset, "", null, null, false, false);
} else {
UrlRequest request = UrlRequest.splitUrlRequest((String)item.asset);
pipeline.startFrame(request.path, request.query, null, null, false, false);
}
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_FRAME_ERROR, MediaSetPipelineProcessor.errorMessage(item), (Throwable)e);
}
}
private static void processImage(@NotNull ImageSetItem item, @NotNull FvctxNode pipeline) throws IZoomException {
try {
UrlRequest request = MediaSetPipelineProcessor.processImageAsset(item);
if (request != null) {
pipeline.image(request.path, request.query, null, null);
}
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_IMAGE_ERROR, MediaSetPipelineProcessor.errorMessage(item), (Throwable)e);
}
}
private static boolean processSwatch(@NotNull ImageSetItem item, @NotNull FvctxNode pipeline, @NotNull LocaleMap localeMap, @NotNull String locale) throws IZoomException {
try {
if (item.colorLabel != null) {
pipeline.swatch(new ImageSetColorLabel(item.colorLabel.color, item.colorLabel.label.urlDecode()), localeMap, locale, false);
return false;
}
UrlRequest request = MediaSetPipelineProcessor.processImageAsset(item);
if (request != null) {
pipeline.swatch(request.path, request.query, null, null, false, false);
return false;
}
return true;
}
catch (IZoomException e) {
throw e;
}
catch (ApplicationException e) {
throw new IZoomException(IZoomException.FVCTX_SWATCH_ERROR, MediaSetPipelineProcessor.errorMessage(item), (Throwable)e);
}
catch (IllegalArgumentException e) {
throw new IZoomException(IZoomException.FVCTX_INVALID_COLOR_LABEL, MediaSetPipelineProcessor.errorMessage(item), e);
}
}
private static void handleSwatch(@Nullable ImageSetItem swatch, @NotNull FvctxNode pipeline) throws ApplicationException {
UrlRequest swatchRequest;
if (swatch != null && (swatchRequest = MediaSetPipelineProcessor.processImageAsset(swatch)) != null) {
pipeline.swatch(swatchRequest.path, swatchRequest.query, null, null, false, true);
}
}
@Nullable
private static UrlRequest processImageAsset(@NotNull ImageSetItem item) throws IZoomException {
if (item.asset == null) {
throw new IZoomException(IZoomException.FVCTX_IMAGE_EXPECTED, item.generateString(), null);
}
if (item.asset.isEmpty()) {
return null;
}
return UrlRequest.splitUrlRequest((String)item.asset);
}
@NotNull
private static String errorMessage(@NotNull ImageSetItem item) {
return item.generateString();
}
}