public class DLStoreUtil
extends Object
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);
DLStoreImpl
Constructor and Description |
---|
DLStoreUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
addFile(long companyId,
long repositoryId,
String fileName,
boolean validateFileExtension,
byte[] bytes)
Adds a file based on a byte array.
|
static void |
addFile(long companyId,
long repositoryId,
String fileName,
boolean validateFileExtension,
File file)
Adds a file based on a
File object. |
static void |
addFile(long companyId,
long repositoryId,
String fileName,
boolean validateFileExtension,
InputStream inputStream)
Adds a file based on a
InputStream object. |
static void |
addFile(long companyId,
long repositoryId,
String fileName,
byte[] bytes)
Adds a file based on a byte array.
|
static void |
addFile(long companyId,
long repositoryId,
String fileName,
File file)
Adds a file based on a
File object. |
static void |
addFile(long companyId,
long repositoryId,
String fileName,
InputStream inputStream)
Adds a file based on an
InputStream object. |
static void |
copyFileVersion(long companyId,
long repositoryId,
String fileName,
String fromVersionLabel,
String toVersionLabel)
Creates a new copy of the file version.
|
static void |
deleteDirectory(long companyId,
long repositoryId,
String dirName)
Deletes a directory.
|
static void |
deleteFile(long companyId,
long repositoryId,
String fileName)
Deletes a file.
|
static void |
deleteFile(long companyId,
long repositoryId,
String fileName,
String versionLabel)
Deletes a file at a particular version.
|
static byte[] |
getFileAsBytes(long companyId,
long repositoryId,
String fileName)
Returns the file as a byte array.
|
static byte[] |
getFileAsBytes(long companyId,
long repositoryId,
String fileName,
String versionLabel)
Returns the file as a byte array.
|
static InputStream |
getFileAsStream(long companyId,
long repositoryId,
String fileName)
Returns the file as an
InputStream object. |
static InputStream |
getFileAsStream(long companyId,
long repositoryId,
String fileName,
String versionLabel)
Returns the file as an
InputStream object. |
static String[] |
getFileNames(long companyId,
long repositoryId,
String dirName)
Returns all files of the directory.
|
static long |
getFileSize(long companyId,
long repositoryId,
String fileName)
Returns the size of the file.
|
static DLStore |
getStore()
Returns the
DLStore object. |
static boolean |
hasFile(long companyId,
long repositoryId,
String fileName)
Returns
true if the file exists. |
static boolean |
hasFile(long companyId,
long repositoryId,
String fileName,
String versionLabel)
Returns
true if the file exists. |
void |
setStore(DLStore store)
Set's the
DLStore object. |
static void |
updateFile(long companyId,
long repositoryId,
long newRepositoryId,
String fileName)
Moves a file to a new data repository.
|
static void |
updateFile(long companyId,
long repositoryId,
String fileName,
String fileExtension,
boolean validateFileExtension,
String versionLabel,
String sourceFileName,
File file)
Updates a file based on a
File object. |
static void |
updateFile(long companyId,
long repositoryId,
String fileName,
String fileExtension,
boolean validateFileExtension,
String versionLabel,
String sourceFileName,
InputStream inputStream)
Updates a file based on a
InputStream object. |
static void |
updateFileVersion(long companyId,
long repositoryId,
String fileName,
String fromVersionLabel,
String toVersionLabel)
Update's a file version label.
|
static void |
validate(String fileName,
boolean validateFileExtension)
Validates a file's name.
|
static void |
validate(String fileName,
boolean validateFileExtension,
byte[] bytes)
Validates a file's name and data.
|
static void |
validate(String fileName,
boolean validateFileExtension,
File file)
Validates a file's name and data.
|
static void |
validate(String fileName,
boolean validateFileExtension,
InputStream inputStream)
Validates a file's name and data.
|
static void |
validate(String fileName,
String fileExtension,
String sourceFileName,
boolean validateFileExtension) |
static void |
validate(String fileName,
String fileExtension,
String sourceFileName,
boolean validateFileExtension,
File file)
Validates a file's name and data.
|
static void |
validate(String fileName,
String fileExtension,
String sourceFileName,
boolean validateFileExtension,
InputStream inputStream)
Validates a file's name and data.
|
public static void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension, byte[] bytes) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namevalidateFileExtension
- whether to validate the file's extensionbytes
- the files's dataPortalException
public static void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension, File file) throws PortalException
File
object.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namevalidateFileExtension
- whether to validate the file's extensionfile
- Name the file namePortalException
public static void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension, InputStream inputStream) throws PortalException
InputStream
object.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namevalidateFileExtension
- whether to validate the file's extensioninputStream
- the files's dataPortalException
public static void addFile(long companyId, long repositoryId, String fileName, byte[] bytes) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namebytes
- the files's dataPortalException
public static void addFile(long companyId, long repositoryId, String fileName, File file) throws PortalException
File
object. Enforces validation of file's
extension.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namefile
- Name the file namePortalException
public static void addFile(long companyId, long repositoryId, String fileName, InputStream inputStream) throws PortalException
InputStream
object. Enforces validation
of file's extension.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file nameinputStream
- the files's dataPortalException
public static void copyFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the original's file namefromVersionLabel
- the original file's version labeltoVersionLabel
- the new version labelPortalException
public static void deleteDirectory(long companyId, long repositoryId, String dirName)
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)dirName
- the directory's namepublic static void deleteFile(long companyId, long repositoryId, String fileName) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's namePortalException
public static void deleteFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's nameversionLabel
- the file's version labelPortalException
public static byte[] getFileAsBytes(long companyId, long repositoryId, String fileName) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's namePortalException
public static byte[] getFileAsBytes(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's nameversionLabel
- the file's version labelPortalException
public static InputStream getFileAsStream(long companyId, long repositoryId, String fileName) throws PortalException
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
.
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's nameInputStream
object with the file's namePortalException
public static InputStream getFileAsStream(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
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
.
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's nameversionLabel
- the file's version labelInputStream
object with the file's namePortalException
public static String[] getFileNames(long companyId, long repositoryId, String dirName) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)dirName
- the directory's namePortalException
public static long getFileSize(long companyId, long repositoryId, String fileName) throws PortalException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's namePortalException
public static DLStore getStore()
DLStore
object. Used primarily by Spring and should
not be used by the client.DLStore
objectpublic static boolean hasFile(long companyId, long repositoryId, String fileName) throws PortalException
true
if the file exists.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's nametrue
if the file exists; false
otherwisePortalException
public static boolean hasFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException
true
if the file exists.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's nameversionLabel
- the file's version labeltrue
if the file exists; false
otherwisePortalException
public static void updateFile(long companyId, long repositoryId, long newRepositoryId, String fileName) throws PortalException
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 namePortalException
public static void updateFile(long companyId, long repositoryId, String fileName, String fileExtension, boolean validateFileExtension, String versionLabel, String sourceFileName, File file) throws PortalException
File
object.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namefileExtension
- the file's extensionvalidateFileExtension
- whether to validate the file's extensionversionLabel
- the file's new version labelsourceFileName
- the new file's original namefile
- Name the file namePortalException
public static void updateFile(long companyId, long repositoryId, String fileName, String fileExtension, boolean validateFileExtension, String versionLabel, String sourceFileName, InputStream inputStream) throws PortalException
InputStream
object.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file namefileExtension
- the file's extensionvalidateFileExtension
- whether to validate the file's extensionversionLabel
- the file's new version labelsourceFileName
- the new file's original nameinputStream
- the new file's dataPortalException
public static void updateFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) throws PortalException
copyFileVersion(long,
long, String, String, String)
except that the old file version is
deleted.companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants.SYSTEM
)fileName
- the file's namefromVersionLabel
- the file's version labeltoVersionLabel
- the file's new version labelPortalException
public static void validate(String fileName, boolean validateFileExtension) throws PortalException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensionPortalException
public static void validate(String fileName, boolean validateFileExtension, byte[] bytes) throws PortalException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensionbytes
- the file's data (optionally null
)PortalException
public static void validate(String fileName, boolean validateFileExtension, File file) throws PortalException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensionfile
- Name the file's namePortalException
public static void validate(String fileName, boolean validateFileExtension, InputStream inputStream) throws PortalException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensioninputStream
- the file's data (optionally null
)PortalException
public static void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension) throws PortalException
PortalException
public static void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension, File file) throws PortalException
fileName
- the file's namefileExtension
- the file's extensionsourceFileName
- the file's original namevalidateFileExtension
- whether to validate the file's extensionfile
- Name the file's namePortalException
public static void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension, InputStream inputStream) throws PortalException
fileName
- the file's namefileExtension
- the file's extensionsourceFileName
- the file's original namevalidateFileExtension
- whether to validate the file's extensioninputStream
- the file's data (optionally null
)PortalException