Package com.jalios.jcms.upload
Class DocUploadInfo
- java.lang.Object
-
- com.jalios.jcms.upload.DocUploadInfo
-
- All Implemented Interfaces:
JcmsConstants
,JaliosConstants
public class DocUploadInfo extends java.lang.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: 135868 $
- Author:
- Jean-Philippe Encausse
- See Also:
FileDocument
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
contentType
protected java.lang.String
fieldName
protected java.io.File
file
protected long
fileLength
protected java.io.File
fileTmp
static FileDocument
INVALID_DOCUMENT
protected java.lang.String
originalFileName
static java.lang.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 java.lang.String
statusMsgProp
protected java.lang.String
targetFileDir
protected java.lang.String
targetFileName
protected FileUploadOptions
uploadOptions
protected Workspace
workspace
Workspace used during FileDocument creationprotected org.jdom.Document
xmlImportDocument
XML Document used to import fields during FileDocument creation-
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
-
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, AJAX_MODE_ATTR, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, CLASS_PROPERTY, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, COUNTRY_SPRITE, CS_TYPOLOGY_ROOT_CAT_VID, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DEFAULT_PHOTO_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, GLYPH_ICON_PREFIX, ICON_ARCHIVE, ICON_ICON_PREFIX, ICON_LOCK, ICON_LOCK_STRONG, ICON_PREFIX_PROP, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, IS_IN_FRONT_OFFICE, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JCMS_TOASTR_COLLECTION, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LANG_SPRITE, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_CREATE_STR, OP_DEEP_COPY, OP_DEEP_COPY_STR, OP_DEEP_DELETE, OP_DEEP_DELETE_STR, OP_DELETE, OP_DELETE_STR, OP_MERGE, OP_MERGE_STR, OP_UPDATE, OP_UPDATE_STR, ORGANIZATION_ROOT_GROUP_PROP, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_PROP_PREFIX, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_PROP_PREFIX, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_PROP_PREFIX, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_PROP_PREFIX, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_PROP_PREFIX, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, RAW_CONTENT_ICON_PREFIX, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SECURITY_LOG_FILE, SESSION_AUTHORIZED_FILENAMES_SET, SPRITE_ICON_PREFIX, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, TTCARD_MEDIA_HEIGHT, TTCARD_MEDIA_WIDTH, TYPES_ICON_ALT_PROP, TYPES_ICON_SUFFIX_PROP, TYPES_ICON_TITLE_PROP, TYPES_PREFIX_PROP, TYPES_THUMB_SUFFIX_PROP, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, UPLOAD_PERMISSION_COUNT_PROP_PREFIX, UPLOAD_PERMISSION_SIZE_PROP_PREFIX, URL_REGEXP, VID_LOGGED_MEMBER, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
-
-
Constructor Summary
Constructors Constructor Description DocUploadInfo()
DocUploadInfo(FileDocument fd)
Convenient constructor to call method checkPermission() from a given existing FileDocument
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
canOverride()
Deprecated.boolean
checkPermission()
Check upload permission for the given DocUploadInfo.protected void
computePath()
Setup upload infos: targetFileDir, only when working with FileDocument targetFileName, only when working with FileDocument file status (Name conflicts)void
doUpload(java.io.File file, FileUploadOptions options)
Performs upload of the specified file with corresponding options.void
doUpload(java.io.File file, java.lang.String contentType, boolean isFileDocument, boolean override)
Deprecated.void
doUpload(org.apache.commons.fileupload.FileItem item, boolean isFileDocument, boolean override)
Deprecated.void
doUpload(org.apache.commons.fileupload.FileItem item, FileUploadOptions options)
Performs upload of the specified FileItem with corresponding options.java.lang.String
getContentType()
Returns the ContentTypejava.io.File
getFile()
Returns the uploaded File.FileDocument
getFileDocument()
Returns an instance of FileDocument build from current upload infos.FileDocument
getFileDocument(java.lang.Class clazz)
Returns an instance of FileDocument build from current upload infos.long
getFileLength()
Returns an flie length build from current upload infos.java.lang.String
getFilename()
Returns the relative path of the file or "" if there is no file.java.io.File
getFileTmp()
Returns the uploaded tmp File.static long
getMaxFileSize(java.lang.String contentType)
Returns the maximum file size allowed for the given contentType.java.lang.String
getOriginalFileName()
Returns the original File name.int
getStatus()
Returns the Statusjava.lang.String
getStatusMessage(java.lang.String lang)
Return a Message for the current Status.java.lang.String
getTargetFileDir()
Returns the path of the directory containing the target file.java.lang.String
getTargetFileName()
Returns the name of the target file.java.lang.String
getTitle()
boolean
isFileDocument()
Deprecated.protected void
performUpload(org.apache.commons.fileupload.FileItem item)
Creates real file for the given FileItemvoid
setCustomStatusMessage(java.lang.String prop)
Set the custom status message that should be displayed to the user, must be used.void
setWorkspace(Workspace workspace)
Set the Workspace to in FileDocument when being created.void
setXmlImportDocument(org.jdom.Document xmlImportDocument)
Set the XML Document to use to populate FileDocument when being created.java.lang.String
toString()
-
-
-
Field Detail
-
REVISION
public static final java.lang.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 java.lang.String fieldName
-
originalFileName
protected java.lang.String originalFileName
-
contentType
protected java.lang.String contentType
-
targetFileName
protected java.lang.String targetFileName
-
targetFileDir
protected java.lang.String targetFileDir
-
file
protected java.io.File file
-
fileLength
protected long fileLength
-
fileTmp
protected java.io.File fileTmp
-
uploadOptions
protected FileUploadOptions uploadOptions
-
status
protected int status
-
statusMsgProp
protected java.lang.String statusMsgProp
-
xmlImportDocument
protected org.jdom.Document xmlImportDocument
XML Document used to import fields during FileDocument creation
-
workspace
protected Workspace workspace
Workspace used during FileDocument creation
-
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
- the FileDocument
-
-
Method Detail
-
doUpload
@Deprecated public void doUpload(java.io.File file, java.lang.String contentType, boolean isFileDocument, boolean override)
Deprecated.Performs upload of the given File.- Parameters:
file
- the File representing the given FilecontentType
- the contentType of the given FileisFileDocument
- true if it must be stored in a FileDocument Pathoverride
- IGNORED
-
doUpload
public void doUpload(java.io.File file, FileUploadOptions options)
Performs upload of the specified file with corresponding options.- Parameters:
file
- the File representing the given Fileoptions
- the upload options may be null- Since:
- jcms-10.0.6 / JCMS-8317
-
doUpload
@Deprecated public void doUpload(org.apache.commons.fileupload.FileItem item, boolean isFileDocument, boolean override)
Deprecated.Performs upload of the given FileItem.- Parameters:
item
- the FileItem representing the given FileisFileDocument
- true if it must be stored in a FileDocument Pathoverride
- IGNORED
-
doUpload
public void doUpload(org.apache.commons.fileupload.FileItem item, FileUploadOptions options)
Performs upload of the specified FileItem with corresponding options.- Parameters:
item
- the FileItem representing the given Fileoptions
- the upload options may be null- Since:
- jcms-10.0.6 / JCMS-8317
-
computePath
protected void computePath()
Setup upload infos:- targetFileDir, only when working with FileDocument
- targetFileName, only when working with FileDocument
- file
- status (Name conflicts)
-
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(java.lang.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 java.lang.String getStatusMessage(java.lang.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(java.lang.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(java.lang.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 java.lang.String getTitle()
-
getFilename
public java.lang.String getFilename()
Returns the relative path of the file or "" if there is no file.For use only when working with FileDocument.
- Returns:
- String the path relative to the webapp root, return null if upload was not performed to create/update a FileDocument
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getFile
public java.io.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 java.io.File getFileTmp()
Returns the uploaded tmp File. Used for permission checks- Returns:
- File the uploaded File
-
getOriginalFileName
public java.lang.String getOriginalFileName()
Returns the original File name.Value is guaranteed to be sanitized (ie without path seperator like / or \to prevent any path traversal) and safe for use as new file name.
- Returns:
- String original File name
-
getContentType
public java.lang.String getContentType()
Returns the ContentType- Returns:
- String the ContentType
-
getTargetFileName
public java.lang.String getTargetFileName()
Returns the name of the target file. e.g.:"uploaded-file.gif"
- Returns:
- a file name
-
getTargetFileDir
public java.lang.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
@Deprecated public boolean isFileDocument()
Deprecated.Returns the isFileDocument parameter- Returns:
- boolean the isFileDocument
-
canOverride
@Deprecated public boolean canOverride()
Deprecated.Returns the override parameter- Returns:
- always return false
-
getFileLength
public long getFileLength()
Returns an flie length build from current upload infos.- Returns:
- file length
-
setXmlImportDocument
public void setXmlImportDocument(org.jdom.Document xmlImportDocument)
Set the XML Document to use to populate FileDocument when being created.- Parameters:
xmlImportDocument
- a JDom XML Document- Since:
- jcms-9.0
-
setWorkspace
public void setWorkspace(Workspace workspace)
Set the Workspace to in FileDocument when being created.- Parameters:
workspace
- a Workspace- Since:
- jcms-9.0.2
-
-