GuideProgressiveUtils.java
2.25 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.utils;
import com.adobe.aemds.guide.progressive.GuideProgressiveCompletionInfo;
import com.adobe.aemds.guide.progressive.GuideProgressiveSectionInfo;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideConstants;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class GuideProgressiveUtils {
private static Logger logger = LoggerFactory.getLogger(GuideProgressiveUtils.class);
private static String getSectionJson(Object section) {
if (section instanceof GuideProgressiveSectionInfo) {
return ((GuideProgressiveSectionInfo)section).convertToJSON();
}
if (section instanceof GuideProgressiveCompletionInfo) {
return ((GuideProgressiveCompletionInfo)section).convertToJSON();
}
return null;
}
public static String convertToJson(List<Object> allSections) {
if (allSections.size() == 1) {
return GuideProgressiveUtils.getSectionJson(allSections.get(0));
}
StringWriter jsonStringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter((Writer)jsonStringWriter);
try {
jsonWriter.array();
for (int i = 0; i < allSections.size(); ++i) {
jsonWriter.value((Object)GuideProgressiveUtils.getSectionJson(allSections.get(i)));
}
jsonWriter.endArray();
}
catch (JSONException ex) {
throw new GuideException(ex.getMessage(), (Exception)ex);
}
return jsonStringWriter.toString();
}
public static boolean isGuideProgressiveFieldModel(String guideNodeClass) {
return GuideConstants.GUIDE_PROGRESSIVE_FIELDS_CLASS_NAMES.indexOf(guideNodeClass) >= 0;
}
}