TableUtils.java
2.55 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.utils;
import java.util.Arrays;
import java.util.Iterator;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TableUtils {
public static final String[] DISALLOWED_PANEL_ELEMENTS_IN_TABLE = new String[]{"guidePanel", "guideTable"};
public static final String GUIDE_NODE_CLASS = "guideNodeClass";
public static final String ITEMS = "items";
private static Logger logger = LoggerFactory.getLogger(TableUtils.class);
public static int getColumnsCount(JSONObject table) {
int columnsCount = 0;
try {
JSONObject tableItems = table.getJSONObject("items");
Iterator itr = tableItems.keys();
JSONObject item = null;
while (itr.hasNext() && ((item = tableItems.optJSONObject((String)itr.next())) == null || !item.has("guideNodeClass"))) {
}
JSONObject headerRow = item;
JSONObject headerRowItems = headerRow.getJSONObject("items");
itr = headerRowItems.keys();
while (itr.hasNext()) {
item = headerRowItems.optJSONObject((String)itr.next());
if (item == null || !item.has("guideNodeClass")) continue;
++columnsCount;
}
}
catch (JSONException e) {
logger.error("JSON exception while finding number of columns in a table", (Throwable)e);
}
return columnsCount;
}
public static boolean shouldGenerateDoRTable(JSONObject panel) {
try {
JSONObject panelItems = panel.getJSONObject("items");
Iterator itr = panelItems.keys();
while (itr.hasNext()) {
JSONObject item = panelItems.optJSONObject((String)itr.next());
if (item == null || !Arrays.asList(DISALLOWED_PANEL_ELEMENTS_IN_TABLE).contains(item.optString("guideNodeClass"))) continue;
logger.warn("Not converting Repeatable panel to Table as it contains a " + item.optString("guideNodeClass"));
return false;
}
}
catch (JSONException e) {
logger.error("JSON exception while finding whether to convert repeatable panel to Table in DoR", (Throwable)e);
}
return true;
}
}