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 |
bundle, dms
Constructor and Description |
---|
FilesPlugin() |
Modifier and Type | Method and Description |
---|---|
private File |
absolutePath(String repoPath)
Maps a repository path to an absolute path.
|
private void |
checkAuthorization(File path,
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 path)
Creates a file in the file repository, and creates 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 path)
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 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(File path)
Fetches the File topic representing the file at the given absolute path.
|
private Topic |
fetchFolderTopic(File path)
Fetches the Folder topic representing the folder at the given absolute path.
|
private Topic |
fetchTopic(File path,
String topicTypeUri)
Fetches the File/Folder topic representing the file/directory at the given absolute path.
|
Topic |
getChildFileTopic(long folderTopicId,
String path)
Returns the File topic representing the file at a given repository path.
|
Topic |
getChildFolderTopic(long folderTopicId,
String path)
Returns the Folder topic representing the folder at a given repository path.
|
DirectoryListing |
getDirectoryListing(String path) |
File |
getFile(long fileTopicId)
Accesses a file/directory in the file repository that is represented by the given File/Folder topic.
|
File |
getFile(String path)
Accesses a file/directory in the file repository by the given repository path.
|
Topic |
getFileTopic(String path)
Returns the File topic representing the file at a given repository path.
|
Topic |
getFolderTopic(String path)
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 path) |
private long |
getWorkspaceId() |
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.
|
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) |
void |
resourceRequestFilter(javax.servlet.http.HttpServletRequest request) |
void |
shutdown() |
StoredFile |
storeFile(UploadedFile file,
String path)
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, toString
public 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 Pattern PER_WORKSPACE_PATH_PATTERN
public static DeepaMehtaEvent CHECK_DISK_QUOTA
private ConfigService configService
public FilesPlugin()
public Topic getFileTopic(String path)
FilesService
getFileTopic
in interface FilesService
path
- A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.public Topic getFolderTopic(String path)
FilesService
getFolderTopic
in interface FilesService
path
- A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.public Topic getChildFileTopic(long folderTopicId, String path)
FilesService
Creates 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 FilesService
folderTopicId
- ID of the parent Folder topic.path
- A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.public Topic getChildFolderTopic(long folderTopicId, String path)
FilesService
Creates 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 FilesService
folderTopicId
- ID of the parent Folder topic.path
- A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.public StoredFile storeFile(UploadedFile file, String path)
FilesService
storeFile
in interface FilesService
path
- The directory where to store the uploaded file.
A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
The directory must exist.public Topic createFile(InputStream in, String path)
FilesService
createFile
in interface FilesService
in
- The input stream the file content is read from.path
- The path and filename of the file to be created.
A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.
If that file exists already it is overwritten. ### TODO: rethink overwritingpublic void createFolder(String folderName, String path)
FilesService
createFolder
in interface FilesService
path
- 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.public ResourceInfo getResourceInfo(String path)
getResourceInfo
in interface FilesService
public DirectoryListing getDirectoryListing(String path)
getDirectoryListing
in interface FilesService
public String getRepositoryPath(URL url)
FilesService
getRepositoryPath
in interface FilesService
null
if the URL
does not refer to the file repository of this DeepaMehta installation.public File getFile(String path)
FilesService
getFile
in interface FilesService
path
- A repository path. Relative to the repository base path.
Must begin with slash, no slash at the end.public File getFile(long fileTopicId)
FilesService
getFile
in interface FilesService
public void openFile(long fileTopicId)
openFile
in interface FilesService
public void preInstall()
preInstall
in interface PluginContext
preInstall
in class PluginActivator
public void init()
init
in interface PluginContext
init
in class PluginActivator
public void shutdown()
shutdown
in interface PluginContext
shutdown
in class PluginActivator
public void resourceRequestFilter(javax.servlet.http.HttpServletRequest request)
resourceRequestFilter
in interface ResourceRequestFilterListener
public String repoPath(File path)
PathMapper
repoPath
in interface PathMapper
path
- An absolute path.private Topic fetchFileTopic(File path)
null
is returned.path
- An absolute path.private Topic fetchFolderTopic(File path)
null
is returned.path
- An absolute path.private Topic fetchTopic(File path, String topicTypeUri)
null
is returned.path
- An absolute path.topicTypeUri
- The type of the topic to fetch: either "dm4.files.file" or "dm4.files.folder".private Topic createFileTopic(File path) throws Exception
path
- An absolute path.Exception
private Topic createFolderTopic(File path) throws Exception
path
- An absolute path.Exception
private Topic createFileOrFolderTopic(TopicModel model) throws Exception
Exception
private 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.FileRepositoryException
private long getWorkspaceId()
private void createWorkspaceFileRepository(File repo)
private File checkPath(File path) throws FileRepositoryException, IOException
path
- The absolute path to check.FileRepositoryException
IOException
private void checkExistence(File path) throws FileRepositoryException
FileRepositoryException
private void checkAuthorization(File path, String repoPath, javax.servlet.http.HttpServletRequest request) throws FileRepositoryException
path
- The absolute path of the file to check (as calculated already from the repository path).repoPath
- The repository path of the file to check.request
- The request.FileRepositoryException
private 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.
An absolute path.private String repoPath(long fileTopicId)
Copyright © 2015. All Rights Reserved.