1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.layout.impl;
18
19 import java.util.Locale;
20 import java.util.Map;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.jetspeed.JetspeedActions;
25 import org.apache.jetspeed.ajax.AjaxAction;
26 import org.apache.jetspeed.ajax.AjaxBuilder;
27 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
28 import org.apache.jetspeed.page.document.NodeNotFoundException;
29 import org.apache.jetspeed.portalsite.Menu;
30 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
31 import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
32 import org.apache.jetspeed.request.RequestContext;
33
34 /***
35 * Get menu action retrieves a menu defined for the addressed page.
36 *
37 * AJAX Parameters:
38 * menu = the name of the menu definition to retrieve
39 *
40 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
41 * @version $Id: $
42 */
43 public class GetMenuAction extends BasePortletAction
44 implements AjaxAction, AjaxBuilder, Constants
45 {
46 protected static final Log log = LogFactory.getLog(GetMenusAction.class);
47
48 public GetMenuAction(String template,
49 String errorTemplate,
50 PortletActionSecurityBehavior securityBehavior)
51 {
52 super(template, errorTemplate, securityBehavior);
53 }
54
55 public boolean run(RequestContext requestContext, Map resultMap)
56 {
57 boolean success = true;
58 String status = "success";
59 try
60 {
61
62 resultMap.put(ACTION, "getmenu");
63
64
65 if (!checkAccess(requestContext, JetspeedActions.VIEW))
66 {
67 success = false;
68 resultMap.put(REASON, "Insufficient access to get menu");
69 return success;
70 }
71
72
73 String menuName = getActionParameter(requestContext, MENU_NAME);
74 if (menuName == null)
75 {
76 success = false;
77 resultMap.put(REASON, "Missing required '" + MENU_NAME + "' parameter");
78 return success;
79 }
80
81
82 PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
83 if (siteRequestContext == null)
84 {
85 success = false;
86 resultMap.put(REASON, "Missing portal site request context from ProfilerValve");
87 return success;
88 }
89
90
91 Locale locale = requestContext.getLocale();
92
93
94 Menu menuDefinition = null;
95 try
96 {
97 menuDefinition = siteRequestContext.getMenu(menuName);
98 }
99 catch (NodeNotFoundException nnfe)
100 {
101 }
102 if (menuDefinition == null)
103 {
104 success = false;
105 resultMap.put(REASON, "Unable to lookup specified menu for page");
106 return success;
107 }
108
109
110 resultMap.put(MENU, menuDefinition);
111 resultMap.put(MENU_CONTEXT, siteRequestContext);
112 resultMap.put(MENU_LOCALE, locale);
113 resultMap.put(STATUS, status);
114 }
115 catch (Exception e)
116 {
117 log.error("Exception while getting page menus info", e);
118 success = false;
119 }
120
121 return success;
122 }
123 }