Package org.silverpeas.core.io.upload
Class UploadSession
- java.lang.Object
-
- org.silverpeas.core.io.upload.UploadSession
-
public class UploadSession extends Object
A session of files and folders uploads. Each file is saved in a temporary folder in the server whose the name is derived from the session identifier. A user in Silverpeas can upload one or several files. For latter, in order to avoid to process each file one by one, theUploadSession
is a way to identify a set of uploaded files to process in a whole.The different treatments which use this mechanism must use all the services provided by
FileUploadManager
andUploadedFile
in order to save definitely the uploaded files.- Author:
- Yohann Chastagnier
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the session (deletes all the file from the server).static void
clearFrom(SessionInfo sessionInfo)
Clears the upload sessions still attached to a user session.UploadSession
forComponentInstanceId(String componentInstanceId)
Sets the identifier of the component instance associated with the files uploads session.static UploadSession
from(String uploadSessionId)
Initializes an instance from a session id (if not created, a new one will be created if necessary).static UploadSession
from(javax.servlet.http.HttpServletRequest request)
Initializes an instance from a request (if not created, a new one will be created if necessary).String
getComponentInstanceId()
Gets the component instance identifier if any.String
getComponentInstanceParameterValue(String parameterName)
Gets the parameter value of a component instance.String
getId()
Gets the session identifier.File
getRootFolder()
Gets the root folder on the server of the files upload session.
If the folder does not yet exist, then it is created.File[]
getRootFolderFiles()
Gets theFile
list (so file or folder) from the root folder on the server of the upload session.
If the folder does not yet exist, then it is created.UploadSessionFile
getUploadSessionFile(String fullPath)
Gets the file that was or will be uploaded within this session and located at the specified path relative the root folder of this session.boolean
isUserAuthorized(String componentInstanceId)
Indicates if the current user is authorized to perform this files upload session in the context of the given component instance.boolean
remove(String fullPath)
Removes from the upload session the file identified by the given identifier.
-
-
-
Method Detail
-
forComponentInstanceId
public UploadSession forComponentInstanceId(String componentInstanceId)
Sets the identifier of the component instance associated with the files uploads session.- Parameters:
componentInstanceId
- the unique identifier of an existing component instance.
-
isUserAuthorized
public boolean isUserAuthorized(String componentInstanceId)
Indicates if the current user is authorized to perform this files upload session in the context of the given component instance.- Parameters:
componentInstanceId
- the unique identifier of a component instance.
-
getId
public String getId()
Gets the session identifier.- Returns:
- a string.
-
getComponentInstanceId
public String getComponentInstanceId()
Gets the component instance identifier if any.- Returns:
- a string.
-
getComponentInstanceParameterValue
public String getComponentInstanceParameterValue(String parameterName)
Gets the parameter value of a component instance. The component instance is the one set in this session. If no component instance identifier has been set, then nothing is done.- Returns:
- a string that represents the parameter value or an empty value if either the component instance identifier is unknown or the parameter is not defined for the component instance.
-
clear
public void clear()
Clears the session (deletes all the file from the server).
-
remove
public boolean remove(String fullPath)
Removes from the upload session the file identified by the given identifier. If the file path is currently in writing mode, nothing is removed.- Parameters:
fullPath
- the path of the file into the session.- Returns:
- true of removed has been effective, false otherwise.
-
getUploadSessionFile
public UploadSessionFile getUploadSessionFile(String fullPath)
Gets the file that was or will be uploaded within this session and located at the specified path relative the root folder of this session. If the file path is currently in writing mode, theUploadSessionFile.getServerFile()
of the returned instance is null.- Parameters:
fullPath
- the path of the file relative to the root folder of the session.- Returns:
- the
UploadSessionFile
instance at the specified relative path.
-
getRootFolder
public File getRootFolder()
Gets the root folder on the server of the files upload session.
If the folder does not yet exist, then it is created.- Returns:
- a
File
that represents the upload session folder.
-
getRootFolderFiles
public File[] getRootFolderFiles()
Gets theFile
list (so file or folder) from the root folder on the server of the upload session.
If the folder does not yet exist, then it is created.- Returns:
- a list of
File
from the root folder provided bygetRootFolder()
.
-
from
public static UploadSession from(javax.servlet.http.HttpServletRequest request)
Initializes an instance from a request (if not created, a new one will be created if necessary).- Parameters:
request
- an http servlet request.- Returns:
- a new initialized instance.
-
from
public static UploadSession from(String uploadSessionId)
Initializes an instance from a session id (if not created, a new one will be created if necessary).- Parameters:
uploadSessionId
- an existing, or not, upload session id.- Returns:
- a new initialized instance.
-
clearFrom
public static void clearFrom(SessionInfo sessionInfo)
Clears the upload sessions still attached to a user session.- Parameters:
sessionInfo
- the session of a user.
-
-