View Javadoc

1   /*
2    * DropDownMenuDisplayer.java
3    *
4    * Created on February 6, 2001, 1:00 PM
5    */
6   package net.sf.navigator.displayer;
7   
8   import net.sf.navigator.menu.MenuComponent;
9   
10  import java.io.IOException;
11  
12  import javax.servlet.jsp.JspException;
13  import javax.servlet.jsp.PageContext;
14  
15  
16  /**
17   *
18   * @author  ssayles
19   * @version
20   */
21  public class DropDownMenuDisplayer extends MessageResourcesMenuDisplayer {
22      //~ Methods ================================================================
23  
24      public void init(PageContext pageContext, MenuDisplayerMapping mapping) {
25          super.init(pageContext, mapping);
26  
27          StringBuffer sb = new StringBuffer();
28  
29          // add the stylesheet
30          sb.append(displayStrings.getMessage("smd.style", "{", "}"));
31          
32          //display the javascript function
33          sb.append(displayStrings.getMessage("dd.js.start"));
34          sb.append(displayStrings.getMessage("dd.js.image.src.expand",
35                  displayStrings.getMessage("dd.image.src.expand")));
36          sb.append(displayStrings.getMessage("dd.js.image.src.expanded",
37                  displayStrings.getMessage("dd.image.src.expanded")));
38          sb.append(displayStrings.getMessage("dd.js.toggle.display", "{", "}"));
39          sb.append(displayStrings.getMessage("dd.js.end"));
40  
41          try {
42              out.print(sb.toString());
43          } catch (Exception e) {}
44      }
45  
46      public void display(MenuComponent menu) throws JspException, IOException {
47          String title = super.getMessage(menu.getTitle());
48          StringBuffer sb = new StringBuffer();
49          String img = EMPTY;
50  
51          if (menu.getImage() != null) {
52              img = displayStrings.getMessage("dd.image", menu.getImage());
53          }
54  
55          MenuComponent[] components = menu.getMenuComponents();
56  
57          sb.append(displayStrings.getMessage("dd.menu.top"));
58  
59          if (components.length > 0) {
60              if (this.isAllowed(menu)) {
61                  sb.append(displayStrings.getMessage("dd.menu.expander",
62                          menu.getName(), menu.getName() + "_img",
63                          displayStrings.getMessage("dd.image.expander",
64                              menu.getName() + "_img",
65                              displayStrings.getMessage("dd.image.src.expand")) +
66                          NBSP + img + title));
67                  displayComponents(menu, sb);
68                  sb.append(displayStrings.getMessage("dd.menu.restore",
69                          menu.getName(), menu.getName() + "_img"));
70              } else {
71                  // the dd.menu.restricted key is missing!
72                  sb.append(displayStrings.getMessage("dd.menu.restricted",
73                          menu.getName(), menu.getName() + "_img",
74                          displayStrings.getMessage("dd.image.expander",
75                              menu.getName() + "_img",
76                              displayStrings.getMessage("dd.image.src.expand")) +
77                          NBSP + img + title));
78              }
79          } else {
80              sb.append(title);
81          }
82  
83          sb.append(displayStrings.getMessage("dd.menu.bottom"));
84          out.println(sb.toString());
85      }
86  
87      private void displayComponents(MenuComponent menu, StringBuffer sb)
88      throws JspException, IOException {
89          String title = null;
90          String name = menu.getName();
91          String href = EMPTY;
92          String img = EMPTY;
93          MenuComponent[] components = menu.getMenuComponents();
94  
95          sb.append(displayStrings.getMessage("dd.menu.item.top", name));
96  
97          for (int i = 0; i < components.length; i++) {
98              title = super.getMessage(components[i].getTitle());
99  
100             if (components[i].getImage() != null) {
101                 img = displayStrings.getMessage("dd.image",
102                         components[i].getImage());
103             } else {
104                 img = EMPTY;
105             }
106 
107             href = components[i].getUrl();
108 
109             sb.append(displayStrings.getMessage("dd.menu.item.row.start"));
110 
111             if (components[i].getMenuComponents().length > 0) {
112                 if (this.isAllowed(components[i])) {
113                     sb.append(displayStrings.getMessage("dd.menu.expander",
114                             components[i].getName(),
115                             components[i].getName() + "_img",
116                             displayStrings.getMessage("dd.image.expander",
117                                 components[i].getName() + "_img",
118                                 displayStrings.getMessage("dd.image.src.expand")) +
119                             NBSP + img + title));
120                     displayComponents(components[i], sb);
121                     sb.append(displayStrings.getMessage("dd.menu.restore",
122                             components[i].getName(),
123                             components[i].getName() + "_img"));
124                 } else {
125                     sb.append(displayStrings.getMessage("dd.menu.restricted",
126                             components[i].getName(),
127                             components[i].getName() + "_img",
128                             displayStrings.getMessage("dd.image.expander",
129                                 components[i].getName() + "_img",
130                                 displayStrings.getMessage("dd.image.src.expand")) +
131                             NBSP + img + title));
132                 }
133             } else {
134                 if (this.isAllowed(components[i])) {
135                     sb.append(displayStrings.getMessage("dd.link.start", href,
136                             super.getMenuTarget(components[i]),
137                             super.getMenuToolTip(components[i])));
138                     sb.append(NBSP);
139                     sb.append(NBSP); //a couple of spaces
140                     sb.append(img);
141                     sb.append(title);
142                     sb.append(displayStrings.getMessage("dd.link.end"));
143                 } else {
144                     sb.append(displayStrings.getMessage("dd.link.restricted",
145                             href, super.getMenuTarget(components[i]),
146                             super.getMenuToolTip(components[i])));
147                 }
148             }
149 
150             sb.append(displayStrings.getMessage("dd.menu.item.row.end"));
151         }
152 
153         sb.append(displayStrings.getMessage("dd.menu.item.bottom"));
154     }
155 }