Coverage report

  %line %branch
org.apache.jetspeed.layout.impl.GetMenuAction
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * 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 and
 15  
  * limitations under the License.
 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  0
     protected static final Log log = LogFactory.getLog(GetMenusAction.class);
 47  
     
 48  
     public GetMenuAction(String template,
 49  
                          String errorTemplate,
 50  
                          PortletActionSecurityBehavior securityBehavior)
 51  
     {
 52  0
         super(template, errorTemplate, securityBehavior);
 53  0
     }
 54  
 
 55  
     public boolean run(RequestContext requestContext, Map resultMap)
 56  
     {
 57  0
         boolean success = true;
 58  0
         String status = "success";
 59  
         try
 60  
         {
 61  
             // generate action result
 62  0
             resultMap.put(ACTION, "getmenu");
 63  
 
 64  
             // check permission to use ajax api
 65  0
             if (!checkAccess(requestContext, JetspeedActions.VIEW))
 66  
             {
 67  0
                 success = false;
 68  0
                 resultMap.put(REASON, "Insufficient access to get menu");
 69  0
                 return success;
 70  
             }
 71  
 
 72  
             // get action parameter
 73  0
             String menuName = getActionParameter(requestContext, MENU_NAME);
 74  0
             if (menuName == null)
 75  
             {
 76  0
                 success = false;
 77  0
                 resultMap.put(REASON, "Missing required '" + MENU_NAME + "' parameter");
 78  0
                 return success;
 79  
             }
 80  
 
 81  
             // get request context
 82  0
             PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
 83  0
             if (siteRequestContext == null)
 84  
             {
 85  0
                 success = false;
 86  0
                 resultMap.put(REASON, "Missing portal site request context from ProfilerValve");
 87  0
                 return success;
 88  
             }
 89  
 
 90  
             // get request locale
 91  0
             Locale locale = requestContext.getLocale();
 92  
 
 93  
             // get menu definition
 94  0
             Menu menuDefinition = null;
 95  
             try
 96  
             {
 97  0
                 menuDefinition = siteRequestContext.getMenu(menuName);
 98  
             }
 99  0
             catch (NodeNotFoundException nnfe)
 100  
             {
 101  0
             }
 102  0
             if (menuDefinition == null)
 103  
             {
 104  0
                 success = false;
 105  0
                 resultMap.put(REASON, "Unable to lookup specified menu for page");
 106  0
                 return success;
 107  
             }
 108  
 
 109  
             // return menu definition action results
 110  0
             resultMap.put(MENU, menuDefinition);
 111  0
             resultMap.put(MENU_CONTEXT, siteRequestContext);
 112  0
             resultMap.put(MENU_LOCALE, locale);
 113  0
             resultMap.put(STATUS, status);
 114  
         }
 115  0
         catch (Exception e)
 116  
         {
 117  0
             log.error("Exception while getting page menus info", e);
 118  0
             success = false;
 119  0
         }
 120  
 
 121  0
         return success;
 122  
 	}
 123  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.