View Javadoc

1   /*
2    * PermissionsFormMenuDisplayer.java
3    *
4    * Created on April 30, 2002, 12:25 AM
5    */
6   package net.sf.navigator.example;
7   
8   import java.io.IOException;
9   import java.text.MessageFormat;
10  
11  import javax.servlet.jsp.JspException;
12  
13  import net.sf.navigator.displayer.SimpleMenuDisplayer;
14  import net.sf.navigator.menu.MenuComponent;
15  
16  
17  /**
18   *
19   * @author  ssayles
20   */
21  public class PermissionsFormMenuDisplayer extends SimpleMenuDisplayer {
22      //~ Static fields/initializers =============================================
23  
24      private static final MessageFormat inputMessage =
25          new MessageFormat(
26              "<input type=\"checkbox\" name=\"menus\" value=\"{0}\"/>");
27      private static final MessageFormat itemMessage =
28          new MessageFormat(
29              "<tr><td class=\"smd-menu-item\">{0} {1} {2} {3}</td></tr>");
30  
31      //~ Methods ================================================================
32  
33      protected void displayComponents(MenuComponent menu, int level)
34      throws JspException, IOException {
35          String title = getMessage(menu.getTitle());
36          MenuComponent[] components = menu.getMenuComponents();
37  
38          if (components.length > 0) {
39              out.println(displayStrings.getMessage("smd.menu.item.top",
40                      getSpace(level) +
41                      displayStrings.getMessage("smd.menu.item.image.bullet") +
42                      getMenuInput(menu) + getMessage(menu.getTitle())));
43  
44              for (int i = 0; i < components.length; i++) {
45                  if (components[i].getMenuComponents().length > 0) {
46                      displayComponents(components[i], level + 1);
47                  } else {
48                      out.println(getMenuItem(components[i], getSpace(level + 1)));
49                  }
50              }
51          } else {
52              out.println(getMenuItem(menu, ""));
53          }
54      }
55  
56      private String getMenuItem(MenuComponent menu, String space) {
57          return itemMessage.format(new String[] {
58                  space, getMenuInput(menu), getImage(menu),
59                  getMessage(menu.getTitle())
60              });
61      }
62  
63      private String getMenuInput(MenuComponent menu) {
64          return inputMessage.format(new String[] { menu.getName() });
65      }
66  }