Coverage report

  %line %branch
org.apache.jetspeed.layout.impl.GetMenusAction
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  
 import java.util.HashMap;
 22  
 import java.util.Set;
 23  
 import java.util.Iterator;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 import org.apache.jetspeed.JetspeedActions;
 28  
 import org.apache.jetspeed.ajax.AjaxAction;
 29  
 import org.apache.jetspeed.ajax.AjaxBuilder;
 30  
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
 31  
 import org.apache.jetspeed.page.document.NodeNotFoundException;
 32  
 import org.apache.jetspeed.portalsite.Menu;
 33  
 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
 34  
 import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
 35  
 import org.apache.jetspeed.request.RequestContext;
 36  
 
 37  
 /**
 38  
  * Get menus action retrieves all menu names defined for the addressed page.
 39  
  *
 40  
  * AJAX Parameters: 
 41  
  *    none
 42  
  *    
 43  
  * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
 44  
  * @version $Id: $
 45  
  */
 46  
 public class GetMenusAction extends BasePortletAction 
 47  
     implements AjaxAction, AjaxBuilder, Constants
 48  
 {
 49  0
     protected static final Log log = LogFactory.getLog(GetMenusAction.class);
 50  
     
 51  
     public GetMenusAction(String template,
 52  
                           String errorTemplate,
 53  
                           PortletActionSecurityBehavior securityBehavior)
 54  
     {
 55  0
         super(template, errorTemplate, securityBehavior);
 56  0
     }
 57  
 
 58  
     public boolean run(RequestContext requestContext, Map resultMap)
 59  
     {
 60  0
         boolean success = true;
 61  0
         String status = "success";
 62  
         try
 63  
         {
 64  
             // generate action result
 65  0
             resultMap.put(ACTION, "getmenus");
 66  
 
 67  
             // check permission to use ajax api
 68  0
             if (!checkAccess(requestContext, JetspeedActions.VIEW))
 69  
             {
 70  0
                 success = false;
 71  0
                 resultMap.put(REASON, "Insufficient access to get menus");
 72  0
                 return success;
 73  
             }
 74  
 
 75  
             // get request context
 76  0
             PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
 77  0
             if (siteRequestContext == null)
 78  
             {
 79  0
                 success = false;
 80  0
                 resultMap.put(REASON, "Missing portal site request context from ProfilerValve");
 81  0
                 return success;
 82  
             }
 83  
 
 84  
             // get menu names
 85  0
             Set standardMenuNames = siteRequestContext.getStandardMenuNames();
 86  0
             Set customMenuNames = null;
 87  
             try
 88  
             {
 89  0
                 customMenuNames = siteRequestContext.getCustomMenuNames();
 90  
             }
 91  0
             catch (NodeNotFoundException nnfe)
 92  
             {
 93  0
             }
 94  
             
 95  
             // return menu names action results
 96  0
             resultMap.put(STANDARD_MENUS, standardMenuNames);
 97  0
             resultMap.put(CUSTOM_MENUS, customMenuNames);
 98  
             
 99  
             // get action parameter
 100  0
             String includeMenuDefinitions = getActionParameter(requestContext, INCLUDE_MENU_DEFS);
 101  0
             if ( includeMenuDefinitions != null && includeMenuDefinitions.toLowerCase().equals( "true" ) )
 102  
             {
 103  
                 // get request locale
 104  0
                 Locale locale = requestContext.getLocale();
 105  
                 
 106  0
                 HashMap menuDefinitionsMap = new HashMap();
 107  
                 
 108  0
                 StringBuffer failReason = new StringBuffer();
 109  0
                 Iterator menuNamesIter = standardMenuNames.iterator();
 110  0
                 while ( menuNamesIter.hasNext() )
 111  
                 {
 112  0
                     String menuName = (String)menuNamesIter.next();
 113  0
                     Menu menuDefinition = getMenuDefinition( menuName, siteRequestContext, failReason );
 114  0
                     if ( menuDefinition != null )
 115  0
                         menuDefinitionsMap.put( menuName, menuDefinition );
 116  0
                 }
 117  0
                 menuNamesIter = customMenuNames.iterator();
 118  0
                 while ( menuNamesIter.hasNext() )
 119  
                 {
 120  0
                     String menuName = (String)menuNamesIter.next();
 121  0
                     Menu menuDefinition = getMenuDefinition( menuName, siteRequestContext, failReason );
 122  0
                     if ( menuDefinition != null )
 123  0
                         menuDefinitionsMap.put( menuName, menuDefinition );
 124  0
                 }
 125  
                 
 126  0
                 if ( failReason.length() > 0 )
 127  
                 {
 128  0
                     success = false;
 129  0
                     resultMap.put(REASON, failReason.toString() );
 130  0
                     return success;
 131  
                 }
 132  0
                 resultMap.put( INCLUDE_MENU_DEFS, new Boolean( true ) );
 133  0
                 resultMap.put( MENU_DEFINITIONS, menuDefinitionsMap );
 134  0
                 resultMap.put( MENU_CONTEXT, siteRequestContext );
 135  0
                 resultMap.put( MENU_LOCALE, locale );
 136  0
             }
 137  
             else
 138  
             {
 139  0
                 resultMap.put( INCLUDE_MENU_DEFS, new Boolean( false ) );
 140  
             }
 141  0
             resultMap.put(STATUS, status);
 142  
         }
 143  0
         catch (Exception e)
 144  
         {
 145  0
             log.error("Exception while getting page menus info", e);
 146  0
             success = false;
 147  0
         }
 148  
 
 149  0
         return success;
 150  
 	}
 151  
     
 152  
     private Menu getMenuDefinition( String menuName, PortalSiteRequestContext siteRequestContext, StringBuffer failReason )
 153  
     {
 154  
         // get menu definition
 155  0
         Menu menuDefinition = null;
 156  
         try
 157  
         {
 158  0
             menuDefinition = siteRequestContext.getMenu( menuName );
 159  
         }
 160  0
         catch ( NodeNotFoundException nnfe )
 161  
         {
 162  0
         }
 163  0
         if ( menuDefinition == null && failReason != class="keyword">null )
 164  
         {
 165  0
             if ( failReason.length() == 0 )
 166  0
                 failReason.append( "Unable to lookup specified menus: " ).append( menuName );
 167  
             else
 168  0
                 failReason.append( ", " ).append( menuName );
 169  
         }
 170  0
         return menuDefinition;
 171  
     }
 172  
 }

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