Package com.jalios.jcms.upload
Class DocUploadInfo
java.lang.Object
com.jalios.jcms.upload.DocUploadInfo
- All Implemented Interfaces:
JcmsConstants,JaliosConstants
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
- Author:
- Jean-Philippe Encausse
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringprotected Stringprotected Stringprotected Fileprotected longprotected Filestatic final FileDocumentprotected Stringprotected intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected Stringprotected Stringprotected Stringprotected Stringprotected FileUploadOptionsprotected WorkspaceWorkspace used during FileDocument creationprotected org.jdom.DocumentXML Document used to import fields during FileDocument creationFields 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_YEARFields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, 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, DATA_DIRECTORY, DEFAULT_PHOTO_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, GENERATIONAL_STORE_DIRECTORY, 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_MINI, PHOTO_MINI_HEIGHT, PHOTO_MINI_PROP_PREFIX, PHOTO_MINI_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, PHOTO_XLARGE, PHOTO_XLARGE_HEIGHT, PHOTO_XLARGE_PROP_PREFIX, PHOTO_XLARGE_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, SVGSPRITE_ICON_PREFIX, TEMPLATE_TAB, THEME_DIR, 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, TYPES_UNKNOWN_CLASS_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
ConstructorsConstructorDescriptionConvenient constructor to call method checkPermission() from a given existing FileDocument -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck upload permission for the given DocUploadInfo.protected voidSetup upload infos: targetFileDir, only when working with FileDocument targetFileName, only when working with FileDocument file status (Name conflicts)voiddoUpload(File file, FileUploadOptions options) Performs upload of the specified file with corresponding options.voiddoUpload(org.apache.commons.fileupload.FileItem item, FileUploadOptions options) Performs upload of the specified FileItem with corresponding options.Returns the ContentTypegetFile()Returns the uploaded File.Deprecated.the signature with class must be used insteadgetFileDocument(Class clazz) Returns an instance of FileDocument build from current upload infos.longReturns an flie length build from current upload infos.Returns the relative path of the file or "" if there is no file.Returns the uploaded tmp File.static longgetMaxFileSize(String contentType) Returns the maximum file size allowed for the given contentType.Returns the original File name.intReturns the StatusgetStatusMessage(String lang) Return a Message for the current Status.Returns the path of the directory containing the target file.Returns the name of the target file.getTitle()voidsetCustomStatusMessage(String prop) Set the custom status message that should be displayed to the user, must be used.voidsetWorkspace(Workspace workspace) Set the Workspace to in FileDocument when being created.voidsetXmlImportDocument(org.jdom.Document xmlImportDocument) Set the XML Document to use to populate FileDocument when being created.toString()
-
Field Details
-
STATUS_NONE
public static final int STATUS_NONE- See Also:
-
STATUS_FILENAME_CONFLICT
public static final int STATUS_FILENAME_CONFLICT- See Also:
-
STATUS_CUSTOM_REJECTED
public static final int STATUS_CUSTOM_REJECTED- See Also:
-
STATUS_INTERNAL_ERROR
public static final int STATUS_INTERNAL_ERROR- See Also:
-
STATUS_TOO_LARGE
public static final int STATUS_TOO_LARGE- See Also:
-
STATUS_TOO_SMALL
public static final int STATUS_TOO_SMALL- See Also:
-
fieldName
-
originalFileName
-
contentType
-
targetFileName
-
targetFileDir
-
file
-
fileLength
protected long fileLength -
fileTmp
-
uploadOptions
-
status
protected int status -
statusMsgProp
-
xmlImportDocument
protected org.jdom.Document xmlImportDocumentXML Document used to import fields during FileDocument creation -
workspace
Workspace used during FileDocument creation -
extensionRewrittenBefore
-
extensionRewrittenAfter
-
svgValidationFailureExplanation
-
INVALID_DOCUMENT
-
-
Constructor Details
-
DocUploadInfo
public DocUploadInfo() -
DocUploadInfo
Convenient constructor to call method checkPermission() from a given existing FileDocument- Parameters:
fd- the FileDocument
-
-
Method Details
-
doUpload
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
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)
-
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
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
Return a Message for the current Status.- Parameters:
lang- the userlang- Returns:
- String a message for the given status
-
setCustomStatusMessage
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
Deprecated.the signature with class must be used insteadReturns an instance of FileDocument build from current upload infos. performCreate is never called on FileDocument- Returns:
- FileDocument
-
getFileDocument
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
-
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
-
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
Returns the uploaded tmp File. Used for permission checks- Returns:
- File the uploaded File
-
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
Returns the ContentType- Returns:
- String the ContentType
-
getTargetFileName
Returns the name of the target file. e.g.:"uploaded-file.gif"- Returns:
- a file name
-
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
-
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
Set the Workspace to in FileDocument when being created.- Parameters:
workspace- a Workspace- Since:
- jcms-9.0.2
-