1 /**
2 * Copyright 2005-2015 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.kns.web.struts.action;
17
18 import org.apache.log4j.Logger;
19 import org.apache.struts.config.ModuleConfig;
20 import org.apache.struts.upload.CommonsMultipartRequestHandler;
21
22 import java.util.List;
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 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
31 */
32 @Deprecated
33 public class KualiMultipartRequestHandler extends CommonsMultipartRequestHandler {
34 private static final Logger LOG = Logger.getLogger(KualiMultipartRequestHandler.class);
35
36 private String sizeMax;
37
38 /**
39 * Returns the maximum allowable size, in bytes, of an uploaded file. The
40 * value is obtained from the current module's controller configuration.
41 *
42 * @param mc The current module's configuration.
43 *
44 * @return The maximum allowable file size, in bytes.
45 */
46 public long getSizeMax(ModuleConfig mc) {
47 return convertSizeToBytes( sizeMax, super.getSizeMax(mc) );
48 }
49
50 public String getSizeMaxString() {
51 return sizeMax;
52 }
53
54 public void setSizeMax( String sizeString ) {
55 this.sizeMax = sizeString;
56 }
57
58 // public long convertSizeToBytes(String sizeString, long defaultSize) {
59 // return super.convertSizeToBytes(sizeString, defaultSize);
60 // }
61
62 /**
63 * Sets the max size string to the item in the list that represents the largest size.
64 */
65 public void setMaxUploadSizeToMaxOfList( List<String> sizes ) {
66 long maxSize = 0L;
67 for ( String size : sizes ) {
68 long currSize = convertSizeToBytes(size, 0L);
69 if ( currSize == 0L ) {
70 LOG.warn( "Unable to parse max size (" + size + "). Ignoring." );
71 }
72 if ( currSize > maxSize ) {
73 maxSize = currSize;
74 sizeMax = size;
75 }
76 }
77 }
78
79 public long calculateMaxUploadSizeToMaxOfList( List<String> sizes ) {
80 long maxSize = 0L;
81 for ( String size : sizes ) {
82 long currSize = convertSizeToBytes(size, 0L);
83 if ( currSize == 0L ) {
84 LOG.warn( "Unable to parse max size (" + size + "). Ignoring." );
85 }
86 if ( currSize > maxSize ) {
87 maxSize = currSize;
88 }
89 }
90 return maxSize;
91 }
92
93 }