Package org.silverpeas.core.util.file
Class FileRepositoryManager
- java.lang.Object
-
- org.silverpeas.core.util.file.FileRepositoryManager
-
public class FileRepositoryManager extends Object
Provides useful methods to handle files and directories in the Silverpeas specific filesystem.- Author:
- Norbert CHAIX
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyFile(String from, String to)
Copy the specified file content to the given other.static void
createAbsolutePath(String componentId, String directoryName)
Creates the specified directory into the upload directory of the given component instance.static void
createGlobalTempPath(String sDirectoryName)
Creates the specified directory into the temporary directory of Silverpeas.static void
deleteAbsolutePath(String sComponentId, String sDirectoryName)
Deletes the specified directory in the upload directory of the specified component instance.static String
formatFileSize(long lSize)
Get the file size with the suitable unitstatic String
formatFileUploadTime(long time)
Format the specified time with its unit.static String
getAbsolutePath(String sComponentId)
Gets the absolute path of the upload directory associated to the specified Silverpeas component instance.static String
getAbsolutePath(String componentId, String[] relativeDirectoryPath)
Gets the absolute path of the specified path relative to the upload directory of the given component instance.static String[]
getAttachmentContext(String str)
to create the array of the string this array represents the repertories where the files must be stored.static String
getAvatarPath()
Gets the path of the root directory into which are located the users avatars.static <T> long
getDirectorySize(Collection<T> directories)
Computes as fast as possible the size of a given directory list.static <T> long
getDirectorySize(T directory)
Computes as fast as possible the size of a given directory.static String
getDomainAuthenticationPropertiesPath(String domainName)
Gets the absolute path of the authentication descriptor of the specified user domain.static String
getDomainPropertiesPath(String domainName)
Gets the absolute path of the descriptor of the specified user domain.static String
getExportTemplateRepository()
Gets the path of the repository that contains the templates to use in exports.static String
getFileDownloadTime(long size)
Get the estimated download time for a given file size.static String
getFileExtension(String fileName)
static String
getFileIcon(boolean small, String filename)
Gets the path of the small or not version of the specified icon in the icons root directory.static String
getFileIcon(String extension)
Gets the path of the specified icon in the icons root directory.static long
getFileSize(String sourceFile)
Get the size of a file (in bytes)static String
getInitDataDirPath()
Gets the path of the directory of initialization data with which someInitialization
services can use to persist their data required for their work.static String
getSecurityDirPath()
Gets the path of the directory in which all the resources related to the security in Silverpeas are stored.static String
getTemporaryPath()
Gets the temporary path of Silverpeas.static long
getUploadMaximumFileSize()
Gets the file size limit for an upload.static String
getUploadPath()
Gets the path of the repository into which attachments and other files are uploaded in Silverpeas.
-
-
-
Method Detail
-
getSecurityDirPath
public static String getSecurityDirPath()
Gets the path of the directory in which all the resources related to the security in Silverpeas are stored.- Returns:
- the path of the Silverpeas security directory.
-
getInitDataDirPath
public static String getInitDataDirPath()
Gets the path of the directory of initialization data with which someInitialization
services can use to persist their data required for their work.- Returns:
- the path of the directory of initialization data.
-
getAbsolutePath
public static String getAbsolutePath(String sComponentId)
Gets the absolute path of the upload directory associated to the specified Silverpeas component instance.- Parameters:
sComponentId
- the unique identifier of the component instance.- Returns:
- the upload directory absolute path of the given component instance.
-
getAvatarPath
public static String getAvatarPath()
Gets the path of the root directory into which are located the users avatars.- Returns:
- the absolute path of the user avatars.
-
getUploadPath
public static String getUploadPath()
Gets the path of the repository into which attachments and other files are uploaded in Silverpeas.- Returns:
- the path of the root repository for uploads.
-
getAbsolutePath
public static String getAbsolutePath(String componentId, String[] relativeDirectoryPath)
Gets the absolute path of the specified path relative to the upload directory of the given component instance.- Parameters:
componentId
- the unique identifier of a component instance.relativeDirectoryPath
- the relative path of a directory- Returns:
- the absolute path of the directory.
-
getTemporaryPath
public static String getTemporaryPath()
Gets the temporary path of Silverpeas.- Returns:
- the temporary path used by Silverpeas.
- Implementation Note:
- the returned path ends with the path separator.
-
getDomainPropertiesPath
public static String getDomainPropertiesPath(String domainName)
Gets the absolute path of the descriptor of the specified user domain.- Parameters:
domainName
- the name of a user domain.- Returns:
- the path of the domain properties file.
-
getDomainAuthenticationPropertiesPath
public static String getDomainAuthenticationPropertiesPath(String domainName)
Gets the absolute path of the authentication descriptor of the specified user domain.- Parameters:
domainName
- the name of a user domain.- Returns:
- the path of the domain authentication properties file.
-
createAbsolutePath
public static void createAbsolutePath(String componentId, String directoryName)
Creates the specified directory into the upload directory of the given component instance.- Parameters:
componentId
- the unique identifier of a component instance.directoryName
- the name of the directory to create.
-
createGlobalTempPath
public static void createGlobalTempPath(String sDirectoryName)
Creates the specified directory into the temporary directory of Silverpeas.- Parameters:
sDirectoryName
- the name of the directory to create.
-
deleteAbsolutePath
public static void deleteAbsolutePath(String sComponentId, String sDirectoryName)
Deletes the specified directory in the upload directory of the specified component instance. All the content of the directory to delete will be also deleted.- Parameters:
sComponentId
- the unique identifier of a component instance.sDirectoryName
- the name of the directory to delete.
-
getFileIcon
public static String getFileIcon(String extension)
Gets the path of the specified icon in the icons root directory.- Parameters:
extension
- the name of the icon.- Returns:
- the path of the icon.
-
getFileIcon
public static String getFileIcon(boolean small, String filename)
Gets the path of the small or not version of the specified icon in the icons root directory.- Parameters:
small
- a flag indicating if the path of a small version of the icon has to be returned.filename
- the name of the icon.- Returns:
- the path of the icon.
-
formatFileSize
public static String formatFileSize(long lSize)
Get the file size with the suitable unit- Parameters:
lSize
- a size- Returns:
- a size with its unit.
-
getFileSize
public static long getFileSize(String sourceFile)
Get the size of a file (in bytes)- Parameters:
sourceFile
- the file- Returns:
- the size of the file in bytes
-
getDirectorySize
public static <T> long getDirectorySize(Collection<T> directories)
Computes as fast as possible the size of a given directory list.- Parameters:
directories
- a list of directory.- Returns:
- the size of given directory list as long.
-
getDirectorySize
public static <T> long getDirectorySize(T directory)
Computes as fast as possible the size of a given directory.- Parameters:
directory
- a directory.- Returns:
- the size of given directory as long.
-
getFileDownloadTime
public static String getFileDownloadTime(long size)
Get the estimated download time for a given file size.- Parameters:
size
- a file size in bytes.- Returns:
- the estimated download time with its unit.
-
getUploadMaximumFileSize
public static long getUploadMaximumFileSize()
Gets the file size limit for an upload.- Returns:
- the size limit in bytes
-
copyFile
public static void copyFile(String from, String to) throws IOException
Copy the specified file content to the given other.- Parameters:
from
- The name of the source file, the one to copy.to
- The name of the destination file, where to paste data.- Throws:
IOException
- if an error occurs while copying the file.
-
formatFileUploadTime
public static String formatFileUploadTime(long time)
Format the specified time with its unit.- Parameters:
time
- the upload time in milliseconds.- Returns:
- the formatted time with its unit.
-
getAttachmentContext
public static String[] getAttachmentContext(String str)
to create the array of the string this array represents the repertories where the files must be stored.- Parameters:
str
- the string of repertories- Returns:
- the attachment context
-
getExportTemplateRepository
public static String getExportTemplateRepository()
Gets the path of the repository that contains the templates to use in exports.- Returns:
- the path of the export template repository.
-
-