javazoom.upload
Class UploadBean

java.lang.Object
  extended byjavazoom.upload.UploadBean
All Implemented Interfaces:
java.io.Serializable

public class UploadBean
extends java.lang.Object
implements java.io.Serializable

This class implements an UploadBean.
Features :
- Store file(s) under a remote folder.
- Store file(s) in a zip archive.
- Store file(s) in a database.
- Store file(s) in a memory folder.

- Events generated on upload.

See Also:
Serialized Form

Field Summary
static int DATABASESTORE
           
static java.lang.String EMPTYENTRY
           
static int FOLDERSTORE
           
static boolean INSERTASBYTES
          Internal switch to use setBytes or setBinaryStream : Default is false (setBinaryStream)
static int MAXUPLOADEDFILES
          Maximum uploaded files.
static long MAXUPLOADEDFILESIZE
          Size limit for an uploaded file.
static int MEMORYSTORE
           
static char SEPARATOR
           
static int SERIALIZEDFILESTORE
          Reserved for future usage.
static java.lang.String SQLUPLOADFILE
          Column name to store uploaded data : Default is BINARYFILE
static java.lang.String SQLUPLOADFILENAME
          Column name to store uploaded filename : Default is FILENAME
static java.lang.String SQLUPLOADFILESIZE
          Column name to store uploaded filesize : Default is FILESIZE
static java.lang.String SQLUPLOADFILETYPE
          Column name to store uploaded filetype : Default is FILETYPE
static java.lang.String SQLUPLOADID
          Column name to store uploaded file id : Default is UPLOADID
static java.lang.String SQLUPLOADTABLE
          Database table name to store uploaded file : Default is UPLOADS
static int TARGZIPFILESTORE
          Reserved for future usage.
static int TRANSFERBUFFERSIZE
           
static java.lang.String VERSION
           
static int XMLFILESTORE
          Reserved for future usage.
static int ZIPFILESTORE
           
 
Constructor Summary
UploadBean()
          Dummy constructor (needed for JavaBeans).
 
Method Summary
 void addUploadListener(UploadListener listener)
          Adds UploadListener to be notified.
 long computeCRC32(java.io.File file, long offset)
          Compute CRC32 for a given filename.
 byte[] computeMD5(java.io.File file, long offset)
          Compute MD5 for a given filename.
 java.lang.String getBlacklist()
          Returns blacklist.
 java.sql.Connection getDatabasestore()
          Returns database store connection.
 DBStore getDatabasestoreimplementation()
          Returns database store concrete implementation.
 boolean getDump()
          Get dump mode.
 long getFilesizelimit()
          Returns maximum size allowed for an uploaded file.
 java.lang.String getFolderstore()
          Returns store folder.
 java.util.Vector getHistory()
          Returns a Vector[UploadParameters].
 int getMaxfiles()
          Returns maximum amount of stored files.
 java.util.Vector getMemorystore()
          Returns a Vector[UploadFile] from memory store.
 boolean getOverwrite()
          Returns overwrite state.
 java.lang.String getOverwritepolicy()
          Return overwrite policy.
 java.lang.String getParser()
          Gets current multipart parser.
 java.lang.String getParsertmpdir()
          Gets multipart parser tempory directory if applicable.
 java.lang.String getWhitelist()
          Returns whitelist.
 java.lang.String getZipfilestore()
          Returns zip store filename.
 java.lang.String hexDump(byte[] in)
          Dump byte array to hexadecimal string.
 boolean isBlacklistEnabled()
          Returns true if blacklist is enabled or false if whitelist is enabled.
 OverwriteFilter loadOverwriteFilter()
          Returns Overwrite Filter.
 void resetStore()
          Cleans and resets the current store.
 void setBlacklist(java.lang.String blacklist)
          Setup blacklist : filenames separated by comma.
 void setDatabasestore(java.sql.Connection jdbcconnection)
          Setup the store database that suits to JDBC 2.0 extension.
 void setDatabasestore(java.lang.String driver, java.lang.String URL, java.util.Properties credentials)
          Setup the store database.
 void setDatabasestoreimplementation(java.lang.String impl)
          Setup your own database store implemention DBStore API compliant.
 void setDump(boolean dmp)
          Set dump mode.
 void setFilesizelimit(long max)
          Sets maximum size allowed for an uploaded file.
 void setFolderstore(java.lang.String serverfolder)
          Sets the remote store folder.
 void setMaxfiles(int max)
          Sets maximum amount of stored files.
 void setMemorystore()
          Sets the memory store folder.
 void setOverwrite(boolean overwrite)
          Enables/Disables entry overwrite.
 void setOverwritepolicy(java.lang.String policy)
          Set overwrite policy.
 void setParser(java.lang.String parserid)
          Selects a multipart Parser.
 void setParsertmpdir(java.lang.String dir)
          Sets temporary directory for Struts multipart parser only.
 void setStoremodel(int storeid)
          Selects the store model.
 void setWhitelist(java.lang.String whitelist)
          Setup whitelist : filenames separated by comma.
 void setZipfilestore(java.lang.String file)
          Sets the remote store zipfile.
 void store(MultipartFormDataRequest mrequest)
          Moves all files to the store.
 void store(MultipartFormDataRequest mrequest, java.lang.String field)
          Moves one file identified by its form field to the store.
 void store(MultipartFormDataRequest mrequest, java.lang.String field, java.util.Map extra)
          Moves one file identified by its form field to the store and pass extra parameters.
 void updateOverwriteFilter(OverwriteFilter filter)
          Replace Overwrite filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

