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.codehaus.plexus.util.xml.Xpp3Dom;
25  import org.devacfr.maven.skins.reflow.ISkinConfig;
26  
27  /**
28   * Represents the header component.
29   *
30   * @author devacfr
31   * @since 2.2
32   */
33  public class Header extends BsComponent {
34  
35    /** */
36    private static final String COMPONENT = "header";
37  
38    private static final List<String> HEADER_TYPES = Lists.newArrayList("jumbotron", "banner", "custom");
39  
40    /** */
41    private boolean enabled = true;
42  
43    /** */
44    private String type;
45  
46    /** */
47    private String content;
48  
49    /**
50     * Default constructor.
51     *
52     * @param config
53     *          a config (can not be {@code null}).
54     */
55    public Header(@Nonnull final ISkinConfig config) {
56      super(config, COMPONENT);
57      requireNonNull(config);
58      this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, null));
59      this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, null));
60      this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null));
61  
62      this.type = config.getAttributeValue(COMPONENT, "type", String.class, HEADER_TYPES.get(0)).toLowerCase();
63      if (!HEADER_TYPES.contains(this.type)) {
64        this.type = HEADER_TYPES.get(0);
65      }
66      this.enabled = config.getAttributeValue(COMPONENT, "enabled", Boolean.class, true);
67  
68      Xpp3Dom component = config.get(COMPONENT);
69      if (component != null) {
70        this.content = component.getValue();
71        if (!Strings.isNullOrEmpty(this.content)) {
72          this.type = HEADER_TYPES.get(2); // enforce the type to custom
73        }
74      }
75    }
76  
77    /**
78     * Gets the indicating whether the header is displayed.
79     *
80     * @return Returns {@code true} whether the header is displayed, otherwise {@code false}.
81     */
82    public boolean isEnabled() {
83      return enabled;
84    }
85  
86    /**
87     * Gets the type of header.
88     *
89     * @return Returns a String representing the type of header.
90     */
91    public String getType() {
92      return type;
93    }
94  
95    /**
96     * @return the content
97     */
98    public String getContent() {
99      return content;
100   }
101 }