1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.layout.impl;
1819import java.util.Locale;
20import java.util.Map;
2122import org.apache.commons.logging.Log;
23import org.apache.commons.logging.LogFactory;
24import org.apache.jetspeed.JetspeedActions;
25import org.apache.jetspeed.ajax.AjaxAction;
26import org.apache.jetspeed.ajax.AjaxBuilder;
27import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
28import org.apache.jetspeed.page.document.NodeNotFoundException;
29import org.apache.jetspeed.portalsite.Menu;
30import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
31import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
32import org.apache.jetspeed.request.RequestContext;
3334/***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 */43publicclassGetMenuActionextendsBasePortletAction44 implements AjaxAction, AjaxBuilder, Constants45 {
46protectedstaticfinal Log log = LogFactory.getLog(GetMenusAction.class);
4748publicGetMenuAction(String template,
49 String errorTemplate,
50 PortletActionSecurityBehavior securityBehavior)
51 {
52super(template, errorTemplate, securityBehavior);
53 }
5455publicboolean run(RequestContext requestContext, Map resultMap)
56 {
57boolean success = true;
58 String status = "success";
59try60 {
61// generate action result62 resultMap.put(ACTION, "getmenu");
6364// check permission to use ajax api65if (!checkAccess(requestContext, JetspeedActions.VIEW))
66 {
67 success = false;
68 resultMap.put(REASON, "Insufficient access to get menu");
69return success;
70 }
7172// get action parameter73 String menuName = getActionParameter(requestContext, MENU_NAME);
74if (menuName == null)
75 {
76 success = false;
77 resultMap.put(REASON, "Missing required '" + MENU_NAME + "' parameter");
78return success;
79 }
8081// get request context82 PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
83if (siteRequestContext == null)
84 {
85 success = false;
86 resultMap.put(REASON, "Missing portal site request context from ProfilerValve");
87return success;
88 }
8990// get request locale91 Locale locale = requestContext.getLocale();
9293// get menu definition94 Menu menuDefinition = null;
95try96 {
97 menuDefinition = siteRequestContext.getMenu(menuName);
98 }
99catch (NodeNotFoundException nnfe)
100 {
101 }
102if (menuDefinition == null)
103 {
104 success = false;
105 resultMap.put(REASON, "Unable to lookup specified menu for page");
106return success;
107 }
108109// return menu definition action results110 resultMap.put(MENU, menuDefinition);
111 resultMap.put(MENU_CONTEXT, siteRequestContext);
112 resultMap.put(MENU_LOCALE, locale);
113 resultMap.put(STATUS, status);
114 }
115catch (Exception e)
116 {
117 log.error("Exception while getting page menus info", e);
118 success = false;
119 }
120121return success;
122 }
123 }