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
28 import org.apache.maven.doxia.site.Image;
29 import org.devacfr.maven.skins.reflow.ISkinConfig;
30
31
32
33
34
35 public class MenuItem {
36
37
38 private final String name;
39
40
41
42
43 private final String href;
44
45
46 private final Image image;
47
48
49
50 private final String target;
51
52
53
54 private final String inherit;
55
56
57 private final boolean active;
58
59
60 private final List<MenuItem> menuItems = Lists.newArrayList();
61
62
63
64
65
66
67
68
69
70 public MenuItem(@Nonnull final ISkinConfig config, final org.apache.maven.doxia.site.MenuItem item) {
71 Objects.requireNonNull(item);;
72 this.href = config.relativeLink(item.getHref());
73 this.image = item.getImage();
74 this.name = item.getName();
75 this.target = item.getTarget();
76 this.active = config.isActiveLink(this.href);
77 this.inherit = null;
78 recurciveAddItem(config, this.menuItems, item.getItems());
79 }
80
81
82
83
84 private void recurciveAddItem(final ISkinConfig config,
85 final List<MenuItem> menuItems,
86 final List<org.apache.maven.doxia.site.MenuItem> origMenuItems) {
87 if (origMenuItems == null) {
88 return;
89 }
90 for (final org.apache.maven.doxia.site.MenuItem menuItem : origMenuItems) {
91 menuItems.add(new MenuItem(config, menuItem));
92 }
93 }
94
95
96
97
98 public String getName() {
99 return name;
100 }
101
102
103
104
105 public List<MenuItem> getMenuItems() {
106 return menuItems;
107 }
108
109
110
111
112
113
114 public String getInherit() {
115 return inherit;
116 }
117
118
119
120
121 public boolean isActive() {
122 boolean active = this.active;
123 if (active) {
124 return active;
125 }
126 for (final MenuItem menuItem : menuItems) {
127 active = menuItem.isActive();
128 if (active) {
129 break;
130 }
131 }
132 return active;
133 }
134
135
136
137
138
139
140
141
142 public String getHref() {
143 return href;
144 }
145
146
147
148
149 public Image getImage() {
150 return image;
151 }
152
153
154
155
156 public String getTarget() {
157 return target;
158 }
159
160
161
162 }