org.norther.tammi.spray.media
Class DefaultFileUploadFilter

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.spray.filter.DefaultFilter
          extended by org.norther.tammi.spray.filter.DefaultKeyFilter
              extended by org.norther.tammi.spray.filter.DefaultSecureKeyFilter
                  extended by org.norther.tammi.spray.media.DefaultFileUploadFilter
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Filter, Manageable, MBeanDelegate, AccessController, KeyFilter, SecureFilter, SecureKeyFilter, FileUploadFilter

public class DefaultFileUploadFilter
extends DefaultSecureKeyFilter
implements FileUploadFilter

A default implementation of FileUploadFilter.

Author:
Marketta Priha
See Also:
Serialized Form

Field Summary
static String UPLOAD_KEY
          The default key.
 
Fields inherited from class org.norther.tammi.spray.filter.DefaultKeyFilter
DEFAULT_KEY
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultFileUploadFilter()
          Constructs a new filter.
DefaultFileUploadFilter(String key)
          Constructs a new filter with a key.
 
Method Summary
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
           
protected  void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, String fileField)
          Filters the information from the request and protocol extension and uploads the files provided as multipart streams.
 File getUploadedFile(String file)
          Gets the full path of the uploaded file.
 int getUploadFileLimit()
          Gets the limit for the number of upload files.
 String getUploadFolderPath()
          Gets the folder path into which to upload the files.
 String getUploadKey()
          Gets the key of the folder into which to upload the files.
 int getUploadPathLimit()
          Gets the limit for the lenght of the upload path.
 int getUploadSizeLimit()
          Gets the limit for the size of the upload content.
 boolean isOverwriteEnabled()
          Gets the flag that indicates whether a file with the same name may overwrite an existing file in the upload folder.
 void setOverwriteEnabled(boolean flag)
          Sets the flag that indicates whether a file with the same name may overwrite an existing file in the upload folder.
 void setUploadFileLimit(int limit)
          Sets the limit for the number of upload files.
 void setUploadFolderPath(String folder)
          Sets the folder path into which to upload the files.
 void setUploadKey(String key)
          Sets the key of the folder into which to upload the files.
 void setUploadPathLimit(int limit)
          Sets a limit for the lenght of the upload path.
 void setUploadSizeLimit(int limit)
          Sets the limit for the size of the upload content.
protected  String uploadFile(String path, InputStream input)
          Uploads the file by writing the input stream to the named file.
 
Methods inherited from class org.norther.tammi.spray.filter.DefaultSecureKeyFilter
addAllowedPermission, addDeniedPermission, allowedPermissions, allowedRoleSet, checkPermission, checkPermission, checkPermission, checkPermission, checkPermission, checkPermission, clearAllowedPermissions, clearDeniedPermissions, deniedPermissions, deniedRoleSet, getPermissibleRoles, getPermissibleRoles, getPermissibleRoles, isProtected, removeAllowedPermissions, removeDeniedPermissions, setAllowedPermissions, setDeniedPermissions
 
Methods inherited from class org.norther.tammi.spray.filter.DefaultKeyFilter
getKey, getKeyValue, getKeyValues, isLinkedKey, setKey, setLinkedKey
 
Methods inherited from class org.norther.tammi.spray.filter.DefaultFilter
destroy, getFilterConfig, getRequestMap, getSessionMap, init
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.spray.filter.SecureFilter
checkPermission, checkPermission, checkPermission
 
Methods inherited from interface org.norther.tammi.core.security.AccessController
addAllowedPermission, addDeniedPermission, allowedPermissions, allowedRoleSet, checkPermission, checkPermission, checkPermission, clearAllowedPermissions, clearDeniedPermissions, deniedPermissions, deniedRoleSet, getPermissibleRoles, getPermissibleRoles, getPermissibleRoles, isProtected, removeAllowedPermissions, removeDeniedPermissions, setAllowedPermissions, setDeniedPermissions
 
Methods inherited from interface javax.servlet.Filter
destroy, init
 
Methods inherited from interface org.norther.tammi.spray.filter.KeyFilter
getKey, getKeyValue, getKeyValues, isLinkedKey, setKey, setLinkedKey
 
Methods inherited from interface javax.servlet.Filter
destroy, init
 

Field Detail

UPLOAD_KEY

public static final String UPLOAD_KEY
The default key.

See Also:
Constant Field Values
Constructor Detail

DefaultFileUploadFilter

public DefaultFileUploadFilter()
Constructs a new filter.


DefaultFileUploadFilter

public DefaultFileUploadFilter(String key)
Constructs a new filter with a key.

Parameters:
key - the filter key.
Method Detail

getUploadKey

