Coverage report

  %line %branch
org.apache.jetspeed.layout.impl.RemovePortletAction
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.Map;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.apache.jetspeed.JetspeedActions;
 24  
 import org.apache.jetspeed.ajax.AJAXException;
 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.layout.PortletPlacementContext;
 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.pipeline.PipelineException;
 33  
 import org.apache.jetspeed.request.RequestContext;
 34  
 
 35  
 
 36  
 /**
 37  
  * Remove Portlet portlet placement action
 38  
  * 
 39  
  * AJAX Parameters: 
 40  
  *    id = the fragment id of the portlet to remove
 41  
  *    page = (implied in the URL)
 42  
  *    
 43  
  * @author <a>David Gurney </a>
 44  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 45  
  * @version $Id: $
 46  
  */
 47  
 public class RemovePortletAction 
 48  
     extends BasePortletAction 
 49  
     implements AjaxAction, AjaxBuilder, Constants
 50  
 {
 51  0
     protected static final Log log = LogFactory.getLog(RemovePortletAction.class);
 52  
 
 53  
     public RemovePortletAction(String template, String errorTemplate)
 54  
             throws PipelineException
 55  
     {
 56  0
         this(template, errorTemplate, null, class="keyword">null);
 57  0
     }
 58  
 
 59  
     public RemovePortletAction(String template, 
 60  
                                String errorTemplate, 
 61  
                                PageManager pageManager, 
 62  
                                PortletActionSecurityBehavior securityBehavior)
 63  
     throws PipelineException
 64  
     {
 65  0
         super(template, errorTemplate, pageManager, securityBehavior);
 66  0
     }
 67  
     
 68  
     public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
 69  
     {
 70  0
         return runAction(requestContext, resultMap, true);
 71  
     }    
 72  
     
 73  
     public boolean run(RequestContext requestContext, Map resultMap)
 74  
             throws AJAXException
 75  
     {
 76  0
         return runAction(requestContext, resultMap, false);
 77  
     }
 78  
     
 79  
     public boolean runAction(RequestContext requestContext, Map resultMap, class="keyword">boolean batch)
 80  
     {
 81  0
         boolean success = true;
 82  0
         String status = "success";
 83  
         try
 84  
         {
 85  0
             resultMap.put(ACTION, "remove");
 86  
             // Get the necessary parameters off of the request
 87  0
             String portletId = getActionParameter(requestContext, PORTLETID);
 88  0
             if (portletId == null) 
 89  
             { 
 90  0
                 success = false;
 91  0
                 resultMap.put(REASON, "Portlet ID not provided");
 92  0
                 return success;
 93  
             }
 94  0
             resultMap.put(PORTLETID, portletId);
 95  0
             if (false == checkAccess(requestContext, JetspeedActions.EDIT))
 96  
             {
 97  0
                 Page page = requestContext.getPage();
 98  0
                 Fragment fragment = page.getFragmentById(portletId);
 99  0
                 if (fragment == null)
 100  
                 {
 101  0
                     success = false;
 102  0
                     resultMap.put(REASON, "Fragment not found");
 103  0
                     return success;                    
 104  
                 }
 105  0
                 int column = fragment.getLayoutColumn();
 106  0
                 int row = fragment.getLayoutRow();
 107  0
                 if (!createNewPageOnEdit(requestContext))
 108  
                 {                
 109  0
                     success = false;
 110  0
                     resultMap.put(REASON, "Insufficient access to edit page");
 111  0
                     return success;
 112  
                 }
 113  0
                 status = "refresh";                
 114  
                 // translate old portlet id to new portlet id
 115  0
                 Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
 116  0
                 if (newFragment == null)
 117  
                 {
 118  0
                     success = false;
 119  0
                     resultMap.put(REASON, "Failed to find new fragment");
 120  0
                     return success;                    
 121  
                 }
 122  0
                 portletId = newFragment.getId();
 123  
             }
 124  
             
 125  
             // Use the Portlet Placement Manager to accomplish the removal
 126  0
             PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext);
 127  0
             Fragment fragment = placement.getFragmentById(portletId);
 128  0
             if (fragment == null)
 129  
             {
 130  0
                 success = false;
 131  0
                 resultMap.put(REASON, "Fragment not found");
 132  0
                 return success;                
 133  
             }
 134  0
             placement.remove(fragment);
 135  0
             Page page = placement.syncPageFragments();
 136  0
             page.removeFragmentById(fragment.getId());
 137  0
             if (!batch)
 138  
             {
 139  0
                 if (pageManager != null)
 140  0
                     pageManager.updatePage(page);
 141  
             }
 142  
             // Build the results for the response
 143  0
             resultMap.put(PORTLETID, portletId);            
 144  0
             resultMap.put(STATUS, status);
 145  0
             resultMap.put(OLDCOL, String.valueOf(fragment.getLayoutColumn()));
 146  0
             resultMap.put(OLDROW, String.valueOf(fragment.getLayoutRow()));
 147  
         } 
 148  0
         catch (Exception e)
 149  
         {
 150  
             // Log the exception
 151  0
             log.error("exception while adding a portlet", e);
 152  0
             resultMap.put(REASON, e.toString());
 153  
             // Return a failure indicator
 154  0
             success = false;
 155  0
         }
 156  
 
 157  0
         return success;
 158  
     }
 159  
 }

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