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.Image;
30 import org.apache.maven.doxia.site.LinkItem;
31 import org.devacfr.maven.skins.reflow.ISkinConfig;
32
33 import com.google.common.collect.Lists;
34
35
36
37
38
39 public class Menu {
40
41
42 private final String name;
43
44
45
46
47 private final String href;
48
49
50 private final Image image;
51
52
53
54
55 private final String target;
56
57
58
59 private final String inherit;
60
61
62 private final boolean active;
63
64
65 private final List<MenuItem> menuItems = Lists.newArrayList();
66
67
68
69
70
71
72
73
74
75 public Menu(@Nonnull final ISkinConfig config, @Nonnull final LinkItem item) {
76 Objects.requireNonNull(item);
77 this.href = config.relativeLink(item.getHref());
78 this.image = item.getImage();
79 this.name = item.getName();
80 this.target = item.getTarget();
81 this.active = config.isActiveLink(this.href);
82 this.inherit = null;
83 }
84
85
86
87
88
89
90
91
92
93 public Menu(@Nonnull final ISkinConfig config, @Nonnull final org.apache.maven.doxia.site.Menu menu) {
94 Objects.requireNonNull(menu);
95 this.href = null;
96 this.image = menu.getImage();
97 this.name = menu.getName();
98 this.target = null;
99 this.inherit = menu.getInherit();
100 this.active = false;
101 final List<org.apache.maven.doxia.site.MenuItem> items = menu.getItems();
102 for (final org.apache.maven.doxia.site.MenuItem menuItem : items) {
103 if (isNullOrEmpty(menu.getName())) {
104 continue;
105 }
106 this.menuItems.add(new MenuItem(config, menuItem));
107 }
108 }
109
110
111
112
113 public List<MenuItem> getMenuItems() {
114 return menuItems;
115 }
116
117
118
119
120 public String getName() {
121 return name;
122 }
123
124
125
126
127 public String getInherit() {
128 return inherit;
129 }
130
131
132
133
134 public boolean isActive() {
135 boolean active = this.active;
136 if (active) {
137 return active;
138 }
139 for (final MenuItem menuItem : menuItems) {
140 active = menuItem.isActive();
141 if (active) {
142 break;
143 }
144 }
145 return active;
146 }
147
148
149
150
151
152
153
154 public String getHref() {
155 return href;
156 }
157
158
159
160
161 public Image getImage() {
162 return image;
163 }
164
165
166
167
168
169 public String getTarget() {
170 return target;
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184
185 public static boolean matches(@Nonnull final String regex, @Nonnull final org.apache.maven.doxia.site.Menu menu) {
186 requireNonNull(regex);
187 requireNonNull(menu);
188 return menu.getRef() != null && menu.getRef().matches(regex)
189 || menu.getName() != null && menu.getName().matches(regex);
190 }
191 }