public final class FileHelper extends AbstractLogEnabled implements Component, Serviceable
Modifier and Type | Field and Description |
---|---|
private static SourceResolver |
_srcResolver |
static String |
ROLE
The Avalon role name
|
Constructor and Description |
---|
FileHelper() |
Modifier and Type | Method and Description |
---|---|
private FileSource |
_addCollection(FileSource collection,
String name) |
private void |
_addZipEntry(FileSource collection,
ZipFile zipFile,
ZipArchiveEntry zipEntry,
String fileName) |
private void |
_unzip(FileSource destSrc,
ZipFile zipFile) |
Map<String,Object> |
addFolder(String parentURI,
String name,
boolean renameIfExists)
Create a folder
|
Map<String,Object> |
addOrUpdateFile(Part part,
FileSource parentDir,
String mode,
boolean unzip)
Add or update a file
|
Map<String,Object> |
copySource(String srcUri,
String parentTargetUri)
Copy a file or folder
|
Map<String,Object> |
deleteFile(String fileUri)
Remove a folder or a file
|
boolean |
hasChild(String parentUri,
String name)
Tests if a file/folder with given name exists
|
Map<String,Object> |
moveSource(String srcUri,
String parentTargetUri)
Move a file or folder
|
Map<String,Object> |
renameFile(String fileUri,
String name)
Rename a file or a folder
|
Map<String,Object> |
saveFile(String fileURI,
String text)
Saves text to given file in UTF-8 format
|
void |
service(ServiceManager serviceManager) |
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
private static SourceResolver _srcResolver
public FileHelper()
public void service(ServiceManager serviceManager) throws ServiceException
service
in interface Serviceable
ServiceException
public Map<String,Object> saveFile(String fileURI, String text) throws IOException
fileURI
- the file URI. Must point to an existing file.text
- the UTF-8 file contentIOException
- If an error occurred while savingpublic Map<String,Object> addFolder(String parentURI, String name, boolean renameIfExists) throws IOException
parentURI
- the parent URI, relative to the rootname
- the name of the new folder to createrenameIfExists
- true if the folder have to be renamed if the folder
with same name already exits.IOException
- If an error occurred adding the folderpublic Map<String,Object> addOrUpdateFile(Part part, FileSource parentDir, String mode, boolean unzip) throws IOException
part
- The file multipart to uploadparentDir
- The parent directorymode
- The insertion mode: 'add-rename' or 'update' or null.unzip
- true to unzip .zip fileIOException
- If an error occurred manipulating the fileprivate void _unzip(FileSource destSrc, ZipFile zipFile) throws IOException
IOException
private FileSource _addCollection(FileSource collection, String name) throws IOException
IOException
private void _addZipEntry(FileSource collection, ZipFile zipFile, ZipArchiveEntry zipEntry, String fileName) throws IOException
IOException
public Map<String,Object> deleteFile(String fileUri) throws IOException
fileUri
- the file/folder URIIOException
- If an error occurs while removing the folder/filepublic Map<String,Object> renameFile(String fileUri, String name) throws IOException
fileUri
- the relative URI of the file or folder to renamename
- the new name of the file/folderIOException
- if an error occurs while renaming the file/folderpublic boolean hasChild(String parentUri, String name) throws IOException
parentUri
- the parent folder URIname
- the name of the childIOException
- if an error occurredpublic Map<String,Object> copySource(String srcUri, String parentTargetUri) throws IOException
srcUri
- The URI of file/folder to copyparentTargetUri
- The URI of parent target fileIOException
- If an error occured manipulating the sourcepublic Map<String,Object> moveSource(String srcUri, String parentTargetUri) throws IOException
srcUri
- The URI of file/folder to moveparentTargetUri
- The URI of parent target fileIOException
- If an error occurred manipulating the source