blob: 8e6d6cf136ff5b4d03253be480eca2e7bcddce0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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());
}
}
|