com.jalios.jcms.upload
Class DocUploadInfo

java.lang.Object
  extended by com.jalios.jcms.upload.DocUploadInfo
All Implemented Interfaces:
JcmsConstants, JaliosConstants

public class DocUploadInfo
extends Object
implements JcmsConstants

A convenient wrapper of uploaded files that have been decoded by MultiPartFilter. It handle uploads and rights of file path and FileDocument.

Since:
jcms-5.7.0
Version:
$Revision: 27753 $
Author:
Jean-Philippe Encausse
See Also:
FileDocument

Field Summary
protected  String contentType
           
protected  String fieldName
           
protected  File file
           
protected  long fileLength
           
protected  File fileTmp
           
static FileDocument INVALID_DOCUMENT
           
protected  boolean isFileDocument
           
protected  String originalFileName
           
protected  boolean override
           
static String REVISION
           
protected  int status
           
static int STATUS_CUSTOM_REJECTED
           
static int STATUS_FILENAME_CONFLICT
           
static int STATUS_INTERNAL_ERROR
           
static int STATUS_NONE
           
static int STATUS_TOO_LARGE
           
static int STATUS_TOO_SMALL
           
protected  String statusMsgProp
           
protected  String targetFileDir
           
protected  String targetFileName
           
 
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, CRYPT_MD5, CRYPT_UNDEFINED, CRYPT_UNIX, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, ICON_ARCHIVE, ICON_LOCK, ICON_LOCK_STRONG, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_DEEP_COPY, OP_DEEP_DELETE, OP_DELETE, OP_MERGE, OP_UPDATE, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SESSION_AUTHORIZED_FILENAMES_SET, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, URL_REGEXP, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
 
Fields inherited from interface com.jalios.util.JaliosConstants
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
 
Constructor Summary
DocUploadInfo()
           
DocUploadInfo(FileDocument fd)
          Convenient constructor to call method checkPermission() from a given existing FileDocument
 
Method Summary
 boolean canOverride()
          Returns the override parameter
 boolean checkPermission()
          Check upload permission for the given DocUploadInfo.
protected  void computePath()
          Setup upload infos: targetFilePath targetFileName file status (Name conflicts) Vars targetFileName and targetFilePath are not modified by "override" parameter for FileDocument because old file must not be overrided at this time.
 void doUpload(org.apache.commons.fileupload.FileItem item, boolean isFileDocument, boolean override)
          Performs upload of the given FileItem.
 void doUpload(File file, String contentType, boolean isFileDocument, boolean override)
          Performs upload of the given File.
 String getContentType()
          Returns the ContentType
 File getFile()
          Returns the uploaded File.
 FileDocument getFileDocument()
          Returns an instance of FileDocument build from current upload infos.
 FileDocument getFileDocument(Class clazz)
          Returns an instance of FileDocument build from current upload infos.
 String getFilename()
          Returns the relative path of the file or "" if there is no file.
 File getFileTmp()
          Returns the uploaded tmp File.
static long getMaxFileSize(String contentType)
          Returns the maximum file size allowed for the given contentType.
 String getOriginalFileName()
          Returns the original File name
 int getStatus()
          Returns the Status
 String getStatusMessage(String lang)
          Return a Message for the current Status.
 String getTargetFileDir()
          Returns the path of the directory containing the target file.
 String getTargetFileName()
          Returns the name of the target file.
 String getTitle()
           
 boolean isFileDocument()
          Returns the isFileDocument parameter
protected  void performUpload(org.apache.commons.fileupload.FileItem item)
          Creates real file for the given FileItem
 void setCustomStatusMessage(String prop)
          Set the custom status message that should be displayed to the user, must be used.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

STATUS_NONE

public static final int STATUS_NONE
See Also:
Constant Field Values

STATUS_FILENAME_CONFLICT

public static final int STATUS_FILENAME_CONFLICT
See Also:
Constant Field Values

STATUS_CUSTOM_REJECTED

public static final int STATUS_CUSTOM_REJECTED
See Also:
Constant Field Values

STATUS_INTERNAL_ERROR

public static final int STATUS_INTERNAL_ERROR
See Also:
Constant Field Values

STATUS_TOO_LARGE

public static final int STATUS_TOO_LARGE
See Also:
Constant Field Values

STATUS_TOO_SMALL

public static final int STATUS_TOO_SMALL
See Also:
Constant Field Values

fieldName

protected String fieldName

originalFileName

protected String originalFileName

contentType

