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

File Navbar.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart7.png
60% of files have more coverage

Code metrics

26
59
13
2
242
128
28
0,47
4,54
6,5
2,15

Classes

Class Line # Actions
38 48 0% 23 24
0.703703770,4%
192 11 0% 5 8
0.529411852,9%
 

Contributing tests

This file is covered by 22 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.LinkItem;
26    import org.apache.maven.doxia.site.SiteModel;
27    import org.apache.maven.project.MavenProject;
28    import org.codehaus.plexus.util.xml.Xpp3Dom;
29    import org.devacfr.maven.skins.reflow.ISkinConfig;
30    import org.devacfr.maven.skins.reflow.Xpp3Utils;
31   
32    /**
33    * Represents the navbar component.
34    *
35    * @author devacfr
36    * @since 2.0
37    */
 
38    public class Navbar extends BsComponent {
39   
40    /** */
41    public static final String COMPONENT = "navbar";
42   
43    /** */
44    private String brandName;
45   
46    /** */
47    private String brandHref;
48   
49    /** */
50    private final String filterMenu;
51   
52    /** */
53    private final boolean center;
54   
55    /** */
56    private final String alignMenu;
57   
58    /** */
59    private final ImageBrand image;
60   
61    /** */
62    private final List<Menu> menus = Lists.newArrayList();
63   
64    /** */
65    private final Xpp3Dom additionalMenu;
66   
67    /**
68    * Default constructor.
69    *
70    * @param config
71    * a config (can <b>not</b> be {@code null}).
72    */
 
73  30 toggle public Navbar(@Nonnull final ISkinConfig config) {
74  30 super(config, COMPONENT);
75  30 requireNonNull(config);
76  30 final SiteModel model = requireNonNull(config.getSiteModel());
77  30 final MavenProject project = config.getProject();
78  30 final Xpp3Dom brand = config.get("brand");
79  30 if (brand != null) {
80  11 final Xpp3Dom name = brand.getChild("name");
81  11 if (name != null) {
82  11 brandName = name.getValue();
83    }
84  11 final Xpp3Dom href = brand.getChild("href");
85  11 if (href != null) {
86  11 brandHref = config.relativeLink(href.getValue());
87    }
88    } else {
89  19 brandName = project != null ? project.getName() : null;
90    }
91  30 if (isNullOrEmpty(brandName)) {
92  8 brandName = project != null ? project.getArtifactId() : null;
93    }
94  30 this.center = config.getAttributeValue(COMPONENT, "center", Boolean.class, true);
95  30 this.alignMenu = config.getAttributeValue(COMPONENT, "alignMenu", String.class, "right");
96  30 this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, "light"));
97  30 this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, "light"));
98  30 this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null));
99  30 this.filterMenu = config.getAttributeValue(COMPONENT, "filterMenu", String.class, null);
100  30 Xpp3Dom element = config.get(COMPONENT);
101  30 final Xpp3Dom img = Xpp3Utils.getFirstChild(element, "image", config.getNamespace());
102  30 if (img != null) {
103  11 this.image = new ImageBrand(config, img);
104    } else {
105  19 this.image = null;
106    }
107  30 this.additionalMenu = Xpp3Utils.getFirstChild(element, "additionalMenu", config.getNamespace());
108   
109    // add links
110  30 if (model.getBody() != null && model.getBody().getLinks() != null) {
111  11 final List<LinkItem> items = model.getBody().getLinks();
112  11 for (final LinkItem item : items) {
113  11 this.menus.add(new Menu(config, item));
114    }
115    }
116    // add menus
117  30 if (model.getBody() != null && model.getBody().getMenus() != null) {
118  11 final List<org.apache.maven.doxia.site.Menu> menus = model.getBody().getMenus();
119  11 for (final org.apache.maven.doxia.site.Menu menu : menus) {
120  55 if (isNullOrEmpty(menu.getName())) {
121  0 continue;
122    }
123  55 if (isNullOrEmpty(this.filterMenu)) {
124  0 this.menus.add(new Menu(config, menu));
125  55 } else if (Menu.matches(this.filterMenu, menu)) {
126  22 this.menus.add(new Menu(config, menu));
127    }
128    }
129    }
130    }
131   
132    /**
133    * @return the brandName
134    */
 
135  0 toggle public String getBrandName() {
136  0 return brandName;
137    }
138   
139    /**
140    * @return the brandHref
141    */
 
142  0 toggle public String getBrandHref() {
143  0 return brandHref;
144    }
145   
146    /**
147    * @return the center
148    */
 
149  0 toggle public boolean isCenter() {
150  0 return center;
151    }
152   
153    /**
154    * @return the alignMenu
155    */
 
156  0 toggle public String getAlignMenu() {
157  0 return alignMenu;
158    }
159   
160    /**
161    * @return the image
162    */
 
163  0 toggle public ImageBrand getImage() {
164  0 return image;
165    }
166   
167    /**
168    * @return the filterMenu
169    */
 
170  0 toggle public String getFilterMenu() {
171  0 return filterMenu;
172    }
173   
174    /**
175    * @return the additionalMenu
176    */
 
177  0 toggle public Xpp3Dom getAdditionalMenu() {
178  0 return additionalMenu;
179    }
180   
181    /**
182    * @return the menus
183    */
 
184  0 toggle public List<Menu> getMenus() {
185  0 return menus;
186    }
187   
188    /**
189    * @author devacfr
190    * @since 2.0
191    */
 
192    public static class ImageBrand {
193   
194    /** */
195    private final String src;
196   
197    /** */
198    private final String width;
199   
200    /** */
201    private final String height;
202   
203    /**
204    * @param config
205    * a config (can <b>not</b> be {@code null}).
206    * @param element
207    * the element assiciated to image brand.
208    */
 
209  11 toggle ImageBrand(@Nonnull final ISkinConfig config, @Nonnull final Xpp3Dom element) {
210  11 Objects.requireNonNull(config);
211  11 Objects.requireNonNull(element);
212  11 final String link = config.getAttributeValue(element, "src", String.class, null);
213  11 if (isNullOrEmpty(link)) {
214  0 throw new IllegalArgumentException("the attribute 'href' of image element is required");
215    }
216  11 this.src = config.eval(link, String.class);
217  11 this.width = config.getAttributeValue(element, "width", String.class, "30");
218  11 this.height = config.getAttributeValue(element, "height", String.class, "30");
219    }
220   
221    /**
222    * @return the src
223    */
 
224  0 toggle public String getSrc() {
225  0 return src;
226    }
227   
228    /**
229    * @return the height
230    */
 
231  0 toggle public String getHeight() {
232  0 return height;
233    }
234   
235    /**
236    * @return the width
237    */
 
238  0 toggle public String getWidth() {
239  0 return width;
240    }
241    }
242    }