1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.templatingkit.navigation;
35
36 import info.magnolia.jcr.util.PropertyUtil;
37 import info.magnolia.objectfactory.Components;
38
39 import javax.jcr.Node;
40 import javax.jcr.RepositoryException;
41
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45
46
47
48
49
50
51
52
53 public class NavigationItem extends SubNavigation implements Link{
54 private static final Logger log = LoggerFactory.getLogger(NavigationItem.class);
55
56 private final Link link;
57
58 public NavigationItem(Node content, SubNavigation parent, int depth, boolean allOpen) {
59 super(content, parent, depth, allOpen);
60 link = Components.newInstance(Link.class, content);
61 }
62
63 public int getLevel(){
64 return getRoot().depth - this.depth;
65 }
66
67 public String getId() throws RepositoryException{
68 return content.getName().toLowerCase();
69 }
70
71 public boolean isVisible(){
72 return !PropertyUtil.getBoolean(content, "hideInNav", false);
73 }
74
75 public boolean isLeaf() throws RepositoryException{
76 return getItems().isEmpty();
77 }
78
79 public boolean isSelected() throws RepositoryException{
80
81 final String selectedPath = getRoot().getSelectedNode().getPath();
82 final String currentHandle = this.content.getPath();
83
84 if (selectedPath.equals(currentHandle)) {
85 return true;
86 } else if (isLeaf()) {
87 return selectedPath.startsWith(this.content.getPath() + "/");
88 } else {
89 return false;
90 }
91 }
92
93 @Override
94 public String getHref() {
95 return this.link.getHref();
96 }
97
98 @Override
99 public String getTitle() {
100 return this.link.getTitle();
101 }
102
103 @Override
104 public String getNavigationTitle() {
105 return this.link.getNavigationTitle();
106 }
107 }