protected String contentType

targetFileName

protected String targetFileName

targetFileDir

protected String targetFileDir

file

protected File file

fileLength

protected long fileLength

fileTmp

protected File fileTmp

isFileDocument

protected boolean isFileDocument

override

protected boolean override

status

protected int status

statusMsgProp

protected String statusMsgProp

INVALID_DOCUMENT

public static final FileDocument INVALID_DOCUMENT
Constructor Detail

DocUploadInfo

public DocUploadInfo()

DocUploadInfo

public DocUploadInfo(FileDocument fd)
Convenient constructor to call method checkPermission() from a given existing FileDocument

Parameters:
fd -
Method Detail

doUpload

public void doUpload(File file,
                     String contentType,
                     boolean isFileDocument,
                     boolean override)
Performs upload of the given File.

Parameters:
file - the File representing the given File
contentType - the contentType of the given File
isFileDocument - true if it must be stored in a FileDocument Path
override - true to override existing file with same name

doUpload

public void doUpload(org.apache.commons.fileupload.FileItem item,
                     boolean isFileDocument,
                     boolean override)
Performs upload of the given FileItem.

Parameters:
item - the FileItem representing the given File
isFileDocument - true if it must be stored in a FileDocument Path
override - true to override existing file with same name

computePath

protected void computePath()
Setup upload infos: Vars targetFileName and targetFilePath are not modified by "override" parameter for FileDocument because old file must not be overrided at this time.


performUpload

protected void performUpload(org.apache.commons.fileupload.FileItem item)
Creates real file for the given FileItem

Parameters:
item - the FileItem

checkPermission

public boolean checkPermission()
Check upload permission for the given DocUploadInfo. Then check permission in the RightPolicy. If file is rejected then delete file.

Returns:
true if the Permission are OK.

getMaxFileSize

public static long getMaxFileSize(String contentType)
Returns the maximum file size allowed for the given contentType.
Can be configured by modifying properties "upload.permission.size.*".

Parameters:
contentType - the ContentType for which we want to retrieve the maximum file size allowed.
Returns:
a file size in bytes
Since:
jcms-5.7.0

getStatusMessage

public String getStatusMessage(String lang)
Return a Message for the current Status.

Parameters:
lang - the userlang
Returns:
String a message for the given status

setCustomStatusMessage

public void setCustomStatusMessage(String prop)
Set the custom status message that should be displayed to the user, must be used.

Invoke during RightPolicyFilter.checkAfterUpload(DocUploadInfo) if you refuse the file (return false).

Parameters:
prop - an I18N property (e.g. "jcmsplugin.myplugin.msg.")

getFileDocument

public FileDocument getFileDocument()
Returns an instance of FileDocument build from current upload infos. performCreate is never called on FileDocument

Returns:
FileDocument

getFileDocument

public FileDocument getFileDocument(Class clazz)
Returns an instance of FileDocument build from current upload infos. performCreate is never called on FileDocument

Parameters:
clazz - the class of FileDocument to instanciate
Returns:
FileDocument
Since:
jcms-6.2.0

getTitle

public String getTitle()

getFilename

public String getFilename()
Returns the relative path of the file or "" if there is no file. targetFileDir + targetFileName

Returns:
String the relative path

toString

public String toString()
Overrides:
toString in class Object

getFile

public File getFile()
Returns the uploaded File. Since JCMS 6.1, the file is stored in fileTmp then moved to file. So code calling this method might be modified.

Returns:
File the uploaded File
Since:
jcms-6.1.0

getFileTmp

public File getFileTmp()
Returns the uploaded tmp File. Used for permission checks

Returns:
File the uploaded File

getOriginalFileName

public String getOriginalFileName()
Returns the original File name

Returns:
String original File name

getContentType

public String getContentType()
Returns the ContentType

Returns:
String the ContentType

getTargetFileName

public String getTargetFileName()
Returns the name of the target file. e.g.: "uploaded-file.gif"

Returns:
a file name

getTargetFileDir

public String getTargetFileDir()
Returns the path of the directory containing the target file. e.g.: "upload/docs/image/gif/"

Returns:
a relative path

getStatus

public int getStatus()
Returns the Status

Returns:
String the Status

isFileDocument

public boolean isFileDocument()
Returns the isFileDocument parameter

Returns:
boolean the isFileDocument

canOverride

public boolean canOverride()
Returns the override parameter

Returns:
boolean the override


Copyright © 2001-2010 Jalios SA. All Rights Reserved.