Copyright© 2008-2018 SiteVision AB, all rights reserved.
@Requireable(value="FileUtil") public interface FileUtil
sv:file
.
Note! This interface is used to create files. You would typically use
StructureUtil
to move a file
and TrashcanUtil
to delete a file.
To check MIME/Content-Type for a file you would typically use MimeTypeUtil
.
An instance of the SiteVision class implementing this interface can be obtained via Utils.getFileUtil()
.
See Utils
for how to obtain an instance of the Utils
interface.
Modifier and Type | Method and Description |
---|---|
Node |
createFile(Node aParent,
String aFileName,
String anUri)
Adds a file to a sv:localFileRepository, sv:fileRepository, sv:personalFileRepository or a sv:folder residing
as sub node to a file repository.
|
void |
createFiles(Node aParent,
java.util.Map<String,String> aFileMappings)
Adds several files to a sv:localFileRepository, sv:fileRepository, sv:personalFileRepository or a sv:folder
residing as sub node to a file repository.
|
String |
getContentAsString(Node aFile)
Gets the contents of a file as a String using the UTF-8 character encoding.
|
String |
getContentAsString(Node aFile,
String aCharacterEncoding)
Gets the contents of a file as a String using a given character encoding.
|
void |
updateBinaryContent(Node aFile,
String anUri)
Updates the binary content of an existing file.
|
void createFiles(Node aParent, java.util.Map<String,String> aFileMappings) throws ConstraintViolationException, RepositoryException
Adds several files to a sv:localFileRepository, sv:fileRepository, sv:personalFileRepository or a sv:folder residing as sub node to a file repository.
Files are specified by a map where the keys denotes the file names (will correspond to the property fileName of the sv:file nodes) and the values denotes the URIs pointing to the file resources. The file resources (i.e. the URIs) must be accessible from the SiteVision server. SiteVision opens a stream with the URI value when creating/uploading the binary content of the file. If a firewall or such blocks outgoing communication from the server - file creation will fail.
Permission note! Current user must be authorized to alter the parent node
(e.g. PermissionUtil.Permission.WRITE
).
A warning will be written to the system log if SiteVision for any reason is unable to create one of the files.
aParent
- the parent node for the filesaFileMappings
- a map of file name to URI pairsNullPointerException
- if aParent
or aFileMappings
is null
ConstraintViolationException
- if the user is not authorized to alter the parent node or if an invalid
parent node is specifiedRepositoryException
- if something else goes wrongNode createFile(Node aParent, String aFileName, String anUri) throws ConstraintViolationException, RepositoryException
Adds a file to a sv:localFileRepository, sv:fileRepository, sv:personalFileRepository or a sv:folder residing as sub node to a file repository.
Permission note! Current user must be authorized to alter the parent node
(e.g. PermissionUtil.Permission.WRITE
).
URI note! The file resource must be accessible from the SiteVision server! SiteVision opens
a stream to an URL with the anUri
value when creating/uploading the binary content of the file.
If a firewall or such blocks outgoing communication from the server - file creation will fail.
aParent
- the parent node of the fileaFileName
- the fileName property of the sv:fileanUri
- the URI pointing to the file resource retrievable from the SiteVision servernull
NullPointerException
- if aParent
, aFileName
or anUri
is null
ConstraintViolationException
- if the user is not authorized to alter the parent node or if an invalid
parent node is specifiedRepositoryException
- if something else goes wrongvoid updateBinaryContent(Node aFile, String anUri) throws ConstraintViolationException, RepositoryException
Properties related to the binary content will also be updated (e.g. length
). A new version will
be created if the binary content of a group file is updated.
URI note! The URI must be accessible from the SiteVision server and the ending part
of the URI must match the file extension of the existing file that should be updated! SiteVision opens
a stream to an URL with the anUri
value when uploading the binary content of the file.
If a firewall or such blocks outgoing communication from the server - file update will fail.
Permission note! Current user must be authorized to alter the file node that
should be updated (e.g. PermissionUtil.Permission.WRITE
).
aFile
- the fileanUri
- the URI pointing to the file resource to fetch new binary content fromConstraintViolationException
- if the user is not authorized to alter the file node,
if an invalid node is specified or if the end part of anUri
doesn't match the file extension
of aFile
RepositoryException
- if something else goes wrongString getContentAsString(Node aFile)
Note! This is mere a convenience method for getContentAsString(Node, String)
using UTF-8 as character encoding.
aFile
- the filegetContentAsString(Node, String)
String getContentAsString(Node aFile, String aCharacterEncoding)
Note! This method operates on character-based file nodes only! That is:
MimeTypeUtil.isTextType(String)
).
MimeTypeUtil.isXmlType(String)
).
aFile
- the fileaCharacterEncoding
- the character encoding (Note! UTF-8 will be used instead for null, empty and illegal/unsupported encoding)SiteVision - Portal and Content Management Made Easy
SiteVision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2018 SiteVision AB, all rights reserved.