View Javadoc
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 java.util.Objects.requireNonNull;
19  
20  import com.google.common.base.Strings;
21  import com.google.common.collect.Lists;
22  import java.util.List;
23  import javax.annotation.Nonnull;
24  import org.apache.maven.doxia.site.SiteModel;
25  import org.codehaus.plexus.util.xml.Xpp3Dom;
26  import org.devacfr.maven.skins.reflow.ISkinConfig;
27  
28  /**
29   * Represents the footer component.
30   *
31   * @author devacfr
32   * @since 2.0
33   */
34  public class Footer extends BsComponent {
35  
36    /** */
37    private static final String COMPONENT = "footer";
38  
39    /** */
40    private final List<Column> columns = Lists.newArrayList();
41  
42    /**
43     * Default constructor.
44     *
45     * @param config
46     *          a config (can not be {@code null}).
47     */
48    public Footer(@Nonnull final ISkinConfig config) {
49      super(config, COMPONENT);
50      requireNonNull(config);
51      final SiteModel model = requireNonNull(config.getSiteModel());
52      this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, "light"));
53      this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, "light"));
54      this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null));
55  
56      final Xpp3Dom bottomNav = config.get("bottomNav");
57  
58      if (model.getBody() != null && model.getBody().getMenus() != null) {
59        final List<org.apache.maven.doxia.site.Menu> menus = model.getBody().getMenus();
60        if (bottomNav != null && bottomNav.getChildren().length > 0) {
61          // foreach columns
62          for (final Xpp3Dom col : bottomNav.getChildren()) {
63            final String regex = col.getValue();
64            if (Strings.isNullOrEmpty(regex)) {
65              continue;
66            }
67            final List<Menu> amenus = Lists.newArrayList();
68            for (final org.apache.maven.doxia.site.Menu menu : menus) {
69              // add in column, if matches with regex
70              if (Menu.matches(regex, menu)) {
71                amenus.add(new Menu(config, menu));
72              }
73            }
74            this.columns.add(new Column(config, amenus));
75          }
76        } else {
77          final List<Menu> amenus = Lists.newArrayList();
78          for (final org.apache.maven.doxia.site.Menu menu : menus) {
79            amenus.add(new Menu(config, menu));
80          }
81          this.columns.add(new Column(config, amenus));
82        }
83      }
84    }
85  
86    /**
87     * @return Returns a list of {@link Column}.
88     */
89    public List<Column> getColumns() {
90      return columns;
91    }
92  
93    /**
94     * @author Christophe Friederich
95     * @since 2.0
96     */
97    public static class Column {
98  
99      /** */
100     private final List<Menu> menus;
101 
102     /**
103      * @param config
104      *          a config (can not be {@code null}).
105      * @param menus
106      *          list of menu.
107      */
108     public Column(@Nonnull final ISkinConfig config, @Nonnull final List<Menu> menus) {
109       requireNonNull(config);
110       requireNonNull(menus);
111       this.menus = menus;
112     }
113 
114     /**
115      * @return Returns a list of {@link Menu}.
116      */
117     public List<Menu> getMenus() {
118       return menus;
119     }
120   }
121 }