Class FilesPlugin
- java.lang.Object
-
- systems.dmx.core.osgi.PluginActivator
-
- systems.dmx.files.FilesPlugin
-
- All Implemented Interfaces:
org.osgi.framework.BundleActivator
,PluginContext
,StaticResourceFilter
,EventListener
,FilesService
public class FilesPlugin extends PluginActivator implements FilesService, StaticResourceFilter
-
-
Field Summary
Fields Modifier and Type Field Description static DMXEvent
CHECK_DISK_QUOTA
-
Fields inherited from class systems.dmx.core.osgi.PluginActivator
bundle, dmx, mf
-
-
Constructor Summary
Constructors Constructor Description FilesPlugin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Topic
createFile(InputStream in, String repoPath)
Creates a file in the file repository and a corresponding File topic.RelatedTopic
createFolder(String folderName, String repoPath)
Creates a folder in the file repository.boolean
fileExists(String repoPath)
Checks if a file/directory with the given repository path exists in the file repository.RelatedTopic
getChildFileTopic(long folderTopicId, String repoPath)
Returns the File topic representing the file at a given repository path.RelatedTopic
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 DMX installation.ResourceInfo
getResourceInfo(String repoPath)
void
init()
int
openFile(long fileTopicId)
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.String
repoPath(File path)
void
staticResourceFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
StoredFile
storeFile(UploadedFile file, String repoPath)
Receives an uploaded file, stores it in the file repository, and creates a corresponding File topic.-
Methods inherited from class systems.dmx.core.osgi.PluginActivator
getBundleContext, getPluginName, getStaticResource, getUri, preInstall, publishFileSystem, serviceArrived, serviceGone, setCoreService, shutdown, start, stop, toString
-
-
-
-
Field Detail
-
CHECK_DISK_QUOTA
public static DMXEvent CHECK_DISK_QUOTA
-
-
Method Detail
-
getFileTopic
public Topic getFileTopic(String repoPath)
Description copied from interface:FilesService
Returns the File topic representing the file at a given repository path. If no such File topic exists it is created.- Specified by:
getFileTopic
in interfaceFilesService
- Parameters:
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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
- The File topic. Its child topics ("File Name", "Path", "Media Type", "Size") are included.
-
getFolderTopic
public Topic getFolderTopic(String repoPath)
Description copied from interface:FilesService
Returns the Folder topic representing the folder at a given repository path. If no such Folder topic exists it is created.- Specified by:
getFolderTopic
in interfaceFilesService
- Parameters:
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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
- The Folder topic. Its child topics ("Folder Name", "Path") are included.
-
getChildFileTopic
public RelatedTopic getChildFileTopic(long folderTopicId, String repoPath)
Description copied from interface:FilesService
Returns the File topic representing the file at a given repository path. If no such File topic exists it is created.Creates an association (type "Composition") between the File topic (role type "Child") and its parent Folder topic (role type "Parent"), if not exists already.
- Specified by:
getChildFileTopic
in interfaceFilesService
- Parameters:
folderTopicId
- 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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
- The File topic. Its child topics ("File Name", "Path", "Media Type", "Size") are included.
-
getChildFolderTopic
public RelatedTopic getChildFolderTopic(long folderTopicId, String repoPath)
Description copied from interface:FilesService
Returns the Folder topic representing the folder at a given repository path. If no such Folder topic exists it is created.Creates an association (type "Composition") between the Folder topic (role type "Child") and its parent Folder topic (role type "Parent"), if not exists already.
- Specified by:
getChildFolderTopic
in interfaceFilesService
- Parameters:
folderTopicId
- 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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
- The Folder topic. Its child topics ("Folder Name", "Path") are included.
-
storeFile
public StoredFile storeFile(UploadedFile file, String repoPath) throws FileRepositoryException
Description copied from interface:FilesService
Receives an uploaded file, stores it in the file repository, and creates a corresponding File topic.- Specified by:
storeFile
in interfaceFilesService
repoPath
- 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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
- a StoredFile object which holds 2 information: the name of the uploaded file, and the ID of the created File topic. ### FIXDOC
- Throws:
FileRepositoryException
-
createFile
public Topic createFile(InputStream in, String repoPath)
Description copied from interface:FilesService
Creates a file in the file repository and a corresponding File topic.- Specified by:
createFile
in interfaceFilesService
- Parameters:
in
- 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 overwritingA repository path. Relative to the repository base path. Must begin with slash, no slash at the end.
If per-workspace file repos are active (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
- the File topic that corresponds to the created file.
-
createFolder
public RelatedTopic createFolder(String folderName, String repoPath) throws FileRepositoryException
Description copied from interface:FilesService
Creates a folder in the file repository. Note: no corresponding Folder topic is created.- Specified by:
createFolder
in interfaceFilesService
repoPath
- 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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Throws:
FileRepositoryException
-
getResourceInfo
public ResourceInfo getResourceInfo(String repoPath)
- Specified by:
getResourceInfo
in interfaceFilesService
-
getDirectoryListing
public DirectoryListing getDirectoryListing(String repoPath)
- Specified by:
getDirectoryListing
in interfaceFilesService
-
getRepositoryPath
public String getRepositoryPath(URL url)
Description copied from interface:FilesService
Checks if the given URL refers to the file repository of this DMX installation.- Specified by:
getRepositoryPath
in interfaceFilesService
- Returns:
- the refered file's/directory's repository path, or
null
if the URL does not refer to the file repository of this DMX installation.
-
getFile
public File getFile(String repoPath)
Description copied from interface:FilesService
Accesses a file/directory in the file repository by the given repository path. If no such file/directory exists a FileRepositoryException is thrown.Note: this method does not require the corresponding File/Folder topic to exist.
- Specified by:
getFile
in interfaceFilesService
- Parameters:
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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.
-
getFile
public File getFile(long fileTopicId)
Description copied from interface:FilesService
Convenience method to access the file/directory in the file repository that is represented by the given File/Folder topic.- Specified by:
getFile
in interfaceFilesService
- Parameters:
fileTopicId
- ID of a File/Folder topic.
-
fileExists
public boolean fileExists(String repoPath)
Description copied from interface:FilesService
Checks if a file/directory with the given repository path exists in the file repository.- Specified by:
fileExists
in interfaceFilesService
- Parameters:
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 (
dmx.filerepo.per_workspace=true
) the repository path must contain the workspace prefix as the first path segment, e.g."/workspace-1234"
where1234
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
FilesService.pathPrefix()
methods.- Returns:
true
if the file exists,false
otherwise.
-
pathPrefix
public String pathPrefix()
Description copied from interface:FilesService
Returns a prefix that can be used for constructing a repository path. In case of per-workspace file repos are active (dmx.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.- Specified by:
pathPrefix
in interfaceFilesService
-
pathPrefix
public String pathPrefix(long workspaceId)
Description copied from interface:FilesService
Returns a prefix that can be used for constructing a repository path. In case of per-workspace file repos are active (dmx.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.- Specified by:
pathPrefix
in interfaceFilesService
-
openFile
public int openFile(long fileTopicId)
- Specified by:
openFile
in interfaceFilesService
-
init
public void init()
- Specified by:
init
in interfacePluginContext
- Overrides:
init
in classPluginActivator
-
staticResourceFilter
public void staticResourceFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
- Specified by:
staticResourceFilter
in interfaceStaticResourceFilter
-
-