GuideElementUtils.java
2.37 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.addon.dor.elements;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GuideElementUtils {
private static Logger logger = LoggerFactory.getLogger(GuideElementUtils.class);
public static boolean isRepeatable(JSONObject jsonObject) {
String minOccur = jsonObject.optString("minOccur", "1");
String maxOccur = jsonObject.optString("maxOccur", minOccur);
if (minOccur.equals("1") && maxOccur.equals("1")) {
return false;
}
return true;
}
public static boolean hasContentBinding(String bindRef) {
if (bindRef != null) {
return bindRef.contains("/text()");
}
return false;
}
public static String removeContentBinding(String bindRef) {
if (bindRef != null) {
return bindRef.replace("/text()", "");
}
return bindRef;
}
public static boolean hasAttributeBinding(String bindRef) {
if (bindRef != null) {
return bindRef.contains("@");
}
return false;
}
public static boolean isDataDescRequired(String bindRef) {
return GuideElementUtils.hasContentBinding(bindRef) || GuideElementUtils.hasAttributeBinding(bindRef);
}
public static String adjustIndexes(String bindRef) {
try {
StringBuilder builder = new StringBuilder(bindRef);
int startIndex = builder.indexOf("[");
int endIndex = builder.indexOf("]");
while (startIndex != -1) {
String replace = builder.substring(startIndex + 1, endIndex);
String replacement = Integer.toString(Integer.parseInt(replace) - 1);
builder.replace(startIndex + 1, endIndex, replacement);
startIndex = builder.indexOf("[", startIndex + 1);
endIndex = builder.indexOf("]", startIndex + 1);
}
return builder.toString();
}
catch (NumberFormatException e) {
logger.error("Bind reference in adaptive form has non number string as index in bind reference " + bindRef, (Throwable)e);
return bindRef;
}
}
}