public String getUploadKey()
Description copied from interface: FileUploadFilter
Gets the key of the folder into which to upload the files.

Specified by:
getUploadKey in interface FileUploadFilter
Returns:
the upload key.

setUploadKey

public void setUploadKey(String key)
Description copied from interface: FileUploadFilter
Sets the key of the folder into which to upload the files.

Specified by:
setUploadKey in interface FileUploadFilter
Parameters:
key - the upload key.

getUploadFolderPath

public String getUploadFolderPath()
Description copied from interface: FileUploadFilter
Gets the folder path into which to upload the files. A relative folder will be combined with the upload key.

Specified by:
getUploadFolderPath in interface FileUploadFilter
Returns:
the folder path.

setUploadFolderPath

public void setUploadFolderPath(String folder)
Description copied from interface: FileUploadFilter
Sets the folder path into which to upload the files. A relative folder will be combined with the upload key.

Specified by:
setUploadFolderPath in interface FileUploadFilter
Parameters:
folder - the folder either as an absolute path or relative to the key folder.

isOverwriteEnabled

public boolean isOverwriteEnabled()
Description copied from interface: FileUploadFilter
Gets the flag that indicates whether a file with the same name may overwrite an existing file in the upload folder.

Specified by:
isOverwriteEnabled in interface FileUploadFilter
Returns:
true if files may be overwritten, otherwise false.

setOverwriteEnabled

public void setOverwriteEnabled(boolean flag)
Description copied from interface: FileUploadFilter
Sets the flag that indicates whether a file with the same name may overwrite an existing file in the upload folder.

Specified by:
setOverwriteEnabled in interface FileUploadFilter
Parameters:
flag - the flag, give true if files may be overwritten, otherwise false.

getUploadSizeLimit

public int getUploadSizeLimit()
Description copied from interface: FileUploadFilter
Gets the limit for the size of the upload content.

Specified by:
getUploadSizeLimit in interface FileUploadFilter
Returns:
the limit for the upload size in bytes, or -1 if unlimited.

setUploadSizeLimit

public void setUploadSizeLimit(int limit)
Description copied from interface: FileUploadFilter
Sets the limit for the size of the upload content. The limit is checked against the request size, so some extra may be needed.

Specified by:
setUploadSizeLimit in interface FileUploadFilter
Parameters:
limit - the limit for the upload size in bytes, or -1 if unlimited.

getUploadPathLimit

public int getUploadPathLimit()
Description copied from interface: FileUploadFilter
Gets the limit for the lenght of the upload path.

Specified by:
getUploadPathLimit in interface FileUploadFilter
Returns:
the limit for the upload path in chars, or -1 if unlimited.

setUploadPathLimit

public void setUploadPathLimit(int limit)
Description copied from interface: FileUploadFilter
Sets a limit for the lenght of the upload path.

Specified by:
setUploadPathLimit in interface FileUploadFilter
Parameters:
limit - the limit for the upload path in chars, or -1 if unlimited.

getUploadFileLimit

public int getUploadFileLimit()
Description copied from interface: FileUploadFilter
Gets the limit for the number of upload files.

Specified by:
getUploadFileLimit in interface FileUploadFilter
Returns:
the limit for the upload files, or -1 if unlimited.

setUploadFileLimit

public void setUploadFileLimit(int limit)
Description copied from interface: FileUploadFilter
Sets the limit for the number of upload files. Files exceeding the limit will be deleted upon new uploads.

Specified by:
setUploadFileLimit in interface FileUploadFilter
Parameters:
limit - the limit for the upload files, or -1 if unlimited.

getUploadedFile

public File getUploadedFile(String file)
Description copied from interface: FileUploadFilter
Gets the full path of the uploaded file.

Specified by:
getUploadedFile in interface FileUploadFilter
Parameters:
file - the uploaded file.
Returns:
the uploaded file path.

doFilter

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain chain)
              throws ServletException,
                     IOException
Specified by:
doFilter in interface Filter
Overrides:
doFilter in class DefaultFilter
Throws:
ServletException
IOException

doFilter

protected void doFilter(ServletRequest request,
                        ServletResponse response,
                        FilterChain chain,
                        String fileField)
                 throws IOException
Filters the information from the request and protocol extension and uploads the files provided as multipart streams.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
fileField - the file name field name.
Throws:
IOException - on I/O errors.

uploadFile

protected String uploadFile(String path,
                            InputStream input)
                     throws LogException
Uploads the file by writing the input stream to the named file. Throws WARN level LogExceptions on errors allowing the filter to continue with the following partial streams.

Parameters:
path - the file name.
input - the input stream.
Returns:
the normalized path of the uploaded file.
Throws:
LogException - if upload fails.


Copyright © 2004 The Norther Organization. All rights reserved.