1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.devacfr.maven.skins.reflow.model; |
20 |
|
|
21 |
|
import javax.annotation.Nonnull; |
22 |
|
|
23 |
|
import java.util.List; |
24 |
|
import java.util.Objects; |
25 |
|
|
26 |
|
import com.google.common.collect.Lists; |
27 |
|
import org.apache.maven.doxia.site.SiteModel; |
28 |
|
import org.apache.maven.doxia.site.LinkItem; |
29 |
|
import org.apache.maven.project.MavenProject; |
30 |
|
import org.codehaus.plexus.util.xml.Xpp3Dom; |
31 |
|
import org.devacfr.maven.skins.reflow.ISkinConfig; |
32 |
|
import org.devacfr.maven.skins.reflow.Xpp3Utils; |
33 |
|
|
34 |
|
import static com.google.common.base.Strings.isNullOrEmpty; |
35 |
|
import static java.util.Objects.requireNonNull; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@author |
41 |
|
@since |
42 |
|
|
|
|
| 68,8% |
Uncovered Elements: 24 (77) |
Complexity: 21 |
Complexity Density: 0,44 |
|
43 |
|
public class Navbar extends BsComponent { |
44 |
|
|
45 |
|
|
46 |
|
public static final String COMPONENT = "navbar"; |
47 |
|
|
48 |
|
|
49 |
|
private String brandName; |
50 |
|
|
51 |
|
|
52 |
|
private String brandHref; |
53 |
|
|
54 |
|
|
55 |
|
private final String filterMenu; |
56 |
|
|
57 |
|
|
58 |
|
private final boolean center; |
59 |
|
|
60 |
|
|
61 |
|
private final String alignMenu; |
62 |
|
|
63 |
|
|
64 |
|
private final ImageBrand image; |
65 |
|
|
66 |
|
|
67 |
|
private final List<Menu> menus = Lists.newArrayList(); |
68 |
|
|
69 |
|
|
70 |
|
private final Xpp3Dom additionalMenu; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@param |
76 |
|
|
77 |
|
|
|
|
| 86,7% |
Uncovered Elements: 8 (60) |
Complexity: 13 |
Complexity Density: 0,32 |
|
78 |
17 |
public Navbar(@Nonnull final ISkinConfig config) {... |
79 |
17 |
super(COMPONENT); |
80 |
17 |
requireNonNull(config); |
81 |
17 |
final MavenProject project = config.getProject(); |
82 |
17 |
final Xpp3Dom brand = config.get("brand"); |
83 |
17 |
if (brand != null) { |
84 |
6 |
final Xpp3Dom name = brand.getChild("name"); |
85 |
6 |
if (name != null) { |
86 |
6 |
brandName = name.getValue(); |
87 |
|
} |
88 |
6 |
final Xpp3Dom href = brand.getChild("href"); |
89 |
6 |
if (href != null) { |
90 |
6 |
brandHref = config.relativeLink(href.getValue()); |
91 |
|
} |
92 |
|
} else { |
93 |
11 |
brandName = project.getName(); |
94 |
|
} |
95 |
17 |
if (isNullOrEmpty(brandName)) { |
96 |
0 |
brandName = project.getArtifactId(); |
97 |
|
} |
98 |
17 |
this.center = config.getAttributeValue(COMPONENT, "center", Boolean.class, true); |
99 |
17 |
this.alignMenu = config.getAttributeValue(COMPONENT, "alignMenu", String.class, "right"); |
100 |
17 |
this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, "light")); |
101 |
17 |
this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, "light")); |
102 |
17 |
this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null)); |
103 |
17 |
this.filterMenu = config.getAttributeValue(COMPONENT, "filterMenu", String.class, null); |
104 |
17 |
Xpp3Dom element = config.get(COMPONENT); |
105 |
17 |
final Xpp3Dom img = Xpp3Utils.getFirstChild(element, "image", config.getNamespace()); |
106 |
17 |
if (img != null) { |
107 |
6 |
this.image = new ImageBrand(config, img); |
108 |
|
} else { |
109 |
11 |
this.image = null; |
110 |
|
} |
111 |
17 |
this.additionalMenu = Xpp3Utils.getFirstChild(element, "additionalMenu", config.getNamespace()); |
112 |
|
|
113 |
|
|
114 |
17 |
final SiteModel model = config.getSiteModel(); |
115 |
17 |
if (model.getBody() != null && model.getBody().getLinks() != null) { |
116 |
6 |
final List<LinkItem> items = model.getBody().getLinks(); |
117 |
6 |
for (final LinkItem item : items) { |
118 |
6 |
this.menus.add(new Menu(config, item)); |
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
17 |
if (model.getBody() != null && model.getBody().getMenus() != null) { |
123 |
6 |
final List<org.apache.maven.doxia.site.Menu> menus = model.getBody().getMenus(); |
124 |
6 |
for (final org.apache.maven.doxia.site.Menu menu : menus) { |
125 |
30 |
if (isNullOrEmpty(menu.getName())) { |
126 |
0 |
continue; |
127 |
|
} |
128 |
30 |
if (isNullOrEmpty(this.filterMenu)) { |
129 |
0 |
this.menus.add(new Menu(config, menu)); |
130 |
30 |
} else if (Menu.matches(this.filterMenu, menu)) { |
131 |
12 |
this.menus.add(new Menu(config, menu)); |
132 |
|
} |
133 |
|
} |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@return |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
public String getBrandName() {... |
141 |
0 |
return brandName; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
0 |
public String getBrandHref() {... |
148 |
0 |
return brandHref; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
@return |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
0 |
public boolean isCenter() {... |
155 |
0 |
return center; |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
@return |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
0 |
public String getAlignMenu() {... |
162 |
0 |
return alignMenu; |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
@return |
167 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
168 |
0 |
public ImageBrand getImage() {... |
169 |
0 |
return image; |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
@return |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0 |
public String getFilterMenu() {... |
176 |
0 |
return filterMenu; |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
@return |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0 |
public Xpp3Dom getAdditionalMenu() {... |
183 |
0 |
return additionalMenu; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
@return |
188 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
0 |
public List<Menu> getMenus() {... |
190 |
0 |
return menus; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
@author |
195 |
|
@since |
196 |
|
|
|
|
| 52,9% |
Uncovered Elements: 8 (17) |
Complexity: 5 |
Complexity Density: 0,45 |
|
197 |
|
public static class ImageBrand { |
198 |
|
|
199 |
|
|
200 |
|
private final String src; |
201 |
|
|
202 |
|
|
203 |
|
private final String width; |
204 |
|
|
205 |
|
|
206 |
|
private final String height; |
207 |
|
|
208 |
|
|
209 |
|
@param |
210 |
|
|
211 |
|
@param |
212 |
|
|
213 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
214 |
6 |
ImageBrand(@Nonnull final ISkinConfig config, @Nonnull final Xpp3Dom element) {... |
215 |
6 |
Objects.requireNonNull(config); |
216 |
6 |
Objects.requireNonNull(element); |
217 |
6 |
final String link = config.getAttributeValue(element, "src", String.class, null); |
218 |
6 |
if (isNullOrEmpty(link)) { |
219 |
0 |
throw new IllegalArgumentException("the attribute 'href' of image element is required"); |
220 |
|
} |
221 |
6 |
this.src = config.eval(link, String.class); |
222 |
6 |
this.width = config.getAttributeValue(element, "width", String.class, "30"); |
223 |
6 |
this.height = config.getAttributeValue(element, "height", String.class, "30"); |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
|
@return |
228 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
229 |
0 |
public String getSrc() {... |
230 |
0 |
return src; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
@return |
235 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
236 |
0 |
public String getHeight() {... |
237 |
0 |
return height; |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
@return |
242 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
243 |
0 |
public String getWidth() {... |
244 |
0 |
return width; |
245 |
|
} |
246 |
|
} |
247 |
|
} |