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 |
|
import javax.annotation.Nullable; |
23 |
|
|
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import com.google.common.base.Strings; |
29 |
|
import com.google.common.collect.Lists; |
30 |
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
31 |
|
import org.codehaus.plexus.util.xml.Xpp3Dom; |
32 |
|
import org.devacfr.maven.skins.reflow.ISkinConfig; |
33 |
|
import org.devacfr.maven.skins.reflow.SkinConfigTool; |
34 |
|
import org.devacfr.maven.skins.reflow.Xpp3Utils; |
35 |
|
|
36 |
|
import static java.util.Objects.requireNonNull; |
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 |
|
@author |
66 |
|
@since |
67 |
|
|
|
|
| 56,4% |
Uncovered Elements: 34 (78) |
Complexity: 19 |
Complexity Density: 0,36 |
|
68 |
|
public class NavSideMenu extends BsComponent { |
69 |
|
|
70 |
|
|
71 |
|
private static final String COMPONENT = "navside-menu"; |
72 |
|
|
73 |
|
|
74 |
|
private static final String MENU_COMPONENT = "menu"; |
75 |
|
|
76 |
|
|
77 |
|
private String name; |
78 |
|
|
79 |
|
|
80 |
|
private List<SideNavMenuItem> items; |
81 |
|
|
82 |
|
|
83 |
|
private boolean selectFirstOnExpand = false; |
84 |
|
|
85 |
|
|
86 |
|
@link |
87 |
|
|
88 |
|
@param |
89 |
|
|
90 |
|
@return@link |
91 |
|
|
92 |
|
|
|
|
| 84,6% |
Uncovered Elements: 4 (26) |
Complexity: 6 |
Complexity Density: 0,33 |
|
93 |
17 |
@Nonnull... |
94 |
|
public static List<SideNavMenuItem> findAllSideNavMenuItems(@Nonnull final ISkinConfig config) { |
95 |
17 |
requireNonNull(config); |
96 |
17 |
final Xpp3Dom pagesNode = Xpp3Utils.getFirstChild(config.getGlobalProperties(), "pages", config.getNamespace()); |
97 |
17 |
if (pagesNode == null) { |
98 |
10 |
return Collections.emptyList(); |
99 |
|
} |
100 |
7 |
final Xpp3Dom[] pages = pagesNode.getChildren(); |
101 |
7 |
final List<SideNavMenuItem> includePages = new ArrayList<>(); |
102 |
7 |
for (final Xpp3Dom page : pages) { |
103 |
19 |
final String type = page.getAttribute("type"); |
104 |
19 |
if ("doc".equals(type)) { |
105 |
|
|
106 |
|
|
107 |
7 |
final String projectId = page.getAttribute("project"); |
108 |
7 |
if (!Strings.isNullOrEmpty(projectId) && !projectId.equals(config.getProjectId())) { |
109 |
0 |
continue; |
110 |
|
} |
111 |
7 |
final Xpp3Dom menu = page.getChild(MENU_COMPONENT); |
112 |
7 |
if (menu == null) { |
113 |
0 |
continue; |
114 |
|
} |
115 |
7 |
final String pageName = page.getName(); |
116 |
|
|
117 |
7 |
addMenuItemRecursively(includePages, config, menu, pageName, true); |
118 |
|
} |
119 |
|
} |
120 |
7 |
return includePages; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
|
128 |
|
|
|
|
| 52,6% |
Uncovered Elements: 9 (19) |
Complexity: 3 |
Complexity Density: 0,2 |
|
129 |
1 |
public NavSideMenu(@Nonnull final ISkinConfig config) {... |
130 |
1 |
super("navside"); |
131 |
1 |
requireNonNull(config); |
132 |
1 |
final Xpp3Dom pageNode = config.getPageProperties(); |
133 |
1 |
final Xpp3Dom menu = pageNode.getChild(MENU_COMPONENT); |
134 |
1 |
final List<SideNavMenuItem> items = Lists.newArrayList(); |
135 |
1 |
if (menu != null) { |
136 |
0 |
final String pageName = pageNode.getName(); |
137 |
0 |
addMenuItemRecursively(items, config, menu, pageName, false); |
138 |
|
|
139 |
0 |
this.withName(menu.getAttribute("name")) |
140 |
|
.withItems(items) |
141 |
|
.withSelectFirstOnSelect( |
142 |
|
config.getAttributeValue(MENU_COMPONENT, "selectFirstOnExpand", Boolean.class, true)); |
143 |
0 |
this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, "light")); |
144 |
0 |
this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, "light")); |
145 |
0 |
this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null)); |
146 |
|
} |
147 |
1 |
this.addCssOptions("m-sidenav-enabled"); |
148 |
1 |
if (isSelectFirstOnExpand()) { |
149 |
0 |
this.addCssOptions("m-sidenav-select-first-on-select"); |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
@return@link |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
158 |
0 |
@Nullable public String getName() {... |
159 |
0 |
return name; |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
@param |
166 |
|
|
167 |
|
@return |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
169 |
0 |
protected NavSideMenu withName(final String name) {... |
170 |
0 |
this.name = name; |
171 |
0 |
return this; |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@return |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
0 |
public boolean isHasItems() {... |
180 |
0 |
return items != null && !items.isEmpty(); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
@return@link@link |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
0 |
@Nonnull... |
187 |
|
public List<SideNavMenuItem> getItems() { |
188 |
0 |
return items; |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
@link@link |
193 |
|
|
194 |
|
@param |
195 |
|
|
196 |
|
@return |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
198 |
0 |
protected NavSideMenu withItems(final List<SideNavMenuItem> items) {... |
199 |
0 |
this.items = items; |
200 |
0 |
return this; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@return |
208 |
|
|
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
1 |
public boolean isSelectFirstOnExpand() {... |
211 |
1 |
return selectFirstOnExpand; |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
@param |
219 |
|
|
220 |
|
@return |
221 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
222 |
0 |
protected NavSideMenu withSelectFirstOnSelect(final boolean selectFirstOnExpand) {... |
223 |
0 |
this.selectFirstOnExpand = selectFirstOnExpand; |
224 |
0 |
return this; |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
@inheritDoc |
229 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
0 |
@Override... |
231 |
|
public String toString() { |
232 |
0 |
return ToStringBuilder.reflectionToString(this); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
@param |
237 |
|
@param |
238 |
|
@param |
239 |
|
@param |
240 |
|
|
|
|
| 63,6% |
Uncovered Elements: 4 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
241 |
28 |
private static void addMenuItemRecursively(@Nonnull final List<SideNavMenuItem> menuItems,... |
242 |
|
@Nonnull final ISkinConfig config, |
243 |
|
@Nonnull final Xpp3Dom parentNode, |
244 |
|
@Nonnull final String pageName, |
245 |
|
final boolean flatten) { |
246 |
28 |
for (final Xpp3Dom item : Xpp3Utils.getChildrenNodes(parentNode, "item")) { |
247 |
21 |
final String href = item.getAttribute("href"); |
248 |
21 |
final SideNavMenuItem menuItem = new SideNavMenuItem().withName(item.getAttribute("name")) |
249 |
|
.withParent(pageName) |
250 |
|
.withHref(config.relativeLink(href)) |
251 |
|
.withSlugName(SkinConfigTool.slugFilename(href)) |
252 |
|
.withIcon(item.getAttribute("icon")); |
253 |
21 |
menuItems.add(menuItem); |
254 |
21 |
if (flatten) { |
255 |
21 |
addMenuItemRecursively(menuItems, config, item, pageName, true); |
256 |
|
} else { |
257 |
0 |
final List<SideNavMenuItem> list = new ArrayList<>(); |
258 |
0 |
menuItem.withItems(list); |
259 |
0 |
addMenuItemRecursively(list, config, item, pageName, false); |
260 |
|
} |
261 |
|
} |
262 |
|
} |
263 |
|
} |