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