Coverage Report - org.kuali.rice.krad.web.struts.action.KualiMultipartRequestHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiMultipartRequestHandler
0%
0/25
0%
0/12
2.2
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krad.web.struts.action;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 import org.apache.struts.config.ModuleConfig;
 22  
 import org.apache.struts.upload.CommonsMultipartRequestHandler;
 23  
 
 24  
 /**
 25  
  * Subclass of the MultipartRequestHandler used by Struts.  This one allows the maximum upload size to be set
 26  
  * by the application rather than by an init parameter. 
 27  
  * 
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  *
 30  
  */
 31  0
 public class KualiMultipartRequestHandler extends CommonsMultipartRequestHandler {
 32  0
     private static final Logger LOG = Logger.getLogger(KualiMultipartRequestHandler.class);
 33  
 
 34  
     private String sizeMax;
 35  
     
 36  
     /**
 37  
      * Returns the maximum allowable size, in bytes, of an uploaded file. The
 38  
      * value is obtained from the current module's controller configuration.
 39  
      *
 40  
      * @param mc The current module's configuration.
 41  
      *
 42  
      * @return The maximum allowable file size, in bytes.
 43  
      */
 44  
     public long getSizeMax(ModuleConfig mc) {
 45  0
         return convertSizeToBytes( sizeMax, super.getSizeMax(mc) );
 46  
     }
 47  
 
 48  
     public String getSizeMaxString() {
 49  0
         return sizeMax;
 50  
     }    
 51  
 
 52  
     public void setSizeMax( String sizeString ) {
 53  0
             this.sizeMax = sizeString;
 54  0
     }
 55  
     
 56  
 //    public long convertSizeToBytes(String sizeString, long defaultSize) {
 57  
 //        return super.convertSizeToBytes(sizeString, defaultSize);
 58  
 //    }
 59  
     
 60  
     /**
 61  
      * Sets the max size string to the item in the list that represents the largest size.
 62  
      */
 63  
     public void setMaxUploadSizeToMaxOfList( List<String> sizes ) {
 64  0
         long maxSize = 0L;
 65  0
         for ( String size : sizes ) {
 66  0
             long currSize = convertSizeToBytes(size, 0L);
 67  0
             if ( currSize == 0L ) {
 68  0
                 LOG.warn( "Unable to parse max size (" + size + ").  Ignoring." );
 69  
             }
 70  0
             if ( currSize > maxSize ) {
 71  0
                 maxSize = currSize;
 72  0
                 sizeMax = size;
 73  
             }
 74  0
         }
 75  0
     }
 76  
     
 77  
     public long calculateMaxUploadSizeToMaxOfList( List<String> sizes ) {
 78  0
             long maxSize = 0L;
 79  0
             for ( String size : sizes ) {
 80  0
                 long currSize = convertSizeToBytes(size, 0L);
 81  0
                 if ( currSize == 0L ) {
 82  0
                     LOG.warn( "Unable to parse max size (" + size + ").  Ignoring." );
 83  
                 }
 84  0
                 if ( currSize > maxSize ) {
 85  0
                     maxSize = currSize;                    
 86  
                 }
 87  0
             }
 88  0
             return maxSize;
 89  
     }
 90  
     
 91  
 }