Coverage report

  %line %branch
org.apache.jetspeed.layout.impl.UpdateFolderAction
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.om.folder.Folder;
 29  
 import org.apache.jetspeed.om.page.Fragment;
 30  
 import org.apache.jetspeed.page.PageManager;
 31  
 import org.apache.jetspeed.page.document.Node;
 32  
 import org.apache.jetspeed.request.RequestContext;
 33  
 
 34  
 /**
 35  
  * Update Folder action -- updates various parts of the PSML folder
 36  
  * 
 37  
  * AJAX Parameters: 
 38  
  *    action = updatefolder
 39  
  *    General methods:
 40  
  *    method = add | remove 
 41  
  *    Info methods:
 42  
  *    | info 
 43  
  *    Meta methods:
 44  
  *    | add-meta | update-meta | remove-meta
 45  
  *    Security methods:
 46  
  *    | add-secref | remove-secref
 47  
  *    
 48  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 49  
  * @version $Id: $
 50  
  */
 51  
 public class UpdateFolderAction 
 52  
     extends BaseSiteUpdateAction 
 53  
     implements AjaxAction, AjaxBuilder, Constants
 54  
 {
 55  0
     protected Log log = LogFactory.getLog(UpdateFolderAction.class);
 56  
 
 57  
     public UpdateFolderAction(String template, 
 58  
                             String errorTemplate, 
 59  
                             PageManager pm,
 60  
                             PortletActionSecurityBehavior securityBehavior)
 61  
                             
 62  
     {
 63  0
         super(template, errorTemplate, pm, securityBehavior); 
 64  0
     }
 65  
     
 66  
     public boolean run(RequestContext requestContext, Map resultMap)
 67  
             throws AJAXException
 68  
     {
 69  0
         boolean success = true;
 70  0
         String status = "success";
 71  
         try
 72  
         {
 73  0
             resultMap.put(ACTION, "updatefolder");
 74  
             // Get the necessary parameters off of the request
 75  0
             String method = getActionParameter(requestContext, "method");
 76  0
             if (method == null) 
 77  
             { 
 78  0
                 throw new RuntimeException("Method not provided"); 
 79  
             }            
 80  0
             resultMap.put("method", method);
 81  0
             if (false == checkAccess(requestContext, JetspeedActions.EDIT))
 82  
             {
 83  0
                 success = false;
 84  0
                 resultMap.put(REASON, "Insufficient access to administer portal permissions");                
 85  0
                 return success;
 86  
             }           
 87  0
             int count = 0;
 88  0
             String path = getActionParameter(requestContext, "path");
 89  0
             if (path == null)
 90  0
                 throw new AJAXException("Missing 'path' parameter");             
 91  0
             Folder folder = null; 
 92  0
             if (!method.equals("add"))
 93  
             {
 94  0
                 folder = pageManager.getFolder(path);
 95  
             }       
 96  
             else
 97  
             {
 98  0
                 if (pageManager.folderExists(path))
 99  
                 {
 100  0
                     success = false;
 101  0
                     resultMap.put(REASON, "Can't create: Folder already exists: " + path);                
 102  0
                     return success;                
 103  
                 }
 104  
             }            
 105  0
             if (method.equals("info"))
 106  
             {
 107  0
                 count = updateInformation(requestContext, resultMap, folder, path);
 108  
             }
 109  0
             else if (method.equals("add-meta"))
 110  
             {
 111  0
                 count = insertMetadata(requestContext, resultMap, folder);
 112  
             }
 113  0
             else if ( method.equals("update-meta"))
 114  
             {
 115  0
                 count = updateMetadata(requestContext, resultMap, folder);
 116  
             }
 117  0
             else if (method.equals("remove-meta"))
 118  
             {
 119  0
                 count = removeMetadata(requestContext, resultMap, folder);
 120  
             }
 121  0
             else if (method.equals("update-secref"))
 122  
             {
 123  0
                 count = updateSecurityReference(requestContext, resultMap, folder);
 124  
             }            
 125  0
             else if (method.equals("add-secref"))
 126  
             {
 127  0
                 count = insertSecurityReference(requestContext, resultMap, folder);
 128  
             }
 129  0
             else if (method.equals("remove-secref"))
 130  
             {
 131  0
                 count = removeSecurityReference(requestContext, resultMap, folder);
 132  
             }
 133  0
             else if (method.equals("remove-secdef"))
 134  
             {
 135  0
                 count = removeSecurityDef(requestContext, resultMap, folder);
 136  
             }                        
 137  0
             else if (method.equals("add"))
 138  
             {
 139  0
                 folder = pageManager.newFolder(path);
 140  0
                 folder.setTitle(getActionParameter(requestContext, "title"));
 141  0
                 String s = getActionParameter(requestContext, "short-title");
 142  0
                 if (!isBlank(s))
 143  0
                     folder.setShortTitle(s);
 144  0
                 count++;                
 145  0
             }
 146  0
             else if (method.equals("copy"))
 147  
             {            	   
 148  0
             	String destination = getActionParameter(requestContext, "destination");
 149  0
             	String name = getActionParameter(requestContext, RESOURCE_NAME);
 150  0
             	destination = destination + Folder.PATH_SEPARATOR + name;
 151  0
             	pageManager.deepCopyFolder(folder,destination,null);
 152  0
             }
 153  0
             else if (method.equals("move"))
 154  
             {            	
 155  0
             	String destination = getActionParameter(requestContext, "destination");
 156  0
             	String name = getActionParameter(requestContext, RESOURCE_NAME);            	
 157  0
             	destination = destination + Folder.PATH_SEPARATOR + name;
 158  0
             	pageManager.deepCopyFolder(folder,destination,null);            	
 159  0
             	pageManager.removeFolder(folder);
 160  0
             }            
 161  0
             else if (method.equals("remove"))
 162  
             {
 163  0
                 pageManager.removeFolder(folder);
 164  
             }                        
 165  
             else
 166  
             {
 167  0
                 success = false;
 168  0
                 resultMap.put(REASON, "Unsupported Site Update method: " + method);                
 169  0
                 return success;                
 170  
             }
 171  0
             if (count > 0)
 172  
             {
 173  0
                 pageManager.updateFolder(folder);                
 174  
             }
 175  0
             resultMap.put("count", Integer.toString(count));
 176  0
             resultMap.put(STATUS, status);
 177  
         } 
 178  0
         catch (Exception e)
 179  
         {
 180  0
             log.error("exception administering Site update", e);
 181  0
             resultMap.put(REASON, e.toString());
 182  0
             success = false;
 183  0
         }
 184  0
         return success;
 185  
     }
 186  
     
 187  
     protected int updateInformation(RequestContext requestContext, Map resultMap, Node node, String path)
 188  
     throws AJAXException    
 189  
     {
 190  0
         int count = 0;
 191  
         try
 192  
         {
 193  0
             Folder folder = (Folder)node;            
 194  0
             String title = getActionParameter(requestContext, "title");
 195  0
             if (isFieldModclass="keyword">ified(title, folder.getTitle()))
 196  0
                 folder.setTitle(title);
 197  0
             String shortTitle = getActionParameter(requestContext, "short-title");
 198  0
             if (isFieldModclass="keyword">ified(shortTitle, folder.getShortTitle()))
 199  0
                 folder.setShortTitle(shortTitle);
 200  0
             String layoutDecorator = getActionParameter(requestContext, "layout-decorator");
 201  0
             if (isFieldModclass="keyword">ified(layoutDecorator, folder.getDefaultDecorator(Fragment.LAYOUT)))
 202  
             {
 203  0
                 if (isBlank(layoutDecorator))
 204  0
                     layoutDecorator = null;                 
 205  0
                 folder.setDefaultDecorator(layoutDecorator, Fragment.LAYOUT);
 206  
             }
 207  0
             String portletDecorator = getActionParameter(requestContext, "portlet-decorator");
 208  0
             if (isFieldModclass="keyword">ified(portletDecorator, folder.getDefaultDecorator(Fragment.PORTLET)))
 209  
             {
 210  0
                 if (isBlank(portletDecorator))
 211  0
                     portletDecorator = null;                 
 212  0
                 folder.setDefaultDecorator(portletDecorator, Fragment.PORTLET);
 213  
             }
 214  0
             String defaultPage = getActionParameter(requestContext, "default-page");
 215  0
             if (isFieldModclass="keyword">ified(defaultPage, folder.getDefaultPage()))
 216  0
                 folder.setDefaultPage(defaultPage);                        
 217  0
             String hidden = getActionParameter(requestContext, "hidden");
 218  0
             if (isBooleanModclass="keyword">ified(hidden, folder.isHidden()))
 219  0
                 folder.setHidden(!folder.isHidden());                                    
 220  0
             count++;
 221  
         }
 222  0
         catch (Exception e)
 223  
         {
 224  0
             throw new AJAXException(e);
 225  0
         }        
 226  0
         return count;
 227  
     }
 228  
     
 229  
 }

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