summaryrefslogtreecommitdiff
path: root/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2015-01-21 13:05:41 +0000
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2015-06-10 17:08:00 +0000
commit69773f54bbac08953f0fbce16eecea0816e04338 (patch)
treec0802e8f3adc7e80af451dee43996b5a17ace541 /android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
parentb8b4ac9e6e8f03fb84bddb714d3c5908a45153b1 (diff)
Android: initial implementation of ownCloud provider.
This implementation can connect to a local server and browser its contents, but cannot download and open the documents yet. TODO: * Download and open documents. * UI to configure server, user and password. * Implement filtering to show only the documents of the desired type. * Improve error handling. Change-Id: I54a2e2e1d3e8ec8d824d75639e176ca452551f3e Reviewed-on: https://gerrit.libreoffice.org/16191 Reviewed-by: Jacobo Aragunde Pérez <jaragunde@igalia.com> Tested-by: Jacobo Aragunde Pérez <jaragunde@igalia.com>
Diffstat (limited to 'android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java')
-rw-r--r--android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
new file mode 100644
index 000000000000..8e6d6cf136ff
--- /dev/null
+++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
@@ -0,0 +1,113 @@
+package org.libreoffice.storage.owncloud;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.libreoffice.storage.IFile;
+
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
+import com.owncloud.android.lib.resources.files.RemoteFile;
+
+/**
+ * Implementation of IFile for ownCloud servers.
+ */
+public class OwnCloudFile implements IFile {
+
+ private OwnCloudProvider provider;
+ private RemoteFile file;
+
+ private String name;
+ private String parentPath;
+
+ protected OwnCloudFile(OwnCloudProvider provider, RemoteFile file) {
+ this.provider = provider;
+ this.file = file;
+
+ // get name and parent from path
+ File localFile = new File(file.getRemotePath());
+ this.name = localFile.getName();
+ this.parentPath = localFile.getParent();
+ }
+
+ @Override
+ public URI getUri() {
+ return URI.create(file.getRemotePath());
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public boolean isDirectory() {
+ return file.getMimeType().equals("DIR");
+ }
+
+ @Override
+ public long getSize() {
+ return file.getLength();
+ }
+
+ @Override
+ public Date getLastModified() {
+ return new Date(file.getModifiedTimestamp());
+ }
+
+ @Override
+ public List<IFile> listFiles() {
+ List<IFile> children = new ArrayList<IFile>();
+ if (isDirectory()) {
+ ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(
+ file.getRemotePath());
+ RemoteOperationResult result = refreshOperation.execute(provider
+ .getClient());
+ if (!result.isSuccess()) {
+ throw new RuntimeException(result.getLogMessage(),
+ result.getException());
+ }
+ for (Object obj : result.getData()) {
+ RemoteFile child = (RemoteFile) obj;
+ if (!child.getRemotePath().equals(file.getRemotePath()))
+ children.add(new OwnCloudFile(provider, child));
+ }
+ }
+ return children;
+ }
+
+ @Override
+ public List<IFile> listFiles(FileFilter filter) {
+ // TODO no filtering yet
+ return listFiles();
+ }
+
+ @Override
+ public IFile getParent() {
+ if (parentPath == null)
+ // this is the root node
+ return null;
+
+ return provider.createFromUri(URI.create(parentPath));
+ }
+
+ @Override
+ public File getDocument() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object)
+ return true;
+ if (!(object instanceof OwnCloudFile))
+ return false;
+ OwnCloudFile file = (OwnCloudFile) object;
+ return file.getUri().equals(getUri());
+ }
+}