Class DLStoreUtil
Object
com.liferay.document.library.kernel.store.DLStoreUtil
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFile(DLStoreRequest dlStoreRequest, byte[] bytes) static voidaddFile(DLStoreRequest dlStoreRequest, File file) static voidaddFile(DLStoreRequest dlStoreRequest, InputStream inputStream) static voidcopyFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) Creates a new copy of the file version.static voiddeleteDirectory(long companyId, long repositoryId, String dirName) Deletes a directory.static voiddeleteFile(long companyId, long repositoryId, String fileName) Deletes a file.static voiddeleteFile(long companyId, long repositoryId, String fileName, String versionLabel) Deletes a file at a particular version.static InputStreamgetFileAsStream(long companyId, long repositoryId, String fileName, String versionLabel) Returns the file as anInputStreamobject.static String[]getFileNames(long companyId, long repositoryId, String dirName) Returns all files of the directory.static longgetFileSize(long companyId, long repositoryId, String fileName) Returns the size of the file.static DLStoregetStore()Returns theDLStoreobject.static booleanReturnstrueif the file exists.voidsetDLStore(DLStore dlStore) static voidupdateFile(long companyId, long repositoryId, long newRepositoryId, String fileName) Moves a file to a new data repository.static voidupdateFile(DLStoreRequest dlStoreRequest, File file) static voidupdateFile(DLStoreRequest dlStoreRequest, InputStream inputStream) static voidupdateFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) Update's a file version label.
-
Constructor Details
-
DLStoreUtil
public DLStoreUtil()
-
-
Method Details
-
addFile
- Throws:
PortalException
-
addFile
- 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 companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.SYSTEM)fileName- the original's file namefromVersionLabel- the original file's version labeltoVersionLabel- 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 companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.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 companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.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 companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.SYSTEM)fileName- the file's nameversionLabel- 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 anInputStreamobject.If using an S3 store, it is preferable for performance reasons to use this method to get the file as an
InputStreaminstead of using other methods to get the file as aFile.- Parameters:
companyId- the primary key of the companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.SYSTEM)fileName- the file's nameversionLabel- the file's version label- Returns:
- Returns the
InputStreamobject 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 companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.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 companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.SYSTEM)fileName- the file's name- Returns:
- Returns the size of the file
- Throws:
PortalException
-
getStore
Returns theDLStoreobject. Used primarily by Spring and should not be used by the client.- Returns:
- Returns the
DLStoreobject
-
hasFile
public static boolean hasFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException Returnstrueif the file exists.- Parameters:
companyId- the primary key of the companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.SYSTEM)fileName- the file's nameversionLabel- the file's version label- Returns:
trueif the file exists;falseotherwise- Throws:
PortalException
-
updateFile
- 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 companyrepositoryId- the primary key of the data repositorynewRepositoryId- the primary key of the new data repositoryfileName- 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 tocopyFileVersion(long, long, String, String, String)except that the old file version is deleted.- Parameters:
companyId- the primary key of the companyrepositoryId- the primary key of the data repository (optionallyCompanyConstants.SYSTEM)fileName- the file's namefromVersionLabel- the file's version labeltoVersionLabel- the file's new version label- Throws:
PortalException
-
setDLStore
-