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 *
11 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
12 * @version 1.0
13 */
14 public class TabbedMenuDisplayer extends ListMenuDisplayer {
15
16
17
18 public void display(MenuComponent menu) throws JspException, IOException {
19 if (isAllowed(menu)) {
20 displayComponents(menu, 0);
21 }
22 }
23
24 protected void displayComponents(MenuComponent menu, int level)
25 throws JspException, IOException {
26 MenuComponent[] components = menu.getMenuComponents();
27
28 if (components.length > 0) {
29 out.print("\t<li>");
30
31 String menuClass = "submenu";
32
33 if (level >= 1) {
34 menuClass = "deepmenu";
35 }
36
37 if (menu.getUrl() == null) {
38 log.info("The Menu '" + getMessage(menu.getTitle()) +
39 "' does not have a location defined, using first submenu's location");
40 menu.setUrl(components[0].getUrl());
41 }
42
43 out.print(displayStrings.getMessage("tmd.menu.tab",
44 menu.getUrl(), super.getMenuToolTip(menu),
45 getExtra(menu), getMessage(menu.getTitle())));
46
47 for (int i = 0; i < components.length; i++) {
48
49 if (isAllowed(components[i])) {
50 if (components[i].getMenuComponents().length > 0) {
51
52 if (menuClass.equals("submenu")) {
53 out.print("<li>");
54 }
55
56 displayComponents(components[i], level + 1);
57
58 out.println("</ul></li>");
59
60 if (i == (components[i].getMenuComponents().length - 1)) {
61 out.println("</li>");
62 }
63 } else {
64 out.println(displayStrings.getMessage("tmd.menu.item",
65 components[i].getUrl(),
66 super.getMenuToolTip(components[i]),
67 super.getExtra(components[i]),
68 this.getMessage(components[i].getTitle())));
69 }
70 }
71 }
72
73
74 if (menuClass.equals("submenu")) {
75 out.println("\t</ul>");
76 }
77
78 out.print("\t</li>");
79 } else {
80 out.println(displayStrings.getMessage("tmd.menu.item",
81 menu.getUrl(), super.getMenuToolTip(menu),
82 super.getExtra(menu), getMessage(menu.getTitle())));
83 }
84 }
85 }