MAXUPLOADEDFILES

public static final int MAXUPLOADEDFILES
Maximum uploaded files. Default is -1 unlimited

See Also:
Constant Field Values

MAXUPLOADEDFILESIZE

public static final long MAXUPLOADEDFILESIZE
Size limit for an uploaded file. Default is 1GB

See Also:
Constant Field Values

SEPARATOR

public static char SEPARATOR

MEMORYSTORE

public static final int MEMORYSTORE
See Also:
Constant Field Values

FOLDERSTORE

public static final int FOLDERSTORE
See Also:
Constant Field Values

DATABASESTORE

public static final int DATABASESTORE
See Also:
Constant Field Values

ZIPFILESTORE

public static final int ZIPFILESTORE
See Also:
Constant Field Values

TARGZIPFILESTORE

public static final int TARGZIPFILESTORE
Reserved for future usage.

See Also:
Constant Field Values

SERIALIZEDFILESTORE

public static final int SERIALIZEDFILESTORE
Reserved for future usage.

See Also:
Constant Field Values

XMLFILESTORE

public static final int XMLFILESTORE
Reserved for future usage.

See Also:
Constant Field Values

EMPTYENTRY

public static final java.lang.String EMPTYENTRY
See Also:
Constant Field Values

TRANSFERBUFFERSIZE

public static int TRANSFERBUFFERSIZE

SQLUPLOADTABLE

public static java.lang.String SQLUPLOADTABLE
Database table name to store uploaded file : Default is UPLOADS


SQLUPLOADID

public static java.lang.String SQLUPLOADID
Column name to store uploaded file id : Default is UPLOADID


SQLUPLOADFILENAME

public static java.lang.String SQLUPLOADFILENAME
Column name to store uploaded filename : Default is FILENAME


SQLUPLOADFILE

public static java.lang.String SQLUPLOADFILE
Column name to store uploaded data : Default is BINARYFILE


SQLUPLOADFILESIZE

public static java.lang.String SQLUPLOADFILESIZE
Column name to store uploaded filesize : Default is FILESIZE


SQLUPLOADFILETYPE

public static java.lang.String SQLUPLOADFILETYPE
Column name to store uploaded filetype : Default is FILETYPE


INSERTASBYTES

public static boolean INSERTASBYTES
Internal switch to use setBytes or setBinaryStream : Default is false (setBinaryStream)

