Index: lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java,v diff -u -r1.9 -r1.10 --- lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java 14 Dec 2006 04:13:32 -0000 1.9 +++ lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java 21 Feb 2012 10:04:47 -0000 1.10 @@ -126,35 +126,37 @@ return validateFileSize(fileSize, largeFile,errorKey, errors); } - - private static boolean validateFileSize(int fileSize, boolean largeFile, String errorKey, ActionMessages errors){ - float maxFileSize; - - //whether we are using large file or not? - if(largeFile) - maxFileSize = Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE); - else - maxFileSize = Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_MAX_SIZE); - - if(fileSize > maxFileSize){ - //Set arg0 in message bundle - String unit= ""; - if(maxFileSize >= 1024){ - maxFileSize = maxFileSize/1024; - unit = "K"; - } - if(maxFileSize >= 1024){ - maxFileSize = maxFileSize/1024; - unit = "M"; - } - NumberFormat format = NumberFormat.getInstance(); - format.setMaximumFractionDigits(1); - String maxSize = format.format(maxFileSize) + unit; - - //set error message - errors.add(errorKey, new ActionMessage(MSG_KEY,maxSize)); - return false; - } - return true; + + private static boolean validateFileSize(int fileSize, boolean largeFile, String errorKey, ActionMessages errors) { + float maxFileSize = largeFile ? Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE) + : Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_MAX_SIZE); + + if (fileSize > maxFileSize) { + String maxSize = formatSize(maxFileSize); + + // set error message + errors.add(errorKey, new ActionMessage(MSG_KEY, maxSize)); + return false; + } + return true; } + + public static String formatSize(double size) { + String unit = null; + if (size >= 1024) { + size = size / 1024; + if (size >= 1024) { + size = size / 1024; + unit = " MB"; + } else { + unit = " KB"; + } + } else { + unit = " B"; + } + + NumberFormat format = NumberFormat.getInstance(); + format.setMaximumFractionDigits(1); + return format.format(size) + unit; + } } Index: lams_tool_forum/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/conf/language/lams/ApplicationResources.properties,v diff -u -r1.43 -r1.44 --- lams_tool_forum/conf/language/lams/ApplicationResources.properties 15 Feb 2012 22:00:21 -0000 1.43 +++ lams_tool_forum/conf/language/lams/ApplicationResources.properties 21 Feb 2012 10:04:43 -0000 1.44 @@ -235,7 +235,7 @@ monitor.summary.date.restriction.removed =Date restriction has been removed errors.maxfilesize =Uploaded file exceeded maximum size: {0} error.attachment.executable =Uploaded file is executable -label.upload.info =Uploaded file must not be executable and not exceed size of {0} bytes +label.upload.info =Uploaded file must not be executable and not exceed size of {0} #======= End labels: Exported 230 labels for en AU ===== Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java,v diff -u -r1.73 -r1.74 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java 15 Feb 2012 19:15:24 -0000 1.73 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java 21 Feb 2012 10:04:43 -0000 1.74 @@ -75,6 +75,7 @@ import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.FileValidatorUtil; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.util.DateUtil; import org.lamsfoundation.lams.web.session.SessionManager; @@ -621,9 +622,12 @@ // as it has a link from the view topic screen back to View Forum screen. boolean hideReflection = WebUtil.readBooleanParam(request, ForumConstants.ATTR_HIDE_REFLECTION, false); sessionMap.put(ForumConstants.ATTR_HIDE_REFLECTION, hideReflection); + + if (sessionMap.get(ForumConstants.ATTR_UPLOAD_MAX_FILE_SIZE) == null && LearningAction.UPLOAD_MAX_FILE_SIZE > 0) { + sessionMap.put(ForumConstants.ATTR_UPLOAD_MAX_FILE_SIZE, + FileValidatorUtil.formatSize(LearningAction.UPLOAD_MAX_FILE_SIZE)); + } - sessionMap.put(ForumConstants.ATTR_UPLOAD_MAX_FILE_SIZE, LearningAction.UPLOAD_MAX_FILE_SIZE); - return mapping.findForward("success"); }