01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: * */
05: package org.jasig.portal;
06:
07: import java.text.DecimalFormat;
08:
09: /**
10: * UploadStatus provides status for mulit-part form data requests to channels.
11: * This allows for channels to handle errors that occur when parameters
12: * are not passed along in the request when the
13: * max upload file size is exceeded.
14: */
15: public class UploadStatus {
16:
17: private int status;
18: private int maxSize;
19:
20: UploadStatus(int status, int maxSize) {
21: this .status = status;
22: this .maxSize = maxSize;
23: }
24:
25: /**
26: * Provides the status for the current upload.
27: * @return the upload status as an int.
28: */
29: public int getStatus() {
30: return status;
31: }
32:
33: /**
34: * Provides the max upload file size set in portal properties.
35: * @return the max upload file size as an int.
36: */
37: public int getMaxSize() {
38: return maxSize;
39: }
40:
41: /**
42: * Provides the max upload file size (in Megabytes)
43: * which are set in portal properties.
44: * @return <code>java.lang.String</code> - the max upload file size.
45: */
46: public String getFormattedMaxSize() {
47: double availableSpace = ((double) maxSize) / (1024.0 * 1024.0);
48: return (fileSizeFormatter.format(availableSpace) + "MB");
49: }
50:
51: /* static members */
52: public static final int SUCCESS = 0;
53: public static final int FAILURE = 1;
54:
55: private static final String SIZE_FORMAT = "##0.##";
56: private static DecimalFormat fileSizeFormatter = new DecimalFormat(
57: SIZE_FORMAT);
58:
59: } // end UploadStatus class
|