Class DLStoreUtil

Object
com.liferay.document.library.kernel.store.DLStoreUtil

public class DLStoreUtil extends Object
Provides methods for storing files in the portal. The file storage implementation can be selected in portal.properties under the property dl.store.impl. Virus checking can also be enabled under the property dl.store.antivirus.impl.

The main client for this class is the Document Library portlet. It is also used by other portlets like Wiki and Message Boards to store file attachments. For the Document Library portlet, the repositoryId can be obtained by calling com.liferay.portlet.documentlibrary.model.DLFolderConstants#getDataRepositoryId(long,long). For all other portlets, the repositoryId should be set to CompanyConstants.SYSTEM. These methods can be used in plugins and other portlets, as shown below.

 
 long repositoryId = CompanyConstants.SYSTEM;
 String dirName = "portlet_name/1234";

 try {
     DLStoreUtil.addDirectory(companyId, repositoryId, dirName);
 }
 catch (PortalException pe) {
 }

 DLStoreUtil.addFile(
     companyId, repositoryId, dirName + "/" + fileName, file);
 
 

Author:
Brian Wing Shun Chan, Alexander Chow, Edward Han, Raymond Augé
See Also:
  • DLStoreImpl
  • Constructor Details

    • DLStoreUtil

      public DLStoreUtil()
  • Method Details

    • addFile

      public static void addFile(DLStoreRequest dlStoreRequest, byte[] bytes) throws PortalException
      Throws:
      PortalException
    • addFile

      public static void addFile(DLStoreRequest dlStoreRequest, File file) throws PortalException
      Throws:
      PortalException
    • addFile

      public static void addFile(DLStoreRequest dlStoreRequest, InputStream inputStream) throws PortalException
      Throws:
      PortalException
    • copyFileVersion

      public static void copyFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) throws PortalException
      Creates a new copy of the file version.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the original's file name
      fromVersionLabel - the original file's version label
      toVersionLabel - the new version label
      Throws:
      PortalException
    • deleteDirectory

      public static void deleteDirectory(long companyId, long repositoryId, String dirName) throws PortalException
      Deletes a directory.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      dirName - the directory's name
      Throws:
      PortalException
    • deleteFile

      public static void deleteFile(long companyId, long repositoryId, String fileName) throws PortalException
      Deletes a file. If a file has multiple versions, all versions will be deleted.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the file's name
      Throws:
      PortalException
    • deleteFile

      public static void deleteFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
      Deletes a file at a particular version.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the file's name
      versionLabel - the file's version label
      Throws:
      PortalException
    • getFileAsStream

      public static InputStream getFileAsStream(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
      Returns the file as an InputStream object.

      If using an S3 store, it is preferable for performance reasons to use this method to get the file as an InputStream instead of using other methods to get the file as a File.

      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the file's name
      versionLabel - the file's version label
      Returns:
      Returns the InputStream object with the file's name
      Throws:
      PortalException
    • getFileNames

      public static String[] getFileNames(long companyId, long repositoryId, String dirName) throws PortalException
      Returns all files of the directory.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      dirName - the directory's name
      Returns:
      Returns all files of the directory
      Throws:
      PortalException
    • getFileSize

      public static long getFileSize(long companyId, long repositoryId, String fileName) throws PortalException
      Returns the size of the file.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the file's name
      Returns:
      Returns the size of the file
      Throws:
      PortalException
    • getStore

      public static DLStore getStore()
      Returns the DLStore object. Used primarily by Spring and should not be used by the client.
      Returns:
      Returns the DLStore object
    • hasFile

      public static boolean hasFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
      Returns true if the file exists.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the file's name
      versionLabel - the file's version label
      Returns:
      true if the file exists; false otherwise
      Throws:
      PortalException
    • updateFile

      public static void updateFile(DLStoreRequest dlStoreRequest, File file) throws PortalException
      Throws:
      PortalException
    • updateFile

      public static void updateFile(DLStoreRequest dlStoreRequest, InputStream inputStream) throws PortalException
      Throws:
      PortalException
    • updateFile

      public static void updateFile(long companyId, long repositoryId, long newRepositoryId, String fileName) throws PortalException
      Moves a file to a new data repository.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository
      newRepositoryId - the primary key of the new data repository
      fileName - the file's name
      Throws:
      PortalException
    • updateFileVersion

      public static void updateFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) throws PortalException
      Update's a file version label. Similar to copyFileVersion(long, long, String, String, String) except that the old file version is deleted.
      Parameters:
      companyId - the primary key of the company
      repositoryId - the primary key of the data repository (optionally CompanyConstants.SYSTEM)
      fileName - the file's name
      fromVersionLabel - the file's version label
      toVersionLabel - the file's new version label
      Throws:
      PortalException
    • setDLStore

      public void setDLStore(DLStore dlStore)