de.deepamehta.plugins.files
Class FilesPlugin

Show UML class diagram
java.lang.Object
  extended by de.deepamehta.core.osgi.PluginActivator
      extended by de.deepamehta.plugins.files.FilesPlugin
All Implemented Interfaces:
PluginContext, PluginService, SecurityHandler, FilesService, org.osgi.framework.BundleActivator

public class FilesPlugin
extends PluginActivator
implements FilesService, SecurityHandler


Field Summary
private static String FILE_REPOSITORY_PATH
           
private static String FILE_REPOSITORY_URI
           
private  Logger logger
           
 
Fields inherited from class de.deepamehta.core.osgi.PluginActivator
bundle, dms
 
Constructor Summary
FilesPlugin()
           
 
Method Summary
private  void associateChildTopic(long folderTopicId, long childTopicId)
           
private  void checkFileExistence(File file)
           
private  void checkFilePath(File file)
          Prerequisite: the file's path is canonical.
private  boolean childAssociationExists(long folderTopicId, long childTopicId)
           
 Topic createChildFileTopic(long folderTopicId, String path)
           
 Topic createChildFolderTopic(long folderTopicId, String path)
           
 Topic createFile(InputStream in, String path)
          Creates a file in the file repository, and creates a corresponding File topic.
private  Topic createFileTopic(File file)
           
 Topic createFileTopic(String path)
          Creates and returns a File topic representing the file at a given repository path.
 void createFolder(String folderName, String path)
          Creates a folder in the file repository.
private  Topic createFolderTopic(File file)
           
 Topic createFolderTopic(String path)
          Creates and returns a Folder topic representing the folder at a given repository path.
private  File enforeSecurity(String path)
           
private  Topic fetchFileTopic(File file)
          Fetches the File topic representing the file at a given absolute path.
private  Topic fetchFolderTopic(File file)
          Fetches the Folder topic representing the folder at a given absolute path.
private  Topic fetchTopic(File file, String parentTypeUri)
           
 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.
 String getRepositoryPath(URL url)
          Checks if the given URL refers to the file repository of this DeepaMehta installation.
 ResourceInfo getResourceInfo(String path)
           
 boolean handleSecurity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void init()
           
 void openFile(long fileTopicId)
           
private  File repoFile(File directory, String fileName)
           
private  File repoFile(File directory, UploadedFile file)
          Calculates the storage location for the uploaded file.
private  File repoFile(String path)
          Constructs an absolute path from a repository path.
private  String repoPath(File file)
          Returns the repository path that corresponds to the given absolute path.
private  String repoPath(long fileTopicId)
          Returns the repository path of the given File/Folder topic.
 StoredFile storeFile(UploadedFile file, String path)
          Receives an uploaded file, stores it in the file repository, and creates a corresponding File topic.
 
Methods inherited from class de.deepamehta.core.osgi.PluginActivator
getBundleContext, getPluginName, getStaticResource, getUri, publishDirectory, serviceArrived, serviceGone, setCoreService, shutdown, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_REPOSITORY_PATH

private static final String FILE_REPOSITORY_PATH

FILE_REPOSITORY_URI

private static final String FILE_REPOSITORY_URI
See Also:
Constant Field Values

logger

private Logger logger
Constructor Detail

FilesPlugin

public FilesPlugin()
Method Detail

createFileTopic

public Topic createFileTopic(String path)
Description copied from interface: FilesService
Creates and returns a File topic representing the file at a given repository path. If such a File topic exists already that topic is returned.

Specified by:
createFileTopic in interface FilesService
Parameters:
path - A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.

createFolderTopic

public Topic createFolderTopic(String path)
Description copied from interface: FilesService
Creates and returns a Folder topic representing the folder at a given repository path. If such a Folder topic exists already that topic is returned.

Specified by:
createFolderTopic in interface FilesService
Parameters:
path - A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.

createChildFileTopic

public Topic createChildFileTopic(long folderTopicId,
                                  String path)
Specified by:
createChildFileTopic in interface FilesService

createChildFolderTopic

public Topic createChildFolderTopic(long folderTopicId,
                                    String path)
