1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.devops.conga.plugins.aem.maven.model;
21
22 import java.util.Collections;
23 import java.util.LinkedHashSet;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.apache.commons.lang3.StringUtils;
29
30
31
32
33 final class ParserUtil {
34
35 private static final String PROP_VARIANTS = "variants";
36
37 private ParserUtil() {
38
39 }
40
41 @SuppressWarnings("unchecked")
42 static List<Map<String, Object>> children(Map<String, Object> data, String propertyName) {
43 List<Map<String, Object>> children = (List<Map<String, Object>>)data.get(propertyName);
44 if (children == null) {
45 return Collections.emptyList();
46 }
47 else {
48 return children;
49 }
50 }
51
52 @SuppressWarnings("unchecked")
53 static Set<String> toStringSet(Object value) {
54 Set<String> result = new LinkedHashSet<>();
55 if (value instanceof String stringValue) {
56 String target = stringValue;
57 if (StringUtils.isNotBlank(target)) {
58 result.add(target);
59 }
60 }
61 else if (value instanceof List) {
62 result.addAll(((List<String>)value).stream()
63 .filter(StringUtils::isNotBlank)
64 .toList());
65 }
66 else {
67 throw new IllegalArgumentException("Value is neither string nor string list: " + value);
68 }
69 return result;
70 }
71
72 @SuppressWarnings("unchecked")
73 static List<String> getVariants(Map<String, Object> roleData) {
74 List<String> variants = (List<String>)roleData.get(PROP_VARIANTS);
75 if (variants != null) {
76 return variants;
77 }
78 else {
79 return Collections.emptyList();
80 }
81 }
82
83 }