Constructor Detail

UploadBean

public UploadBean()
Dummy constructor (needed for JavaBeans).

Method Detail

addUploadListener

public void addUploadListener(UploadListener listener)
Adds UploadListener to be notified.

Parameters:
listener - UploadListener

setStoremodel

public void setStoremodel(int storeid)
                   throws UploadException
Selects the store model.

Parameters:
storeid - int
Throws:
UploadException

getDatabasestore

public java.sql.Connection getDatabasestore()
Returns database store connection.

Returns:
Connection

getDatabasestoreimplementation

public DBStore getDatabasestoreimplementation()
Returns database store concrete implementation.

Returns:
DBStore

getZipfilestore

public java.lang.String getZipfilestore()
Returns zip store filename.

Returns:
String

getFolderstore

public java.lang.String getFolderstore()
Returns store folder.

Returns:
String

getMemorystore

public java.util.Vector getMemorystore()
Returns a Vector[UploadFile] from memory store.

Returns:
Vector

setMemorystore

public void setMemorystore()
                    throws UploadException
Sets the memory store folder. All files will be stored in memory.

Throws:
UploadException

setFolderstore

public void setFolderstore(java.lang.String serverfolder)
                    throws UploadException
Sets the remote store folder. This method check thats if the folder exists (and is RW). If not then it attemps to create it.
i.e. : /usr/client/www/uploaded

Parameters:
serverfolder - String
Throws:
UploadException

setZipfilestore

public void setZipfilestore(java.lang.String file)
                     throws UploadException,
                            java.io.IOException
Sets the remote store zipfile.
if the does not exits then it attemps to create one. i.e. : /usr/client/www/uploaded.zip

Parameters:
file - String
Throws:
UploadException
java.io.IOException

setDatabasestoreimplementation

public void setDatabasestoreimplementation(java.lang.String impl)
                                    throws UploadException
Setup your own database store implemention DBStore API compliant.

Parameters:
impl - String
Throws:
UploadException

setDatabasestore

public void setDatabasestore(java.lang.String driver,
                             java.lang.String URL,
                             java.util.Properties credentials)
                      throws java.lang.Exception
Setup the store database.
i.e. : Driver : oracle.jdbc.driver.OracleDriver
i.e. : URL : jdbc:oracle:thin:@dbserver:1521:DEMODB

Parameters:
driver - String
URL - String
credentials - Properties
Throws:
java.lang.Exception

setDatabasestore

public void setDatabasestore(java.sql.Connection jdbcconnection)
                      throws java.lang.Exception
Setup the store database that suits to JDBC 2.0 extension.
Think about DataSource to fill in the jdbcconnection parameter.

Parameters:
jdbcconnection - Connection
Throws:
java.lang.Exception

getBlacklist

public java.lang.String getBlacklist()
Returns blacklist.

Returns:
String

setBlacklist

public void setBlacklist(java.lang.String blacklist)
Setup blacklist : filenames separated by comma.
i.e. : "install.exe,setup.zip,*.cab"

Parameters:
blacklist - String

getWhitelist

public java.lang.String getWhitelist()
Returns whitelist.

Returns:
String

setWhitelist

public void setWhitelist(java.lang.String whitelist)
Setup whitelist : filenames separated by comma.
i.e. : "mysong.ogg,*.mp2,*.mp3"

Parameters:
whitelist - String

isBlacklistEnabled

public boolean isBlacklistEnabled()
Returns true if blacklist is enabled or false if whitelist is enabled.

Returns:
boolean

setOverwrite

public void setOverwrite(boolean overwrite)
Enables/Disables entry overwrite. For folder ans zip store, overwrite=false will append System.currentTimeMillis() to duplicate filename (see overwritepolicy parameter to customize this behavior). You could get the new filename through UploadParameters.getAltFilename().
For memory store, all uploaded files are appended to a list.
For database store (default implementation), overwrite=false will insert a new record, overwrite=true will update it.

Parameters:
overwrite - boolean

