|
Liferay 6.1.2-ce-ga3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.liferay.portlet.documentlibrary.store.DLStoreUtil
public class 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 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 (DuplicateDirectoryException dde) {
}
DLStoreUtil.addFile(
companyId, repositoryId, dirName + "/" + fileName, file);
DLStoreImpl
Constructor Summary | |
---|---|
DLStoreUtil()
|
Method Summary | |
---|---|
static void |
addDirectory(long companyId,
long repositoryId,
String dirName)
Adds a directory. |
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 is)
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 is)
Adds a file based on an InputStream object. |
static void |
checkRoot(long companyId)
Ensures company's root directory exists. |
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 File |
getFile(long companyId,
long repositoryId,
String fileName)
Returns the file as a File object. |
static File |
getFile(long companyId,
long repositoryId,
String fileName,
String versionLabel)
Returns the file as a File object. |
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 |
hasDirectory(long companyId,
long repositoryId,
String dirName)
Returns true if the directory exists. |
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. |
static void |
move(String srcDir,
String destDir)
Moves an existing directory. |
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 newFileName)
Update's the file's name |
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 is)
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 is)
Validates a file's name and data. |
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 is)
Validates a file's name and data. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DLStoreUtil()
Method Detail |
---|
public static void addDirectory(long companyId, long repositoryId, String dirName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)dirName
- the directory's name
PortalException
- if the directory's information was invalid
SystemException
- if a system exception occurredpublic static void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension, byte[] bytes) throws PortalException, SystemException
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 data
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension, File file) throws PortalException, SystemException
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 name
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void addFile(long companyId, long repositoryId, String fileName, boolean validateFileExtension, InputStream is) throws PortalException, SystemException
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 extensionis
- the files's data
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void addFile(long companyId, long repositoryId, String fileName, byte[] bytes) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)fileName
- the file namebytes
- the files's data
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void addFile(long companyId, long repositoryId, String fileName, File file) throws PortalException, SystemException
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 name
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void addFile(long companyId, long repositoryId, String fileName, InputStream is) throws PortalException, SystemException
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 nameis
- the files's data
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void checkRoot(long companyId) throws SystemException
JCRStore.checkRoot(long)
.
companyId
- the primary key of the company
SystemException
- if a system exception occurredpublic static void copyFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) throws PortalException, SystemException
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 label
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void deleteDirectory(long companyId, long repositoryId, String dirName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)dirName
- the directory's name
PortalException
- if the directory's information was invalid
SystemException
- if a system exception occurredpublic static void deleteFile(long companyId, long repositoryId, String fileName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)fileName
- the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void deleteFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException
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 label
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static File getFile(long companyId, long repositoryId, String fileName) throws PortalException, SystemException
File
object.
This method is useful when optimizing low-level file operations like
copy. The client must not delete or change the returned File
object in any way. This method is only supported in certain stores. If
not supported, this method will throw an UnsupportedOperationException
.
If using an S3 store, it is preferable for performance reasons to use
getFileAsStream(long, long, String)
instead of this method
wherever possible.
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)fileName
- the file's name
File
object with the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static File getFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException
File
object.
This method is useful when optimizing low-level file operations like
copy. The client must not delete or change the returned File
object in any way. This method is only supported in certain stores. If
not supported, this method will throw an UnsupportedOperationException
.
If using an S3 store, it is preferable for performance reasons to use
getFileAsStream(long, long, String, String)
instead of this
method wherever possible.
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 label
File
object with the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static byte[] getFileAsBytes(long companyId, long repositoryId, String fileName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)fileName
- the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static byte[] getFileAsBytes(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException
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 label
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static InputStream getFileAsStream(long companyId, long repositoryId, String fileName) throws PortalException, SystemException
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 name
InputStream
object with the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static InputStream getFileAsStream(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException
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 label
InputStream
object with the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static String[] getFileNames(long companyId, long repositoryId, String dirName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)dirName
- the directory's name
PortalException
- if the directory's information was invalid
SystemException
- if a system exception occurredpublic static long getFileSize(long companyId, long repositoryId, String fileName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)fileName
- the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static DLStore getStore()
DLStore
object. Used primarily by Spring and should
not be used by the client.
DLStore
objectpublic static boolean hasDirectory(long companyId, long repositoryId, String dirName) throws PortalException, SystemException
true
if the directory exists.
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)dirName
- the directory's name
true
if the directory exists; false
otherwise
PortalException
- if the directory's information was invalid
SystemException
- if a system exception occurredpublic static boolean hasFile(long companyId, long repositoryId, String fileName) throws PortalException, SystemException
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 name
true
if the file exists; false
otherwise
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static boolean hasFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException
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 label
true
if the file exists; false
otherwise
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void move(String srcDir, String destDir) throws SystemException
JCRStore.move(String, String)
.
srcDir
- the original directory's namedestDir
- the new directory's name
SystemException
- if a system exception occurredpublic static void updateFile(long companyId, long repositoryId, long newRepositoryId, String fileName) throws PortalException, SystemException
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
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void updateFile(long companyId, long repositoryId, String fileName, String newFileName) throws PortalException, SystemException
companyId
- the primary key of the companyrepositoryId
- the primary key of the data repository (optionally
CompanyConstants#SYSTEM
)fileName
- the file's namenewFileName
- the file's new name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void updateFile(long companyId, long repositoryId, String fileName, String fileExtension, boolean validateFileExtension, String versionLabel, String sourceFileName, File file) throws PortalException, SystemException
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 name
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void updateFile(long companyId, long repositoryId, String fileName, String fileExtension, boolean validateFileExtension, String versionLabel, String sourceFileName, InputStream is) throws PortalException, SystemException
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 nameis
- the new file's data
PortalException
- if the file's information was invalid or is found
to contain a virus
SystemException
- if a system exception occurredpublic static void updateFileVersion(long companyId, long repositoryId, String fileName, String fromVersionLabel, String toVersionLabel) throws PortalException, SystemException
#copyFileVersion(long,
long, String, 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 label
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void validate(String fileName, boolean validateFileExtension) throws PortalException, SystemException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extension
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void validate(String fileName, boolean validateFileExtension, byte[] bytes) throws PortalException, SystemException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensionbytes
- the file's data (optionally null
)
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void validate(String fileName, boolean validateFileExtension, File file) throws PortalException, SystemException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensionfile
- Name the file's name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void validate(String fileName, boolean validateFileExtension, InputStream is) throws PortalException, SystemException
fileName
- the file's namevalidateFileExtension
- whether to validate the file's extensionis
- the file's data (optionally null
)
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension, File file) throws PortalException, SystemException
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 name
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic static void validate(String fileName, String fileExtension, String sourceFileName, boolean validateFileExtension, InputStream is) throws PortalException, SystemException
fileName
- the file's namefileExtension
- the file's extensionsourceFileName
- the file's original namevalidateFileExtension
- whether to validate the file's extensionis
- the file's data (optionally null
)
PortalException
- if the file's information was invalid
SystemException
- if a system exception occurredpublic void setStore(DLStore store)
DLStore
object. Used primarily by Spring and should not
be used by the client.
store
- the DLStore
object
|
Liferay 6.1.2-ce-ga3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |