MediaSetNodeXmlWriter.java
13.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.catalog.util.localization.LocaleMap
* com.scene7.is.provider.ImageSetColorLabel
* com.scene7.is.provider.UserData
* com.scene7.is.provider.ZoomTargets
* com.scene7.is.sleng.HotSpot
* com.scene7.is.util.SizeInt
* com.scene7.is.util.XMLUtil
* 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.provider.ImageSetColorLabel;
import com.scene7.is.provider.UserData;
import com.scene7.is.provider.ZoomTargets;
import com.scene7.is.ps.provider.HotSpotResponseGenerator;
import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.UserDataHandler;
import com.scene7.is.ps.provider.fvctx.FvctxImageProps;
import com.scene7.is.ps.provider.fvctx.MediaSetItemType;
import com.scene7.is.ps.provider.fvctx.MediaSetMetaData;
import com.scene7.is.ps.provider.fvctx.MediaSetNodeWriter;
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.HotSpot;
import com.scene7.is.util.SizeInt;
import com.scene7.is.util.XMLUtil;
import com.scene7.is.util.error.ApplicationException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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;
import org.w3c.dom.NodeList;
class MediaSetNodeXmlWriter
extends MediaSetNodeWriter<Document> {
@NotNull
private final Document document = XMLUtil.createDocument();
@NotNull
private final Element root = this.document.createElement("set");
@NotNull
private Element currentElement;
@NotNull
private List<Element> nestedFrameSwatches = new ArrayList<Element>();
MediaSetNodeXmlWriter(int fvctxVersion, @NotNull LocaleMap localeMap, @NotNull String locale, @NotNull String labelKey, @NotNull MediaSetMetaData publicMetaData, @NotNull MediaSetSetType setType, @NotNull String netPath, int brochureLimit) {
super(fvctxVersion, localeMap, locale, labelKey, publicMetaData, setType, netPath, brochureLimit);
this.document.appendChild(this.root);
XMLUtil.appendAsAttributes((Element)this.root, this.getRootAttributes());
this.currentElement = this.root;
}
@Override
public void postProcess() throws IZoomException {
this.appendMetaData(this.document, this.currentElement, this.publicMetaData, this.localeMap, this.locale, false);
}
@NotNull
public Document getProduct() {
MediaSetNodeXmlWriter.addNumPagesAttribute(this.root);
return this.document;
}
@Override
public void startItem(MediaSetItemType type) {
Element item = this.document.createElement("item");
this.currentElement.appendChild(item);
this.currentElement = item;
XMLUtil.appendAsAttributes((Element)this.currentElement, this.getStartItemAttributes(type));
}
@Override
public void endItem(@NotNull String imageVersion) {
XMLUtil.appendAsAttributes((Element)this.currentElement, MediaSetNodeXmlWriter.getEndItemAttributes(imageVersion));
this.currentElement = (Element)this.currentElement.getParentNode();
}
@Override
public void startFrameset() {
throw new UnsupportedOperationException();
}
@Override
public void endFrameset(@NotNull SizeInt size, @NotNull String imageVersion, @NotNull String metaVersion, boolean anonymousFrames) {
throw new UnsupportedOperationException();
}
@Override
public void startSet(@NotNull String recordName, @NotNull MediaSetSetType setType) {
Element set = this.document.createElement("set");
this.currentElement.appendChild(set);
this.currentElement = set;
XMLUtil.appendAsAttributes((Element)this.currentElement, MediaSetNodeXmlWriter.getStartSetAttributes(recordName, setType));
}
@Override
public void endSet(@NotNull MediaSetMetaData metaData) throws IZoomException {
this.appendMetaData(this.document, this.currentElement, metaData, metaData.getLocaleMap(), metaData.getLocale(), false);
this.currentElement = (Element)this.currentElement.getParentNode();
}
@Override
public void startFrame(@NotNull String netPath, @NotNull String query, Request parsedRequest, FvctxImageProps imageProps, boolean hasNestedFrame, boolean isMediaSetItem) {
Element frame = this.document.createElement("item");
this.currentElement.appendChild(frame);
this.currentElement = frame;
if (!hasNestedFrame) {
Element imageElement = this.createImageElement(netPath, query, imageProps, isMediaSetItem);
this.currentElement.appendChild(imageElement);
} else {
this.nestedFrameSwatches.add(null);
}
}
@Override
public void startVideoFrame(@NotNull String netPath, @NotNull String query, @NotNull MediaSetVideoProps videoProps) throws ApplicationException {
Element frame = this.document.createElement("item");
this.currentElement.appendChild(frame);
this.currentElement = frame;
Element video = this.createVideoElement(netPath, query, videoProps);
this.currentElement.appendChild(video);
}
@Override
public void endVideoFrame(@NotNull MediaSetMetaData metaData, @NotNull String version, @NotNull String suffix) throws IZoomException {
XMLUtil.appendAsAttributes((Element)this.currentElement, MediaSetNodeXmlWriter.getVideoFrameAttributes(version, suffix));
this.appendMetaData(this.document, this.currentElement, metaData, metaData.getLocaleMap(), metaData.getLocale(), false);
this.currentElement = (Element)this.currentElement.getParentNode();
}
@Override
public void endFrame(@Nullable SizeInt size, @NotNull String imageVersion, @NotNull MediaSetMetaData metaData, boolean hasNestedFrames) throws IZoomException {
Element nestedFrameSwatch;
XMLUtil.appendAsAttributes((Element)this.currentElement, this.getFrameAttributes(size, imageVersion, hasNestedFrames, MediaSetNodeXmlWriter.findFrameItemType(hasNestedFrames, this.currentElement)));
if (!hasNestedFrames) {
boolean[] metadataFlags = this.appendMetaData(this.document, this.currentElement, metaData, metaData.getLocaleMap(), metaData.getLocale(), true);
XMLUtil.appendAsAttributes((Element)this.currentElement, MediaSetNodeXmlWriter.getSuppressedMetaDataAttributes(metadataFlags));
} else if (!this.nestedFrameSwatches.isEmpty() && (nestedFrameSwatch = this.nestedFrameSwatches.remove(this.nestedFrameSwatches.size() - 1)) != null) {
this.currentElement.appendChild(nestedFrameSwatch);
}
this.currentElement = (Element)this.currentElement.getParentNode();
}
@Override
public void startAnonymousFrame() {
Element frame = this.document.createElement("item");
this.currentElement.appendChild(frame);
this.currentElement = frame;
}
@Override
public void endAnonymousFrame() {
this.currentElement = (Element)this.currentElement.getParentNode();
}
@Override
public void image(@NotNull String netPath, @NotNull String query, Request parsedRequest, FvctxImageProps imageProps) {
Element imageElement = this.createImageElement(netPath, query, imageProps, false);
this.currentElement.appendChild(imageElement);
}
@Override
public void swatch(@NotNull String netPath, @NotNull String query, Request parsedRequest, FvctxImageProps imageProps, boolean hasNestedFrame, boolean isMediaItemSwatch) {
Element swatch = this.createSwatchImageElement(netPath, query, imageProps);
if (hasNestedFrame && !isMediaItemSwatch) {
assert (!this.nestedFrameSwatches.isEmpty());
this.nestedFrameSwatches.set(this.nestedFrameSwatches.size() - 1, swatch);
}
if (!hasNestedFrame || isMediaItemSwatch) {
this.currentElement.appendChild(swatch);
}
}
@Override
public void swatch(@NotNull ImageSetColorLabel data, @NotNull LocaleMap localeMap, @NotNull String locale, boolean hasNestedFrame) {
Element e = this.document.createElement("s");
XMLUtil.appendAsAttributes((Element)e, MediaSetNodeXmlWriter.getSwatchProps(data, localeMap, locale));
if (hasNestedFrame) {
assert (!this.nestedFrameSwatches.isEmpty());
this.nestedFrameSwatches.set(this.nestedFrameSwatches.size() - 1, e);
} else {
this.currentElement.appendChild(e);
}
}
@Override
public void defaultSwatch() throws ApplicationException {
}
@NotNull
private Element createImageElement(@NotNull String netPath, @NotNull String query, @NotNull FvctxImageProps imageProps, boolean isMediaSetItem) {
Element image = this.document.createElement("i");
XMLUtil.appendAsAttributes((Element)image, this.getImageAttributes(netPath, query, imageProps, isMediaSetItem));
return image;
}
@NotNull
private Element createSwatchImageElement(@NotNull String netPath, String query, @NotNull FvctxImageProps imageProps) {
Element swatch = this.document.createElement("s");
XMLUtil.appendAsAttributes((Element)swatch, this.getCommonImageAttributes(netPath, query, imageProps));
return swatch;
}
@NotNull
private Element createVideoElement(@NotNull String netPath, @NotNull String query, @NotNull MediaSetVideoProps videoProps) {
String fileSuffix = videoProps.getFileSuffix();
Element v = MediaSetVideoExtension.isVideoFileExtension(fileSuffix) || fileSuffix.isEmpty() ? this.document.createElement("v") : this.document.createElement("c");
XMLUtil.appendAsAttributes((Element)v, this.getCommonVideoAttributes(netPath, query, videoProps));
return v;
}
private boolean[] appendMetaData(@NotNull Document document, @NotNull Element e, @NotNull MediaSetMetaData metaData, @NotNull LocaleMap localeMap, @NotNull String locale, boolean isPrivate) throws IZoomException {
boolean[] shouldAppendMetaData = this.shouldAppendMetadata(metaData, isPrivate);
if (shouldAppendMetaData[0]) {
Element t = metaData.getTargets().createXmlElement(document, localeMap, locale, true, true);
e.appendChild(t);
}
if (shouldAppendMetaData[1]) {
Element h = HotSpotResponseGenerator.createHotspotXmlElement(document, localeMap, locale, metaData.getMaps());
e.appendChild(h);
}
if (shouldAppendMetaData[2]) {
for (UserData userData : metaData.getUserData()) {
if (!this.shouldAppendUserData(userData)) continue;
Element userDataElement = UserDataHandler.createXmlElement(document, localeMap, locale, userData, this.labelKey);
e.appendChild(userDataElement);
}
}
return shouldAppendMetaData;
}
@NotNull
private static String findFrameItemType(boolean hasNestedFrame, Element element) {
NodeList nodeList;
String itemType = MediaSetItemType.IMG.name().toLowerCase();
if (hasNestedFrame && (nodeList = element.getElementsByTagName("set")).getLength() > 0) {
Element set = (Element)nodeList.item(0);
itemType = set.getAttribute("type");
assert (itemType != null);
assert (itemType.length() > 0);
}
return itemType;
}
private static void addNumPagesAttribute(@NotNull Element root) {
NodeList sets;
String rootType = root.getAttribute("type");
if (rootType != null && MediaSetSetType.isECatSet(rootType)) {
MediaSetNodeXmlWriter.setNumPagesAttribute(root.getChildNodes());
}
if ((sets = root.getElementsByTagName("set")) != null) {
for (int i = 0; i < sets.getLength(); ++i) {
Element set = (Element)sets.item(i);
String elementSetType = set.getAttribute("type");
if (elementSetType == null || !MediaSetSetType.isECatSet(elementSetType)) continue;
MediaSetNodeXmlWriter.setNumPagesAttribute(set.getChildNodes());
}
}
}
private static void setNumPagesAttribute(@NotNull NodeList items) {
if (items.getLength() > 2) {
Element firstItem = (Element)items.item(0);
Element secondItem = (Element)items.item(1);
MediaSetNodeXmlWriter.setNumPagesAttribute(firstItem, secondItem);
Element nextToLastItem = (Element)items.item(items.getLength() - 2);
Element lastItem = (Element)items.item(items.getLength() - 1);
MediaSetNodeXmlWriter.setNumPagesAttribute(lastItem, nextToLastItem);
}
}
private static void setNumPagesAttribute(@NotNull Element a, @NotNull Element b) {
String bHeight;
String bWidth;
String aHeight;
String aWidth;
String aTagName = a.getTagName();
String bTagName = b.getTagName();
if (aTagName.equalsIgnoreCase("item") && bTagName.equalsIgnoreCase("item") && MediaSetNodeXmlWriter.shouldSetPagesAttribute(aWidth = a.getAttribute("dx"), aHeight = a.getAttribute("dy"), bWidth = b.getAttribute("dx"), bHeight = b.getAttribute("dy"))) {
a.setAttribute("np", "1");
}
}
}