getOverwrite

public boolean getOverwrite()
Returns overwrite state.

Returns:
boolean

setOverwritepolicy

public void setOverwritepolicy(java.lang.String policy)
Set overwrite policy. Default is "filenametimestamp".

Parameters:
policy - String

getOverwritepolicy

public java.lang.String getOverwritepolicy()
Return overwrite policy.

Returns:
String

updateOverwriteFilter

public void updateOverwriteFilter(OverwriteFilter filter)
Replace Overwrite filter.

Parameters:
filter - OverwriteFilter

loadOverwriteFilter

public OverwriteFilter loadOverwriteFilter()
Returns Overwrite Filter.

Returns:
OverwriteFilter

getDump

public boolean getDump()
Get dump mode.

Returns:
boolean

setDump

public void setDump(boolean dmp)
Set dump mode. Dump is disabled by default.

Parameters:
dmp - boolean

setParser

public void setParser(java.lang.String parserid)
Selects a multipart Parser.

Parameters:
parserid - MultipartFormDataRequest.COSPARSER, MultipartFormDataRequest.STRUTSPARSER, MultipartFormDataRequest.CFUPARSER

getParser

public java.lang.String getParser()
Gets current multipart parser.

Returns:
Parser class name

getParsertmpdir

public java.lang.String getParsertmpdir()
Gets multipart parser tempory directory if applicable.

Returns:
null if multipart parser is not Struts.

setParsertmpdir

public void setParsertmpdir(java.lang.String dir)
Sets temporary directory for Struts multipart parser only. If this folder doesn't exist then it will be created automatically by this method.

Parameters:
dir - Something like c:\\Temp or /tmp

setMaxfiles

public void setMaxfiles(int max)
Sets maximum amount of stored files.

Parameters:
max - -1 means no limit

getMaxfiles

public int getMaxfiles()
Returns maximum amount of stored files.

Returns:
int

getFilesizelimit

public long getFilesizelimit()
Returns maximum size allowed for an uploaded file.

Returns:
long

setFilesizelimit

public void setFilesizelimit(long max)
Sets maximum size allowed for an uploaded file.

Parameters:
max - long

computeCRC32

public long computeCRC32(java.io.File file,
                         long offset)
Compute CRC32 for a given filename.

Parameters:
file -
offset - data range [0-offset] to compute CRC32, -1 for all data.
Returns:
-1 if cannot compute CRC32.

computeMD5

public byte[] computeMD5(java.io.File file,
                         long offset)
Compute MD5 for a given filename.

Parameters:
file -
offset - data range [0-offset] to compute MD5, -1 for all data.
Returns:
null if cannot compute MD5.

hexDump

public java.lang.String hexDump(byte[] in)
Dump byte array to hexadecimal string.

Parameters:
in -
Returns:
null if cannot compute

store

public void store(MultipartFormDataRequest mrequest,
                  java.lang.String field,
                  java.util.Map extra)
           throws UploadException,
                  java.io.IOException
Moves one file identified by its form field to the store and pass extra parameters.

Parameters:
mrequest -
field -
extra - parameters
Throws:
UploadException
java.io.IOException

store

public void store(MultipartFormDataRequest mrequest,
                  java.lang.String field)
           throws UploadException,
                  java.io.IOException
Moves one file identified by its form field to the store.

Parameters:
mrequest -
field -
Throws:
UploadException
java.io.IOException

store

public void store(MultipartFormDataRequest mrequest)
           throws UploadException,
                  java.io.IOException
Moves all files to the store.

Parameters:
mrequest -
Throws:
UploadException
java.io.IOException

getHistory

public java.util.Vector getHistory()
Returns a Vector[UploadParameters].

Returns:
Vector

resetStore

public void resetStore()
                throws UploadException,
                       java.io.IOException
Cleans and resets the current store.
MemoryStore will be empty.
ZipFileStore will be deleted and recreated.
All files in FolderStore will be deleted.

Throws:
UploadException
java.io.IOException