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 static com.google.common.base.Strings.isNullOrEmpty;
22 import static java.util.Objects.requireNonNull;
23
24 import java.util.List;
25 import java.util.Objects;
26
27 import javax.annotation.Nonnull;
28
29 import org.apache.maven.doxia.site.LinkItem;
30 import org.devacfr.maven.skins.reflow.ISkinConfig;
31
32 import com.google.common.collect.Lists;
33
34
35
36
37
38 public class Menu {
39
40
41 private final String name;
42
43
44 private final String alt;
45
46
47 private final String border;
48
49
50 private final String height;
51
52
53 private final String width;
54
55
56 private final String href;
57
58
59 private final String image;
60
61
62 private final String position;
63
64
65 private final String target;
66
67
68 private final String title;
69
70
71 private final String inherit;
72
73
74 private final boolean active;
75
76
77 private final List<MenuItem> menuItems = Lists.newArrayList();
78
79
80
81
82
83
84
85
86
87 public Menu(@Nonnull final ISkinConfig config, @Nonnull final LinkItem item) {
88 Objects.requireNonNull(item);
89 this.alt = item.getAlt();
90 this.border = item.getBorder();
91 this.height = item.getHeight();
92 this.width = item.getWidth();
93 this.href = config.relativeLink(item.getHref());
94 this.image = item.getImg();
95 this.name = item.getName();
96 this.position = item.getPosition();
97 this.target = item.getTarget();
98 this.title = item.getTitle();
99 this.active = config.isActiveLink(this.href);
100 this.inherit = null;
101 }
102
103
104
105
106
107
108
109
110
111 public Menu(@Nonnull final ISkinConfig config, @Nonnull final org.apache.maven.doxia.site.Menu menu) {
112 Objects.requireNonNull(menu);
113 this.alt = menu.getAlt();
114 this.border = menu.getBorder();
115 this.height = menu.getHeight();
116 this.width = menu.getWidth();
117 this.href = null;
118 this.image = menu.getImg();
119 this.name = menu.getName();
120 this.position = menu.getPosition();
121 this.target = null;
122 this.title = menu.getTitle();
123 this.inherit = menu.getInherit();
124 this.active = false;
125 final List<org.apache.maven.doxia.site.MenuItem> items = menu.getItems();
126 for (final org.apache.maven.doxia.site.MenuItem menuItem : items) {
127 if (isNullOrEmpty(menu.getName())) {
128 continue;
129 }
130 this.menuItems.add(new MenuItem(config, menuItem));
131 }
132 }
133
134
135
136
137 public List<MenuItem> getMenuItems() {
138 return menuItems;
139 }
140
141
142
143
144 public String getName() {
145 return name;
146 }
147
148
149
150
151 public String getInherit() {
152 return inherit;
153 }
154
155
156
157
158 public boolean isActive() {
159 boolean active = this.active;
160 if (active) {
161 return active;
162 }
163 for (final MenuItem menuItem : menuItems) {
164 active = menuItem.isActive();
165 if (active) {
166 break;
167 }
168 }
169 return active;
170 }
171
172
173
174
175 public String getAlt() {
176 return alt;
177 }
178
179
180
181
182 public String getBorder() {
183 return border;
184 }
185
186
187
188
189 public String getHeight() {
190 return height;
191 }
192
193
194
195
196 public String getHref() {
197 return href;
198 }
199
200
201
202
203 public String getImage() {
204 return image;
205 }
206
207
208
209
210 public String getPosition() {
211 return position;
212 }
213
214
215
216
217 public String getTarget() {
218 return target;
219 }
220
221
222
223
224 public String getTitle() {
225 return title;
226 }
227
228
229
230
231 public String getWidth() {
232 return width;
233 }
234
235
236
237
238
239
240
241
242
243
244
245 public static boolean matches(@Nonnull final String regex, @Nonnull final org.apache.maven.doxia.site.Menu menu) {
246 requireNonNull(regex);
247 requireNonNull(menu);
248 return menu.getRef() != null && menu.getRef().matches(regex)
249 || menu.getName() != null && menu.getName().matches(regex);
250 }
251 }