Coverage report

  %line %branch
org.apache.jetspeed.layout.impl.BaseUserAction
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.Iterator;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 import org.apache.jetspeed.ajax.AJAXException;
 26  
 import org.apache.jetspeed.ajax.AjaxAction;
 27  
 import org.apache.jetspeed.ajax.AjaxBuilder;
 28  
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
 29  
 import org.apache.jetspeed.om.page.Fragment;
 30  
 import org.apache.jetspeed.om.page.Page;
 31  
 import org.apache.jetspeed.page.PageManager;
 32  
 import org.apache.jetspeed.request.RequestContext;
 33  
 import org.apache.jetspeed.security.UserManager;
 34  
 
 35  
 /**
 36  
  * Abstract portlet placement action
 37  
  *
 38  
  * @author <a>David Gurney</a>
 39  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 40  
  * @author <a href="mailto:mikko.wuokko@evtek.fi">Mikko Wuokko</a>
 41  
  * @version $Id: $
 42  
  */
 43  
 public abstract class BaseUserAction 
 44  
     implements AjaxAction, AjaxBuilder, Constants 
 45  
 {
 46  0
     protected Log log = LogFactory.getLog(BaseUserAction.class);    
 47  0
 	protected String template = null;
 48  0
     protected UserManager userManager = null;
 49  0
     protected String errorTemplate = null;
 50  
     protected RolesSecurityBehavior securityBehavior;
 51  
     
 52  
     public BaseUserAction(String template, 
 53  
                              String errorTemplate, 
 54  
                              RolesSecurityBehavior securityBehavior)
 55  0
     {
 56  0
         this.template = template;
 57  0
         this.errorTemplate = errorTemplate;
 58  0
         this.securityBehavior = securityBehavior;
 59  0
     }
 60  
 
 61  
     public BaseUserAction(String template, 
 62  
             String errorTemplate, 
 63  
             UserManager userManager)
 64  0
     {
 65  0
         this.template = template;
 66  0
         this.errorTemplate = errorTemplate;
 67  0
         this.userManager = userManager;
 68  0
         this.securityBehavior = null;
 69  0
     }
 70  
     
 71  
     public BaseUserAction(String template, 
 72  
                              String errorTemplate, 
 73  
                              UserManager userManager,
 74  
                              RolesSecurityBehavior securityBehavior)
 75  
     {
 76  0
         this(template, errorTemplate, securityBehavior);
 77  0
         this.userManager = userManager;
 78  0
     }
 79  
 
 80  
     public boolean buildContext(RequestContext requestContext, Map responseContext)
 81  
     {
 82  0
         return true;
 83  
     }
 84  
 
 85  
     public boolean buildErrorContext(RequestContext requestContext,
 86  
             Map responseContext) 
 87  
     {
 88  0
         responseContext.put(STATUS, "failure");
 89  
 
 90  
         // Check for the case where we don't know basic information
 91  0
         if (responseContext.get(ACTION) == null)
 92  
         {
 93  0
             responseContext.put(ACTION, "unknown");
 94  
         }
 95  
 
 96  0
         if (responseContext.get(PORTLETID) == null)
 97  
         {
 98  0
             responseContext.put(PORTLETID, "unknown");
 99  
         }
 100  
 
 101  0
         return true;
 102  
     }
 103  
 
 104  
     public String getErrorTemplate()
 105  
     {
 106  0
         return errorTemplate;
 107  
     }
 108  
 
 109  
     public String getTemplate()
 110  
     {
 111  0
         return template;
 112  
     }
 113  
 
 114  
     public boolean checkAccess(RequestContext context, String action)
 115  
     {
 116  0
         boolean access = true;
 117  0
         if (null != securityBehavior)
 118  
         {
 119  0
             access = securityBehavior.checkAccess(context, action);
 120  
         }
 121  0
         return access;
 122  
     }
 123  
 
 124  
     public boolean createNewPageOnEdit(RequestContext context)
 125  
     {
 126  0
         return securityBehavior.createNewPageOnEdit(context);        
 127  
     }
 128  
         
 129  
     // TODO: support nested fragments
 130  
     public Fragment getFragmentIdFromLocation(int row, class="keyword">int column, Page page)
 131  
     {
 132  0
         Fragment root = page.getRootFragment();
 133  0
         Iterator fragments = root.getFragments().iterator();
 134  0
         while (fragments.hasNext())
 135  
         {
 136  0
             Fragment fragment = (Fragment)fragments.next();
 137  0
             if (fragment.getLayoutColumn() == column &&
 138  
                 fragment.getLayoutRow() == row)
 139  
             {
 140  0
                 return fragment;
 141  
             }
 142  0
         }
 143  0
         return null;
 144  
     }
 145  
     
 146  
     public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
 147  
     {
 148  0
         return run(requestContext, resultMap);
 149  
     }
 150  
     
 151  
     public String getActionParameter(RequestContext requestContext, String name)
 152  
     {
 153  0
         String parameter = requestContext.getRequestParameter(name);
 154  0
         if (parameter == null)
 155  
         {
 156  0
             Object o = requestContext.getAttribute(name);
 157  0
             if (o != null)
 158  
             {
 159  0
                 if (o instanceof String)
 160  0
                     return (String)o;
 161  
             }
 162  
         }
 163  0
         return parameter;
 164  
     }
 165  
     
 166  
     public Fragment getParentFragmentById(String id, Fragment root)
 167  
     {
 168  0
         if ( id == null )
 169  
         {
 170  0
             return null;
 171  
         }
 172  0
         return searchForParentFragmentById( id, root );
 173  
     }
 174  
     
 175  
     protected Fragment searchForParentFragmentById( String id, Fragment parent )
 176  
     {   
 177  
         // find fragment by id, tracking fragment parent
 178  0
         Fragment matchedParent = null;
 179  0
         if( parent != null ) 
 180  
         {
 181  
             // process the children
 182  0
             List children = parent.getFragments();
 183  0
             for( int i = 0, cSize = children.size() ; i < cSize ; i++) 
 184  
             {
 185  0
                 Fragment childFrag = (Fragment)children.get( i );
 186  0
                 if ( childFrag != null ) 
 187  
                 {
 188  0
                     if ( id.equals( childFrag.getId() ) )
 189  
                     {
 190  0
                         matchedParent = parent;
 191  0
                         break;
 192  
                     }
 193  
                     else
 194  
                     {
 195  0
                         matchedParent = searchForParentFragmentById( id, childFrag );
 196  0
                         if ( matchedParent != null )
 197  
                         {
 198  0
                             break;
 199  
                         }
 200  
                     }
 201  
                 }
 202  
             }
 203  
         }
 204  0
         return matchedParent;
 205  
     }
 206  
     
 207  
        
 208  
     /**
 209  
      * Helper method to determine if a parameter is true. Prevents
 210  
      * accidental NullPointerExceptions when comparing or or using
 211  
      * the parameter value.
 212  
      * @param parameter The value to be determined as boolean true or false.
 213  
      * @return boolean true or false according to the @param value.
 214  
      */
 215  
     public boolean isTrue(String parameter)
 216  
     {
 217  0
     	boolean isTrue = false;
 218  0
     	if(parameter != null)
 219  
     	{
 220  0
     		if(parameter.equalsIgnoreCase("true"))
 221  
     		{
 222  0
     			isTrue = true;
 223  
     		}   			
 224  
     	}
 225  0
     	return isTrue;
 226  
     }
 227  
     
 228  
 }

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