1. Project Clover database mar. avr. 16 2024 08:19:06 CEST
  2. Package org.devacfr.maven.skins.reflow.model

File Menu.java

 

Coverage histogram

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

Code metrics

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

Classes

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

Contributing tests

No tests hitting this source file were found.

Source view

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