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  import org.devacfr.maven.skins.reflow.ISkinConfig;
28  
29  /**
30   * @author Christophe Friederich
31   * @since 2.0
32   */
33  public class MenuItem {
34  
35      /** */
36      private final String name;
37  
38      /** */
39      private final String description;
40  
41      /** */
42      private final String alt;
43  
44      /** */
45      private final String border;
46  
47      /** */
48      private final String height;
49  
50      /** */
51      private final String width;
52  
53      /** */
54      private final String href;
55  
56      /** */
57      private final String image;
58  
59      /** */
60      private final String position;
61  
62      /** */
63      private final String target;
64  
65      /** */
66      private final String title;
67  
68      /** **/
69      private final String inherit;
70  
71      /** */
72      private final boolean active;
73  
74      /** */
75      private final List<MenuItem> menuItems = Lists.newArrayList();
76  
77      /**
78       * Initialize with {@link org.apache.maven.doxia.site.MenuItem}.
79       *
80       * @param config
81       *            a config (can <b>not</b> be {@code null}).
82       * @param item
83       *            item menu used to.
84       */
85      public MenuItem(@Nonnull final ISkinConfig config, final org.apache.maven.doxia.site.MenuItem item) {
86          Objects.requireNonNull(item);
87          this.alt = item.getAlt();
88          this.description = item.getDescription();
89          this.border = item.getBorder();
90          this.height = item.getHeight();
91          this.width = item.getWidth();
92          this.href = config.relativeLink(item.getHref());
93          this.image = item.getImg();
94          this.name = item.getName();
95          this.position = item.getPosition();
96          this.target = item.getTarget();
97          this.title = item.getTitle();
98          this.active = config.isActiveLink(this.href);
99          this.inherit = null;
100         recurciveAddItem(config, this.menuItems, item.getItems());
101     }
102 
103     /**
104      * recurcive
105      */
106     private void recurciveAddItem(final ISkinConfig config,
107         final List<MenuItem> menuItems,
108         final List<org.apache.maven.doxia.site.MenuItem> origMenuItems) {
109         if (origMenuItems == null) {
110             return;
111         }
112         for (final org.apache.maven.doxia.site.MenuItem menuItem : origMenuItems) {
113             menuItems.add(new MenuItem(config, menuItem));
114         }
115     }
116 
117     /**
118      * @return the name
119      */
120     public String getName() {
121         return name;
122     }
123 
124     /**
125      * @return the menuItems
126      */
127     public List<MenuItem> getMenuItems() {
128         return menuItems;
129     }
130 
131     /**
132      * @return the description
133      */
134     public String getDescription() {
135         return description;
136     }
137 
138     /**
139      * @return the inherit
140      */
141     public String getInherit() {
142         return inherit;
143     }
144 
145     /**
146      * @return the active
147      */
148     public boolean isActive() {
149         boolean active = this.active;
150         if (active) {
151             return active;
152         }
153         for (final MenuItem menuItem : menuItems) {
154             active = menuItem.isActive();
155             if (active) {
156                 break;
157             }
158         }
159         return active;
160     }
161 
162     /**
163      * @return the alt
164      */
165     public String getAlt() {
166         return alt;
167     }
168 
169     /**
170      * @return the border
171      */
172     public String getBorder() {
173         return border;
174     }
175 
176     /**
177      * @return the height
178      */
179     public String getHeight() {
180         return height;
181     }
182 
183     /**
184      * @return the href
185      */
186     public String getHref() {
187         return href;
188     }
189 
190     /**
191      * @return the image
192      */
193     public String getImage() {
194         return image;
195     }
196 
197     /**
198      * @return the position
199      */
200     public String getPosition() {
201         return position;
202     }
203 
204     /**
205      * @return the target
206      */
207     public String getTarget() {
208         return target;
209     }
210 
211     /**
212      * @return the title
213      */
214     public String getTitle() {
215         return title;
216     }
217 
218     /**
219      * @return the width
220      */
221     public String getWidth() {
222         return width;
223     }
224 }