1 package net.sf.navigator.displayer;
2
3 import net.sf.navigator.menu.MenuComponent;
4
5 import javax.servlet.jsp.JspException;
6 import java.io.IOException;
7
8 /**
9 *
10 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
11 * @version 1.0
12 */
13 public class CSSListMenuDisplayer extends ListMenuDisplayer {
14
15
16 public void display(MenuComponent menu) throws JspException, IOException {
17 if (isAllowed(menu)) {
18 out.println(displayStrings.getMessage("ccslm.menu.top",
19 (hasViewableChildren(menu)) ? " class=\"menubar\"" : ""));
20 displayComponents(menu, 0);
21 out.println(displayStrings.getMessage("lmd.menu.bottom"));
22 }
23 }
24
25 protected void displayComponents(MenuComponent menu, int level)
26 throws JspException, IOException {
27 if (menu.getUrl() == null) {
28
29 menu.setUrl("javascript:void(0)");
30 }
31 MenuComponent[] components = menu.getMenuComponents();
32
33 if (components.length > 0) {
34
35 if (components.length == 0){
36 out.println(displayStrings.getMessage("lmd.menu.item",
37 menu.getUrl(),
38 super.getMenuToolTip(menu),
39 getExtra(menu),
40 this.getMessage(menu.getTitle())));
41 } else {
42 out.println(displayStrings.getMessage("ccslm.menubar.top",
43 menu.getUrl(), getExtra(menu), this.getMessage(menu.getTitle())));
44 if (hasViewableChildren(menu)) {
45 out.println("\t\t<ul>");
46 }
47 }
48
49 for (int i = 0; i < components.length; i++) {
50
51 if (isAllowed(components[i])) {
52 if (components[i].getMenuComponents().length > 0) {
53 if (!hasViewableChildren(components[i])) {
54 out.println("<li>");
55 } else {
56 out.println("<li class=\"menubar\">");
57 }
58
59 displayComponents(components[i], level + 1);
60
61 out.println((hasViewableChildren(components[i]) ? "\t\t</ul>\t</li>\n" : "\t</li>\n"));
62
63 } else {
64 out.println(displayStrings.getMessage("lmd.menu.item",
65 components[i].getUrl(),
66 super.getMenuToolTip(components[i]),
67 getExtra(components[i]),
68 this.getMessage(components[i].getTitle())));
69 }
70 }
71 }
72
73
74 if (level == 0 && hasViewableChildren(menu)) {
75 out.println("</ul>");
76 }
77 } else {
78 if (menu.getParent() == null) {
79 out.println(displayStrings.getMessage("lmd.menu.standalone",
80 menu.getUrl(),
81 super.getMenuToolTip(menu),
82 getExtra(menu),
83 getMessage(menu.getTitle())));
84 } else {
85 out.println(displayStrings.getMessage("lmd.menu.item",
86 menu.getUrl(),
87 super.getMenuToolTip(menu),
88 getExtra(menu),
89 getMessage(menu.getTitle())));
90 }
91 }
92 }
93
94 private boolean hasViewableChildren(MenuComponent menu) {
95 for (int i = 0; i < menu.getMenuComponents().length; i++) {
96 if (isAllowed(menu.getMenuComponents()[i])) {
97 return true;
98 }
99 }
100 return false;
101 }
102 }