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