martinc 2003/02/06 23:00:49 Modified: conf/share struts-config_1_1.dtd src/share/org/apache/struts/config ControllerConfig.java src/share/org/apache/struts/upload CommonsMultipartRequestHandler.java Log: Allow configuration of the size threshold below which uploads will be saved in memory, and above which they will be saved to some alternate storage medium, typically disk. Revision Changes Path 1.36 +10 -1 jakarta-struts/conf/share/struts-config_1_1.dtd Index: struts-config_1_1.dtd =================================================================== RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- struts-config_1_1.dtd 28 Jan 2003 19:30:23 -0000 1.35 +++ struts-config_1_1.dtd 7 Feb 2003 07:00:49 -0000 1.36 @@ -515,6 +515,14 @@ megabytes, or gigabytes, respectively. ["250M"] + memFileSize The maximum size (in bytes) of a file whose contents will + be retained in memory after uploading. Files larger than + this threshold will be written to some alternative storage + medium, typically a hard disk. Can be expressed as a number + followed by a "K", "M", or "G", which are interpreted to + mean kilobytes, megabytes, or gigabytes, respectively. + ["256K"] + multipartClass The fully qualified Java class name of the multipart request handler class to be used with this module. ["org.apache.struts.upload.CommonsMultipartRequestHandler"] @@ -555,6 +563,7 @@ <!ATTLIST controller inputForward %Boolean; #IMPLIED> <!ATTLIST controller locale %Boolean; #IMPLIED> <!ATTLIST controller maxFileSize CDATA #IMPLIED> +<!ATTLIST controller memFileSize CDATA #IMPLIED> <!ATTLIST controller multipartClass %ClassName; #IMPLIED> <!ATTLIST controller nocache %Boolean; #IMPLIED> <!ATTLIST controller pagePattern CDATA #IMPLIED> 1.13 +26 -5 jakarta-struts/src/share/org/apache/struts/config/ControllerConfig.java Index: ControllerConfig.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ControllerConfig.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ControllerConfig.java 28 Jan 2003 19:30:24 -0000 1.12 +++ ControllerConfig.java 7 Feb 2003 07:00:49 -0000 1.13 @@ -231,6 +231,23 @@ /** + * The maximum file size to retain in memory. + */ + protected String memFileSize = "256K"; + + public String getMemFileSize() { + return (this.memFileSize); + } + + public void setMemFileSize(String memFileSize) { + if (configured) { + throw new IllegalStateException("Configuration is frozen"); + } + this.memFileSize = memFileSize; + } + + + /** * The fully qualified Java class name of the MultipartRequestHandler * class to be used. */ @@ -369,8 +386,12 @@ sb.append(",locale="); sb.append(this.locale); if (this.maxFileSize != null) { - sb.append(",maxFileSzie="); + sb.append(",maxFileSize="); sb.append(this.maxFileSize); + } + if (this.memFileSize != null) { + sb.append(",memFileSize="); + sb.append(this.memFileSize); } sb.append(",multipartClass="); sb.append(this.multipartClass); 1.7 +42 -23 jakarta-struts/src/share/org/apache/struts/upload/CommonsMultipartRequestHandler.java Index: CommonsMultipartRequestHandler.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/upload/CommonsMultipartRequestHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CommonsMultipartRequestHandler.java 9 Nov 2002 04:04:11 -0000 1.6 +++ CommonsMultipartRequestHandler.java 7 Feb 2003 07:00:49 -0000 1.7 @@ -218,7 +218,7 @@ // Set the maximum size before a FileUploadException will be thrown. upload.setSizeMax((int) getSizeMax(ac)); // Set the maximum size that will be stored in memory. - upload.setSizeThreshold(getSizeThreshold(ac)); + upload.setSizeThreshold((int) getSizeThreshold(ac)); // Set the the location for saving data on disk. upload.setRepositoryPath(getRepositoryPath(ac)); @@ -324,8 +324,41 @@ * @return The maximum allowable file size, in bytes. */ protected long getSizeMax(ModuleConfig mc) { + return convertSizeToBytes( + mc.getControllerConfig().getMaxFileSize(), + DEFAULT_SIZE_MAX); + } + + + /** + * Returns the size threshold which determines whether an uploaded file + * will be written to disk or cached in memory. + * + * @param mc The current module's configuration. + * + * @return The size threshold, in bytes. + */ + protected long getSizeThreshold(ModuleConfig mc) { + return convertSizeToBytes( + mc.getControllerConfig().getMemFileSize(), + DEFAULT_SIZE_THRESHOLD); + } - String sizeString = mc.getControllerConfig().getMaxFileSize(); + /** + * Converts a size value from a string representation to its numeric value. + * The string must be of the form nnnm, where nnn is an arbitrary decimal + * value, and m is a multiplier. The multiplier must be one of 'K', 'M' and + * 'G', representing kilobytes, megabytes and gigabytes respectively. + * + * If the size value cannot be converted, for example due to invalid syntax, + * the supplied default is returned instead. + * + * @param sizeString The string representation of the size to be converted. + * @param defaultSize The value to be returned if the string is invalid. + * + * @return The actual size in bytes. + */ + protected long convertSizeToBytes(String sizeString, long defaultSize) { int multiplier = 1; if (sizeString.endsWith("K")) { @@ -343,27 +376,13 @@ try { size = Long.parseLong(sizeString); } catch (NumberFormatException nfe) { - log.warn("Invalid format for maximum file size ('" - + mc.getControllerConfig().getMaxFileSize() - + "'). Using default."); - size = DEFAULT_SIZE_MAX; + log.warn("Invalid format for file size ('" + sizeString + + "'). Using default."); + size = defaultSize; multiplier = 1; } return (size * multiplier); - } - - - /** - * Returns the size threshold which determines whether an uploaded file - * will be written to disk or cached in memory. - * - * @param mc The current module's configuration. - * - * @return The size threshold, in bytes. - */ - protected int getSizeThreshold(ModuleConfig mc) { - return DEFAULT_SIZE_THRESHOLD; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]