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
     	if (securityBehavior == null)
 127  0
             return false;
 128  
     	
 129  0
         return securityBehavior.createNewPageOnEdit(context);        
 130  
     }
 131  
         
 132  
     // TODO: support nested fragments
 133  
     public Fragment getFragmentIdFromLocation(int row, class="keyword">int column, Page page)
 134  
     {
 135  0
         Fragment root = page.getRootFragment();
 136  0
         Iterator fragments = root.getFragments().iterator();
 137  0
         while (fragments.hasNext())
 138  
         {
 139  0
             Fragment fragment = (Fragment)fragments.next();
 140  0
             if (fragment.getLayoutColumn() == column &&
 141  
                 fragment.getLayoutRow() == row)
 142  
             {
 143  0
                 return fragment;
 144  
             }
 145  0
         }
 146  0
         return null;
 147  
     }
 148  
     
 149  
     public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
 150  
     {
 151  0
         return run(requestContext, resultMap);
 152  
     }
 153  
     
 154  
     public String getActionParameter(RequestContext requestContext, String name)
 155  
     {
 156  0
         String parameter = requestContext.getRequestParameter(name);
 157  0
         if (parameter == null)
 158  
         {
 159  0
             Object o = requestContext.getAttribute(name);
 160  0
             if (o != null)
 161  
             {
 162  0
                 if (o instanceof String)
 163  0
                     return (String)o;
 164  
             }
 165  
         }
 166  0
         return parameter;
 167  
     }
 168  
     
 169  
     public Fragment getParentFragmentById(String id, Fragment root)
 170  
     {
 171  0
         if ( id == null )
 172  
         {
 173  0
             return null;
 174  
         }
 175  0
         return searchForParentFragmentById( id, root );
 176  
     }
 177  
     
 178  
     protected Fragment searchForParentFragmentById( String id, Fragment parent )
 179  
     {   
 180  
         // find fragment by id, tracking fragment parent
 181  0
         Fragment matchedParent = null;
 182  0
         if( parent != null ) 
 183  
         {
 184  
             // process the children
 185  0
             List children = parent.getFragments();
 186  0
             for( int i = 0, cSize = children.size() ; i < cSize ; i++) 
 187  
             {
 188  0
                 Fragment childFrag = (Fragment)children.get( i );
 189  0
                 if ( childFrag != null ) 
 190  
                 {
 191  0
                     if ( id.equals( childFrag.getId() ) )
 192  
                     {
 193  0
                         matchedParent = parent;
 194  0
                         break;
 195  
                     }
 196  
                     else
 197  
                     {
 198  0
                         matchedParent = searchForParentFragmentById( id, childFrag );
 199  0
                         if ( matchedParent != null )
 200  
                         {
 201  0
                             break;
 202  
                         }
 203  
                     }
 204  
                 }
 205  
             }
 206  
         }
 207  0
         return matchedParent;
 208  
     }
 209  
     
 210  
        
 211  
     /**
 212  
      * Helper method to determine if a parameter is true. Prevents
 213  
      * accidental NullPointerExceptions when comparing or or using
 214  
      * the parameter value.
 215  
      * @param parameter The value to be determined as boolean true or false.
 216  
      * @return boolean true or false according to the @param value.
 217  
      */
 218  
     public boolean isTrue(String parameter)
 219  
     {
 220  0
     	boolean isTrue = false;
 221  0
     	if(parameter != null)
 222  
     	{
 223  0
     		if(parameter.equalsIgnoreCase("true"))
 224  
     		{
 225  0
     			isTrue = true;
 226  
     		}   			
 227  
     	}
 228  0
     	return isTrue;
 229  
     }
 230  
     
 231  
 }

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