Index: lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java =================================================================== diff -u -ree8be67b9e8421f8423d88f4e5f943aa0b07ee42 -r71cf49f904dd88f033e5db3f20d784cfbe6d59eb --- lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java (.../FileValidatorUtil.java) (revision ee8be67b9e8421f8423d88f4e5f943aa0b07ee42) +++ lams_common/src/java/org/lamsfoundation/lams/util/FileValidatorUtil.java (.../FileValidatorUtil.java) (revision 71cf49f904dd88f033e5db3f20d784cfbe6d59eb) @@ -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 =================================================================== diff -u -r32bc06b45beab63d3188fce5684af8b0a1c6fddd -r71cf49f904dd88f033e5db3f20d784cfbe6d59eb --- lams_tool_forum/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 32bc06b45beab63d3188fce5684af8b0a1c6fddd) +++ lams_tool_forum/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 71cf49f904dd88f033e5db3f20d784cfbe6d59eb) @@ -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 =================================================================== diff -u -r136bf9472ef5da3932ae7bb0e0a344004bba3ad9 -r71cf49f904dd88f033e5db3f20d784cfbe6d59eb --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 136bf9472ef5da3932ae7bb0e0a344004bba3ad9) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 71cf49f904dd88f033e5db3f20d784cfbe6d59eb) @@ -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"); }