1. Project Clover database mar. janv. 20 2026 12:32:22 CET
  2. Package org.devacfr.maven.skins.reflow.model

File Menu.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart5.png
80% of files have more coverage

Code metrics

6
36
10
1
174
81
13
0,36
3,6
10
1,3

Classes

Class Line # Actions
33 36 0% 13 27
0.4807692248,1%
 

Contributing tests

This file is covered by 11 tests. .

Source view

1    /*
2    * Copyright 2012-2025 Christophe Friederich
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * @author Christophe Friederich
31    * @since 2.0
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    * Initialize with {@link LinkItem}.
58    *
59    * @param config
60    * a config (can <b>not</b> be {@code null}).
61    * @param item
62    * link item used to.
63    */
 
64  11 toggle public Menu(@Nonnull final ISkinConfig config, @Nonnull final LinkItem item) {
65  11 Objects.requireNonNull(item);
66  11 this.href = config.relativeLink(item.getHref());
67  11 this.image = item.getImage();
68  11 this.name = item.getName();
69  11 this.target = item.getTarget();
70  11 this.active = config.isActiveLink(this.href);
71  11 this.inherit = null;
72    }
73   
74    /**
75    * Initialize with {@link org.apache.maven.doxia.site.Menu}.
76    *
77    * @param config
78    * a config (can <b>not</b> be {@code null}).
79    * @param menu
80    * menu used to.
81    */
 
82  77 toggle public Menu(@Nonnull final ISkinConfig config, @Nonnull final org.apache.maven.doxia.site.Menu menu) {
83  77 Objects.requireNonNull(menu);
84  77 this.href = null;
85  77 this.image = menu.getImage();
86  77 this.name = menu.getName();
87  77 this.target = null;
88  77 this.inherit = menu.getInherit();
89  77 this.active = false;
90  77 final List<org.apache.maven.doxia.site.MenuItem> items = menu.getItems();
91  77 for (final org.apache.maven.doxia.site.MenuItem menuItem : items) {
92  165 if (isNullOrEmpty(menu.getName())) {
93  0 continue;
94    }
95  165 this.menuItems.add(new MenuItem(config, menuItem));
96    }
97    }
98   
99    /**
100    * @return the menuItems
101    */
 
102  0 toggle public List<MenuItem> getMenuItems() {
103  0 return menuItems;
104    }
105   
106    /**
107    * @return the name
108    */
 
109  0 toggle public String getName() {
110  0 return name;
111    }
112   
113    /**
114    * @return the inherit
115    */
 
116  0 toggle public String getInherit() {
117  0 return inherit;
118    }
119   
120    /**
121    * @return the active
122    */
 
123  0 toggle public boolean isActive() {
124  0 boolean active = this.active;
125  0 if (active) {
126  0 return active;
127    }
128  0 for (final MenuItem menuItem : menuItems) {
129  0 active = menuItem.isActive();
130  0 if (active) {
131  0 break;
132    }
133    }
134  0 return active;
135    }
136   
137    /**
138    * @return the href
139    */
 
140  0 toggle public String getHref() {
141  0 return href;
142    }
143   
144    /**
145    * @return the image
146    */
 
147  0 toggle public Image getImage() {
148  0 return image;
149    }
150   
151    /**
152    * @return the target
153    */
 
154  0 toggle public String getTarget() {
155  0 return target;
156    }
157   
158    /**
159    * Gets indicating whether menu by their ref or name, and returns the matching results. The regex is used to check the
160    * match.
161    *
162    * @param regex
163    * regex to use.
164    * @param menu
165    * the menu to check
166    * @return Returns {@code true} whether menu matches with regex.
167    */
 
168  220 toggle public static boolean matches(@Nonnull final String regex, @Nonnull final org.apache.maven.doxia.site.Menu menu) {
169  220 requireNonNull(regex);
170  220 requireNonNull(menu);
171  220 return menu.getRef() != null && menu.getRef().matches(regex)
172    || menu.getName() != null && menu.getName().matches(regex);
173    }
174    }