commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 31828] - Size Threshold in Commons Upload not Working
Date Sat, 23 Oct 2004 15:03:27 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31828>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31828

Size Threshold in Commons Upload not Working





------- Additional Comments From michael@michaelmcgrady.com  2004-10-23 15:03 -------
What happens with this, Martin, is that even if you don't use the default file
item implementation you have to carry all the default code because it, rather
than the FileItem interface, is referenced in the DiskFileUpload class.  You
might think about changing the architecture to something like the following for
FileItem, because it looks as if you are treating the implementations of
FileItem like providers:

public abstract class FileItem
    implements Serializable {
  private static Map implementations = null;

  private static synchronized void init() {
    if(implementations == null) {
      implementations = new HashMap();

      // load implementation class names and keys
      // from a Properties file, translate names
      // into Class objects using Class.forName and
      // store mappings.
    }
  }

  public static FileItem getInstance(String  key,
                                     String  fieldName,
                                     String  contentType,
                                     boolean isFormField,
                                     String  fileName,
                                     File    repository) {
    init();
    Class fileItem = (Class)implementations.get(key);

    if(fileItem == null) {
      return new
DefaultFileItem(fieldName,contentType,isFormField,fileName,repository);
    }

    FileItem fi = null;

    try {
      fi = (FileItem)fileItem.newInstance();
    } catch (InstantiationException ie) {
      // Fill in as desired
    } catch (IllegalAccessException iae) {
      // Fill in as desired
    }


    fi.setContentType(contentType);
    fi.setFieldName(fieldName);
    fi.setName(fileName);
    fi.setFormField(isFormField);

    return fi;
  }

  public abstract byte[]       get();
  public abstract String       getContentType();
  public abstract String       getFieldName();
  public abstract InputStream  getInputStream() throws IOException;
  public abstract String       getName();
  public abstract OutputStream getOutputStream() throws IOException;
  public abstract long         getSize();
  public abstract String       getString();
  public abstract String       getString(String encoding) throws
UnsupportedEncodingException;

  public abstract void         setContentType(String name);
  public abstract void         setFieldName(String name);
  public abstract void         setName(String name);
  public abstract void         setFormField(boolean state);
  public abstract void         delete();
  public abstract boolean      isFormField();
  public abstract boolean      isInMemory();
  public abstract void         write(File file) throws Exception;
}


This way you can have your default implementation but not use it when you desire
to have a different implementation.  Then you can just change implementations at
will.  This is, of course, just a start and would affect the use of factories,
etc. for file item.

What do you think?

Michael McGrady

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message