1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.qa.glnm.galen.specs;
21
22 import java.util.Collection;
23 import java.util.List;
24
25 import org.apache.commons.collections4.Bag;
26 import org.apache.commons.collections4.bag.HashBag;
27 import org.apache.commons.lang3.StringUtils;
28
29 import io.wcm.qa.glnm.galen.validation.GalenValidation;
30 import io.wcm.qa.glnm.selectors.base.NestedSelector;
31
32
33
34
35
36
37 public final class ParsingUtil {
38
39 private static final String PATTERN_LINE_WITH_TAGS_IN_SPEC = "@on";
40
41 private ParsingUtil() {
42
43 }
44
45
46
47
48
49
50 public static Collection<NestedSelector> getSelectorsFromSpec(String specPath) {
51 GalenSpec galenSpec = GalenValidation.readSpec(specPath);
52 return galenSpec.getObjects();
53 }
54
55
56
57
58
59
60
61
62 public static Collection<String> getTags(String specPath) {
63 Bag<String> tags = new HashBag<>();
64 for (String line : GalenParsing.getSourceLines(specPath)) {
65 String trimmedLine = line.trim();
66 if (StringUtils.startsWith(trimmedLine, PATTERN_LINE_WITH_TAGS_IN_SPEC)) {
67 String tagsAsString = StringUtils.removeStart(trimmedLine, PATTERN_LINE_WITH_TAGS_IN_SPEC);
68 String[] tagsAsArray = tagsAsString.split(",");
69 for (String tag : tagsAsArray) {
70 if (StringUtils.isNotBlank(tag)) {
71 String cleanedTag = tag.trim().replaceAll("[^A-Za-z0-9]*", "");
72 if (StringUtils.isNotBlank(cleanedTag)) {
73 tags.add(cleanedTag);
74 }
75 }
76 }
77 }
78 }
79 return tags.uniqueSet();
80 }
81
82 }