Class 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 Detail

      • STATUS_FILENAME_CONFLICT

        public static final int STATUS_FILENAME_CONFLICT
        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
      • 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 File
        contentType - the contentType of the given File
        isFileDocument - true if it must be stored in a FileDocument Path
        override - 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 File
        options - 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 File
        isFileDocument - true if it must be stored in a FileDocument Path
        override - 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 File
        options - 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 class java.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