DuplicateBindrefsCollector.java
2.75 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang3.StringUtils
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.aemds.guide.utils.guideJson;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.guideJson.GuideJsonVisitor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.commons.json.JSONObject;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class DuplicateBindrefsCollector
implements GuideJsonVisitor {
private Map<String, Boolean> bindRefDupStatus = new HashMap<String, Boolean>();
private Boolean skipDescendants = false;
private String currentRepeatable = null;
@Override
public void visitItem(JSONObject obj) {
if (!this.skipDescendants.booleanValue() && !"guidePanel".equals(obj.optString("guideNodeClass"))) {
String bindRef = obj.optString("bindRef");
String effectiveBindRef = null;
if (StringUtils.isBlank((CharSequence)bindRef)) {
effectiveBindRef = obj.optString("name");
} else if (StringUtils.startsWith((CharSequence)bindRef, (CharSequence)"/")) {
effectiveBindRef = bindRef;
}
if (StringUtils.isNotEmpty((CharSequence)StringUtils.trim((String)effectiveBindRef))) {
this.bindRefDupStatus.put(effectiveBindRef, this.bindRefDupStatus.containsKey(effectiveBindRef));
}
}
}
public List<String> getDuplicatedBindRefs() {
ArrayList<String> duplicatedBindRefs = new ArrayList<String>();
for (String bindRef : this.bindRefDupStatus.keySet()) {
if (!this.bindRefDupStatus.get(bindRef).booleanValue()) continue;
duplicatedBindRefs.add(bindRef);
}
return duplicatedBindRefs;
}
private boolean isSkippableItem(JSONObject obj) {
return GuideUtils.isCompositeField(obj) || GuideUtils.isRepeatablePanel(obj);
}
@Override
public void preRecurse(JSONObject obj) {
if (!this.skipDescendants.booleanValue() && this.isSkippableItem(obj)) {
this.skipDescendants = true;
this.currentRepeatable = obj.optString("templateId");
}
}
@Override
public void postRecurse(JSONObject obj) {
if (this.skipDescendants.booleanValue() && StringUtils.isNotBlank((CharSequence)this.currentRepeatable) && StringUtils.equals((CharSequence)this.currentRepeatable, (CharSequence)obj.optString("templateId"))) {
this.skipDescendants = false;
this.currentRepeatable = null;
}
}
}