1
2
3
4
5
6 package net.sf.navigator.displayer;
7
8 import net.sf.navigator.menu.MenuComponent;
9
10 import javax.servlet.jsp.JspException;
11 import javax.servlet.jsp.PageContext;
12 import java.io.IOException;
13
14
15 /**
16 *
17 * @author ssayles
18 * @version
19 */
20 public class SimpleMenuDisplayer extends MessageResourcesMenuDisplayer {
21
22
23 protected static final String nbsp = NBSP;
24
25
26
27 public void init(PageContext pageContext, MenuDisplayerMapping mapping) {
28 super.init(pageContext, mapping);
29
30 try {
31 out.println(displayStrings.getMessage("smd.style"));
32 } catch (Exception e) {
33 log.error(e.getMessage());
34 }
35 }
36
37 public void display(MenuComponent menu) throws JspException, IOException {
38 if (isAllowed(menu)) {
39 out.println(displayStrings.getMessage("smd.menu.top"));
40 displayComponents(menu, 0);
41 out.println(displayStrings.getMessage("smd.menu.bottom"));
42 }
43 }
44
45 protected void displayComponents(MenuComponent menu, int level)
46 throws JspException, IOException {
47 MenuComponent[] components = menu.getMenuComponents();
48
49 if (components.length > 0) {
50 out.println(displayStrings.getMessage("smd.menu.item.top",
51 getSpace(level) +
52 displayStrings.getMessage("smd.menu.item.image.bullet") +
53 getMessage(menu.getTitle())));
54
55 for (int i = 0; i < components.length; i++) {
56 if (components[i].getMenuComponents().length > 0) {
57 if (isAllowed(components[i])) {
58 displayComponents(components[i], level + 1);
59 }
60 } else {
61 if (isAllowed(components[i])) {
62 out.println(displayStrings.getMessage("smd.menu.item",
63 components[i].getUrl(),
64 super.getMenuTarget(components[i]),
65 super.getMenuToolTip(components[i]),
66 this.getSpace(level + 1) + getImage(components[i]) +
67 this.getMessage(components[i].getTitle())));
68 }
69 }
70 }
71 } else {
72 out.println(displayStrings.getMessage("smd.menu.item",
73 menu.getUrl(), super.getMenuTarget(menu),
74 super.getMenuToolTip(menu),
75 this.getSpace(level) + getImage(menu) +
76 getMessage(menu.getTitle())));
77 }
78 }
79
80 protected String getSpace(int length) {
81 String space = EMPTY;
82
83 for (int i = 0; i < length; i++) {
84 space = space + nbsp + nbsp;
85 }
86
87 return space;
88 }
89
90 protected String getImage(MenuComponent menu) {
91 String imageTag;
92
93 if ((menu.getImage() == null) || (menu.getImage().equals(EMPTY))) {
94 imageTag = EMPTY;
95 } else {
96 imageTag =
97 displayStrings.getMessage("smd.menu.item.image",
98 menu.getImage(), super.getMenuToolTip(menu));
99 }
100
101 return imageTag;
102 }
103 }