public class FilesPlugin extends PluginActivator implements FilesService, ResourceRequestFilterListener, PathMapper
| Modifier and Type | Field and Description |
|---|---|
static DeepaMehtaEvent |
CHECK_DISK_QUOTA |
private ConfigService |
configService |
static int |
DISK_QUOTA_MB |
static String |
FILE_REPOSITORY_PATH |
static boolean |
FILE_REPOSITORY_PER_WORKSPACE |
private static String |
FILE_REPOSITORY_URI |
private Logger |
logger |
private static Pattern |
PER_WORKSPACE_PATH_PATTERN |
private static String |
WORKSPACE_DIRECTORY_PREFIX |
bundle, dm4, mf| Constructor and Description |
|---|
FilesPlugin() |
| Modifier and Type | Method and Description |
|---|---|
private String |
_pathPrefix(long workspaceId) |
private File |
absolutePath(String repoPath)
Maps a repository path to an absolute path.
|
private void |
checkAuthorization(String repoPath,
javax.servlet.http.HttpServletRequest request)
Checks if the user associated with a request is authorized to access a repository file.
|
private void |
checkExistence(File path) |
private File |
checkPath(File path)
Checks if the absolute path represents a directory traversal attack.
|
Topic |
createFile(InputStream in,
String repoPath)
Creates a file in the file repository and a corresponding File topic.
|
private Topic |
createFileOrFolderTopic(TopicModel model) |
private Topic |
createFileTopic(File path)
Creates a File topic representing the file at the given absolute path.
|
void |
createFolder(String folderName,
String repoPath)
Creates a folder in the file repository.
|
private void |
createFolderAssociation(long folderTopicId,
Topic topic) |
private Topic |
createFolderTopic(File path)
Creates a Folder topic representing the directory at the given absolute path.
|
private Topic |
createFolderTopic(String folderName,
String repoPath)
Creates a Folder topic.
|
private void |
createWorkspaceAssignment(DeepaMehtaObject object,
String repoPath)
Creates a workspace assignment for a File topic, a Folder topic, or a folder association (type "Aggregation").
|
private void |
createWorkspaceFileRepository(File repo) |
private Topic |
fetchFileTopic(String repoPath)
Fetches the File topic representing the file at the given repository path.
|
private Topic |
fetchFolderTopic(String repoPath)
Fetches the Folder topic representing the folder at the given repository path.
|
private Topic |
fetchTopic(String repoPath,
String topicTypeUri)
Fetches the File/Folder topic representing the file/directory at the given repository path.
|
boolean |
fileExists(String repoPath)
Checks if a file/directory with the given repository path exists in the file repository.
|
Topic |
getChildFileTopic(long folderTopicId,
String repoPath)
Returns the File topic representing the file at a given repository path.
|
Topic |
getChildFolderTopic(long folderTopicId,
String repoPath)
Returns the Folder topic representing the folder at a given repository path.
|
DirectoryListing |
getDirectoryListing(String repoPath) |
File |
getFile(long fileTopicId)
Convenience method to access the file/directory in the file repository that is represented by the given
File/Folder topic.
|
File |
getFile(String repoPath)
Accesses a file/directory in the file repository by the given repository path.
|
Topic |
getFileTopic(String repoPath)
Returns the File topic representing the file at a given repository path.
|
Topic |
getFolderTopic(String repoPath)
Returns the Folder topic representing the folder at a given repository path.
|
String |
getRepositoryPath(URL url)
Checks if the given URL refers to the file repository of this DeepaMehta installation.
|
ResourceInfo |
getResourceInfo(String repoPath) |
private long |
getWorkspaceId() |
private long |
getWorkspaceId(String repoPath) |
void |
init() |
void |
openFile(long fileTopicId) |
private File |
path(File directory,
String fileName)
Constructs an absolute path from an absolute path and a file name.
|
String |
pathPrefix()
Returns a prefix that can be used for constructing a repository path.
|
String |
pathPrefix(long workspaceId)
Returns a prefix that can be used for constructing a repository path.
|
void |
preInstall() |
String |
repoPath(File path)
Maps an absolute path to a repository path.
|
String |
repoPath(javax.servlet.http.HttpServletRequest request)
Returns the repository path of a filerepo request.
|
private String |
repoPath(long fileTopicId)
Returns the repository path of a File/Folder topic.
|
private String |
repoPath(Topic topic)
Returns the repository path of a File/Folder topic.
|
void |
resourceRequestFilter(javax.servlet.http.HttpServletRequest request) |
void |
shutdown() |
StoredFile |
storeFile(UploadedFile file,
String repoPath)
Receives an uploaded file, stores it in the file repository, and creates a corresponding File topic.
|
private File |
unusedPath(File directory,
UploadedFile file)
Constructs an absolute path for storing an uploaded file.
|
private String |
userInfo(String username) |
getBundleContext, getPluginName, getStaticResource, getUri, publishFileSystem, serviceArrived, serviceGone, setCoreService, start, stop, toStringpublic static final String FILE_REPOSITORY_PATH
public static final boolean FILE_REPOSITORY_PER_WORKSPACE
public static final int DISK_QUOTA_MB
private static final String FILE_REPOSITORY_URI
private static final String WORKSPACE_DIRECTORY_PREFIX
private static final Pattern PER_WORKSPACE_PATH_PATTERN
public static DeepaMehtaEvent CHECK_DISK_QUOTA
private ConfigService configService
public FilesPlugin()
public Topic getFileTopic(String repoPath)
FilesServicegetFileTopic in interface FilesServicerepoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public Topic getFolderTopic(String repoPath)
FilesServicegetFolderTopic in interface FilesServicerepoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public Topic getChildFileTopic(long folderTopicId, String repoPath)
FilesServiceCreates an association (type "Aggregation") between the File topic (role type "Child") and its parent Folder topic (role type "Parent"), if not exists already.
getChildFileTopic in interface FilesServicefolderTopicId - ID of the parent Folder topic.repoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public Topic getChildFolderTopic(long folderTopicId, String repoPath)
FilesServiceCreates an association (type "Aggregation") between the Folder topic (role type "Child") and its parent Folder topic (role type "Parent"), if not exists already.
getChildFolderTopic in interface FilesServicefolderTopicId - ID of the parent Folder topic.repoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public StoredFile storeFile(UploadedFile file, String repoPath)
FilesServicestoreFile in interface FilesServicerepoPath - The directory where to store the uploaded file.
The directory must exist.
A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public Topic createFile(InputStream in, String repoPath)
FilesServicecreateFile in interface FilesServicein - The input stream the file content is read from.repoPath - The path and filename of the file to be created.
If that file exists already it is overwritten. ### TODO: rethink overwriting
A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public void createFolder(String folderName, String repoPath)
FilesServicecreateFolder in interface FilesServicerepoPath - The directory where to create the folder.
A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public ResourceInfo getResourceInfo(String repoPath)
getResourceInfo in interface FilesServicepublic DirectoryListing getDirectoryListing(String repoPath)
getDirectoryListing in interface FilesServicepublic String getRepositoryPath(URL url)
FilesServicegetRepositoryPath in interface FilesServicenull if the URL
does not refer to the file repository of this DeepaMehta installation.public File getFile(String repoPath)
FilesServiceNote: this method does not require the corresponding File/Folder topic to exist.
getFile in interface FilesServicerepoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
public File getFile(long fileTopicId)
FilesServicegetFile in interface FilesServicefileTopicId - ID of a File/Folder topic.public boolean fileExists(String repoPath)
FilesServicefileExists in interface FilesServicerepoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If per-workspace file repos are active (dm4.filerepo.per_workspace=true)
the repository path must contain the workspace prefix as the first path segment,
e.g. "/workspace-1234" where 1234 is the workspace ID.
However there is one exception to that rule: if and only if "/" is passed
as the repository path the workspace prefix is determined automatically with the
semantics of current workspace, based on the request's workspace cookie.
For support with constructing a repository path see the pathPrefix methods.
true if the file exists, false otherwise.public String pathPrefix()
FilesServicedm4.filerepo.per_workspace=true) the prefix
represents the current workspace (e.g. "/workspace-1234"), based on the workspace cookie.
In case of per-workspace file repos are not active an empty string is returned.pathPrefix in interface FilesServicepublic String pathPrefix(long workspaceId)
FilesServicedm4.filerepo.per_workspace=true) the prefix
represents the given workspace (e.g. "/workspace-1234").
In case of per-workspace file repos are not active an empty string is returned.pathPrefix in interface FilesServicepublic void openFile(long fileTopicId)
openFile in interface FilesServicepublic void preInstall()
preInstall in interface PluginContextpreInstall in class PluginActivatorpublic void init()
init in interface PluginContextinit in class PluginActivatorpublic void shutdown()
shutdown in interface PluginContextshutdown in class PluginActivatorpublic void resourceRequestFilter(javax.servlet.http.HttpServletRequest request)
resourceRequestFilter in interface ResourceRequestFilterListenerpublic String repoPath(File path)
PathMapperrepoPath in interface PathMapperpath - A canonized absolute path.private Topic fetchFileTopic(String repoPath)
null is returned.repoPath - A repository path. Must be canonized.private Topic fetchFolderTopic(String repoPath)
null is returned.repoPath - A repository path. Must be canonized.private Topic fetchTopic(String repoPath, String topicTypeUri)
null is returned.repoPath - A repository path. Must be canonized.topicTypeUri - The type of the topic to fetch: either "dm4.files.file" or "dm4.files.folder".private Topic createFileTopic(File path) throws Exception
path - A canonized absolute path.Exceptionprivate Topic createFolderTopic(File path) throws Exception
path - A canonized absolute path.Exceptionprivate Topic createFolderTopic(String folderName, String repoPath) throws Exception
folderName - The folder name.repoPath - The folder repository path.Exceptionprivate Topic createFileOrFolderTopic(TopicModel model) throws Exception
Exceptionprivate void createFolderAssociation(long folderTopicId, Topic topic)
topic - a File topic, or a Folder topic.private void createWorkspaceAssignment(DeepaMehtaObject object, String repoPath)
object - a File topic, a Folder topic, or a folder association (type "Aggregation").private File absolutePath(String repoPath) throws FileRepositoryException
repoPath - A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.FileRepositoryExceptionprivate File checkPath(File path) throws FileRepositoryException, IOException
path - The absolute path to check.FileRepositoryExceptionIOExceptionprivate void checkExistence(File path) throws FileRepositoryException
FileRepositoryExceptionprivate void checkAuthorization(String repoPath, javax.servlet.http.HttpServletRequest request) throws FileRepositoryException
repoPath - The repository path of the file to check. Must be canonized.request - The request.FileRepositoryExceptionprivate File path(File directory, String fileName)
directory - An absolute path.private File unusedPath(File directory, UploadedFile file)
directory - The directory to store the uploaded file to.
A canonized absolute path.private String repoPath(long fileTopicId)
private String repoPath(Topic topic)
public String repoPath(javax.servlet.http.HttpServletRequest request)
null if the request is not a filerepo request.
Note: the returned path is not canonized.private void createWorkspaceFileRepository(File repo)
private long getWorkspaceId()
private long getWorkspaceId(String repoPath)
private String _pathPrefix(long workspaceId)
Copyright © 2016. All Rights Reserved.