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 javax.annotation.Nonnull;
22  
23  import java.util.List;
24  import java.util.Objects;
25  
26  import com.google.common.collect.Lists;
27  
28  import org.apache.maven.doxia.site.Image;
29  import org.devacfr.maven.skins.reflow.ISkinConfig;
30  
31  /**
32   * @author Christophe Friederich
33   * @since 2.0
34   */
35  public class MenuItem {
36  
37      /** */
38      private final String name;
39  
40  
41  
42      /** */
43      private final String href;
44  
45      /** */
46      private final Image image;
47  
48  
49      /** */
50      private final String target;
51  
52  
53      /** **/
54      private final String inherit;
55  
56      /** */
57      private final boolean active;
58  
59      /** */
60      private final List<MenuItem> menuItems = Lists.newArrayList();
61  
62      /**
63       * Initialize with {@link org.apache.maven.doxia.site.MenuItem}.
64       *
65       * @param config
66       *            a config (can <b>not</b> be {@code null}).
67       * @param item
68       *            item menu used to.
69       */
70      public MenuItem(@Nonnull final ISkinConfig config, final org.apache.maven.doxia.site.MenuItem item) {
71          Objects.requireNonNull(item);;
72          this.href = config.relativeLink(item.getHref());
73          this.image = item.getImage();
74          this.name = item.getName();
75          this.target = item.getTarget();
76          this.active = config.isActiveLink(this.href);
77          this.inherit = null;
78          recurciveAddItem(config, this.menuItems, item.getItems());
79      }
80  
81      /**
82       * recurcive
83       */
84      private void recurciveAddItem(final ISkinConfig config,
85          final List<MenuItem> menuItems,
86          final List<org.apache.maven.doxia.site.MenuItem> origMenuItems) {
87          if (origMenuItems == null) {
88              return;
89          }
90          for (final org.apache.maven.doxia.site.MenuItem menuItem : origMenuItems) {
91              menuItems.add(new MenuItem(config, menuItem));
92          }
93      }
94  
95      /**
96       * @return the name
97       */
98      public String getName() {
99          return name;
100     }
101 
102     /**
103      * @return the menuItems
104      */
105     public List<MenuItem> getMenuItems() {
106         return menuItems;
107     }
108 
109 
110 
111     /**
112      * @return the inherit
113      */
114     public String getInherit() {
115         return inherit;
116     }
117 
118     /**
119      * @return the active
120      */
121     public boolean isActive() {
122         boolean active = this.active;
123         if (active) {
124             return active;
125         }
126         for (final MenuItem menuItem : menuItems) {
127             active = menuItem.isActive();
128             if (active) {
129                 break;
130             }
131         }
132         return active;
133     }
134 
135 
136 
137 
138 
139     /**
140      * @return the href
141      */
142     public String getHref() {
143         return href;
144     }
145 
146     /**
147      * @return the image
148      */
149     public Image getImage() {
150         return image;
151     }
152 
153     /**
154      * @return the target
155      */
156     public String getTarget() {
157         return target;
158     }
159 
160 
161 
162 }