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.maven.freemarker.pojo;
21
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25
26 import org.apache.commons.io.FilenameUtils;
27
28 import io.wcm.qa.glnm.galen.specs.ParsingUtil;
29 import io.wcm.qa.glnm.maven.freemarker.util.FormatUtil;
30 import io.wcm.qa.glnm.selectors.base.NestedSelector;
31
32
33
34
35
36
37 public class SpecPojo {
38
39 private Collection<SelectorPojo> selectors;
40 private String specPath;
41
42
43
44
45
46
47 public SpecPojo(String specPath) {
48 setSpecPath(specPath);
49 }
50
51
52
53
54
55
56 public String getBaseName() {
57 return FilenameUtils.getBaseName(getFilename());
58 }
59
60
61
62
63
64
65 public String getClassName() {
66 return FormatUtil.getClassName(getFilename());
67 }
68
69
70
71
72
73
74 public String getFilename() {
75 return FilenameUtils.getBaseName(getSpecPath());
76 }
77
78
79
80
81
82
83 public String getPackageNamePart() {
84 String baseName = getBaseName();
85 return baseName.toLowerCase().replaceAll("[^a-z0-9]", "");
86 }
87
88
89
90
91
92
93 public String getRelativeFilePath() {
94 return getUnixStyleFilePath(getSpecPath());
95 }
96
97
98
99
100
101
102 public Collection<SelectorPojo> getRootSelectors() {
103 Collection<SelectorPojo> rootSelectors = new ArrayList<>();
104 for (NestedSelector selector : getSelectors()) {
105 if (!selector.hasParent()) {
106 rootSelectors.add(new SelectorPojo(this, selector));
107 }
108 }
109 return rootSelectors;
110 }
111
112
113
114
115
116
117 public Collection<SelectorPojo> getSelectors() {
118 if (selectors == null) {
119 selectors = new ArrayList<SelectorPojo>();
120 for (NestedSelector selector : ParsingUtil.getSelectorsFromSpec(getSpecPath())) {
121 selectors.add(new SelectorPojo(this, selector));
122 }
123 }
124 return selectors;
125 }
126
127
128
129
130
131
132 public String getSpecPath() {
133 return specPath;
134 }
135
136
137
138
139
140
141 public Collection<String> getTags() {
142 return ParsingUtil.getTags(getSpecPath());
143 }
144
145 private void setSpecPath(String specPath) {
146 this.specPath = specPath;
147 }
148
149 private static String getUnixStyleFilePath(String path) {
150 return FilenameUtils.normalize(path, true);
151 }
152
153 }