Specified by:
createChildFolderTopic in interface FilesService

storeFile

public StoredFile storeFile(UploadedFile file,
                            String path)
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 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.
Returns:
a StoredFile object which holds 2 information: the name of the uploaded file, and the ID of the created File topic.

createFile

public Topic createFile(InputStream in,
                        String path)
Description copied from interface: FilesService
Creates a file in the file repository, and creates a corresponding File topic.

Specified by:
createFile in interface FilesService
Parameters:
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 overwriting
Returns:
the File topic that corresponds to the created file.

createFolder

public void createFolder(String folderName,
                         String path)
Description copied from interface: FilesService
Creates a folder in the file repository. Note: to corresponding Folder topic is created.

Specified by:
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.

getResourceInfo

public ResourceInfo getResourceInfo(String path)
Specified by:
getResourceInfo in interface FilesService

getDirectoryListing

public DirectoryListing getDirectoryListing(String path)
Specified by:
getDirectoryListing in interface FilesService

getRepositoryPath

public String getRepositoryPath(URL url)
Description copied from interface: FilesService
Checks if the given URL refers to the file repository of this DeepaMehta installation.

Specified by:
getRepositoryPath in interface FilesService
Returns:
the refered file's/directory's repository path, or null if the URL does not refer to the file repository of this DeepaMehta installation.

getFile

public File getFile(String path)
Description copied from interface: FilesService
Accesses a file/directory in the file repository by the given repository path. Note: this method doesn't require the corresponding File/Folder topic to exist.

Specified by:
getFile in interface FilesService
Parameters:
path - A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.

getFile

public File getFile(long fileTopicId)
Description copied from interface: FilesService
Accesses a file/directory in the file repository that is represented by the given File/Folder topic.

Specified by:
getFile in interface FilesService

openFile

public void openFile(long fileTopicId)
Specified by:
openFile in interface FilesService

handleSecurity

public boolean handleSecurity(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
Specified by:
handleSecurity in interface SecurityHandler

init

public void init()
Specified by:
init in interface PluginContext
Overrides:
init in class PluginActivator

fetchFileTopic

private Topic fetchFileTopic(File file)
Fetches the File topic representing the file at a given absolute path. If no such File topic exists null is returned.

Parameters:
file - An absolute path.

fetchFolderTopic

private Topic fetchFolderTopic(File file)
Fetches the Folder topic representing the folder at a given absolute path. If no such Folder topic exists null is returned.

Parameters:
file - An absolute path.

fetchTopic

private Topic fetchTopic(File file,
                         String parentTypeUri)
Parameters:
file - An absolute path.

createFileTopic

private Topic createFileTopic(File file)

createFolderTopic

private Topic createFolderTopic(File file)

associateChildTopic

private void associateChildTopic(long folderTopicId,
                                 long childTopicId)

childAssociationExists

private boolean childAssociationExists(long folderTopicId,
                                       long childTopicId)

repoFile

private File repoFile(String path)
Constructs an absolute path from a repository path.

Parameters:
path - A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.

repoFile

private File repoFile(File directory,
                      UploadedFile file)
Calculates the storage location for the uploaded file.

Parameters:
directory - An absolute path.

repoFile

private File repoFile(File directory,
                      String fileName)
Parameters:
directory - An absolute path.

repoPath

private String repoPath(File file)
Returns the repository path that corresponds to the given absolute path.

Parameters:
file - An absolute path.

repoPath

private String repoPath(long fileTopicId)
Returns the repository path of the given File/Folder topic.


enforeSecurity

private File enforeSecurity(String path)
                     throws FileRepositoryException
Parameters:
path - A repository path. Relative to the repository base path. Must begin with slash, no slash at the end.
Returns:
An absolute path.
Throws:
FileRepositoryException

checkFilePath

private void checkFilePath(File file)
                    throws FileRepositoryException
Prerequisite: the file's path is canonical.

Throws:
FileRepositoryException

checkFileExistence

private void checkFileExistence(File file)
                         throws FileRepositoryException
Throws:
FileRepositoryException


Copyright © 2015. All Rights Reserved.