Class DocUploadInfo

java.lang.Object
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
Author:
Jean-Philippe Encausse
See Also:
  • 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

      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
    • uploadOptions

      protected FileUploadOptions uploadOptions
    • status

      protected int status
    • statusMsgProp

      protected 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
    • extensionRewrittenBefore

      protected String extensionRewrittenBefore
    • extensionRewrittenAfter

      protected String extensionRewrittenAfter
    • svgValidationFailureExplanation

      protected String svgValidationFailureExplanation
    • INVALID_DOCUMENT

      public static final FileDocument INVALID_DOCUMENT
  • Constructor Details

    • DocUploadInfo

      public DocUploadInfo()
    • DocUploadInfo

      public DocUploadInfo(FileDocument fd)
      Convenient constructor to call method checkPermission() from a given existing FileDocument
      Parameters:
      fd - the FileDocument
  • Method Details

    • doUpload

      public void doUpload(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

      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)
    • 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

      @Deprecated public FileDocument getFileDocument()
      Deprecated.
      the signature with class must be used instead
      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.

      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 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.

      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 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
    • 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