001 package de.deepamehta.plugins.files.service;
002
003 import de.deepamehta.plugins.files.DirectoryListing;
004 import de.deepamehta.plugins.files.ResourceInfo;
005 import de.deepamehta.plugins.files.StoredFile;
006 import de.deepamehta.plugins.files.UploadedFile;
007
008 import de.deepamehta.core.Topic;
009 import de.deepamehta.core.service.PluginService;
010
011 import java.io.File;
012 import java.io.InputStream;
013 import java.net.URL;
014
015
016
017 public interface FilesService extends PluginService {
018
019
020
021 // === File System Representation ===
022
023 /**
024 * Creates and returns a File topic representing the file at a given repository path.
025 * If such a File topic exists already that topic is returned.
026 *
027 * @param path A repository path. Relative to the repository base path.
028 * Must begin with slash, no slash at the end.
029 */
030 Topic createFileTopic(String path);
031
032 /**
033 * Creates and returns a Folder topic representing the folder at a given repository path.
034 * If such a Folder topic exists already that topic is returned.
035 *
036 * @param path A repository path. Relative to the repository base path.
037 * Must begin with slash, no slash at the end.
038 */
039 Topic createFolderTopic(String path);
040
041 // ---
042
043 Topic createChildFileTopic(long folderTopicId, String path);
044
045 Topic createChildFolderTopic(long folderTopicId, String path);
046
047
048
049 // === File Repository ===
050
051 /**
052 * Receives an uploaded file, stores it in the file repository, and creates a corresponding File topic.
053 *
054 * @param path The directory where to store the uploaded file.
055 * A repository path. Relative to the repository base path.
056 * Must begin with slash, no slash at the end.
057 * The directory must exist.
058 *
059 * @return a StoredFile object which holds 2 information: the name of the uploaded file, and the ID
060 * of the created File topic.
061 */
062 StoredFile storeFile(UploadedFile file, String path);
063
064 /**
065 * Creates a file in the file repository, and creates a corresponding File topic.
066 *
067 * @param in The input stream the file content is read from.
068 * @param path The path and filename of the file to be created.
069 * A repository path. Relative to the repository base path.
070 * Must begin with slash, no slash at the end.
071 * If that file exists already it is overwritten. ### TODO: rethink overwriting
072 *
073 * @return the File topic that corresponds to the created file.
074 */
075 Topic createFile(InputStream in, String path);
076
077 /**
078 * Creates a folder in the file repository.
079 * Note: to corresponding Folder topic is created.
080 *
081 * @param path The directory where to create the folder.
082 * A repository path. Relative to the repository base path.
083 * Must begin with slash, no slash at the end.
084 */
085 void createFolder(String folderName, String path);
086
087 // ---
088
089 ResourceInfo getResourceInfo(String path);
090
091 DirectoryListing getDirectoryListing(String path);
092
093 /**
094 * Checks if the given URL refers to the file repository of this DeepaMehta installation.
095 *
096 * @return the refered file's/directory's repository path, or <code>null</code> if the URL
097 * does not refer to the file repository of this DeepaMehta installation.
098 */
099 String getRepositoryPath(URL url);
100
101 // ---
102
103 /**
104 * Accesses a file/directory in the file repository by the given repository path.
105 * Note: this method doesn't require the corresponding File/Folder topic to exist.
106 *
107 * @param path A repository path. Relative to the repository base path.
108 * Must begin with slash, no slash at the end.
109 */
110 File getFile(String path);
111
112 /**
113 * Accesses a file/directory in the file repository that is represented by the given File/Folder topic.
114 */
115 File getFile(long fileTopicId);
116
117 // ---
118
119 void openFile(long fileTopicId);
120 }