mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 16:36:13 +00:00
add untestet protoype of new ReadRemoteFileOperation
This commit is contained in:
parent
e78b96348b
commit
2041fb1962
@ -24,19 +24,23 @@
|
|||||||
package com.owncloud.android.lib.resources.files;
|
package com.owncloud.android.lib.resources.files;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.apache.jackrabbit.webdav.DavConstants;
|
|
||||||
import org.apache.jackrabbit.webdav.MultiStatus;
|
|
||||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.WebdavEntry;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
|
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils;
|
||||||
|
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
|
import at.bitfire.dav4android.DavResource;
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
|
import static com.owncloud.android.lib.common.http.methods.webdav.DavConstants.DEPTH_0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the read a file from the ownCloud server.
|
* Remote operation performing the read a file from the ownCloud server.
|
||||||
@ -70,38 +74,37 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
PropFindMethod propfind = null;
|
PropfindMethod propfind = null;
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
|
|
||||||
/// take the duty of check the server for the current state of the file there
|
/// take the duty of check the server for the current state of the file there
|
||||||
try {
|
try {
|
||||||
// remote request
|
// remote request
|
||||||
propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
|
propfind = new PropfindMethod(
|
||||||
WebdavUtils.getFilePropSet(), // PropFind Properties
|
HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||||
DavConstants.DEPTH_0);
|
DEPTH_0,
|
||||||
int status;
|
DavUtils.getAllPropset());
|
||||||
status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
|
|
||||||
|
|
||||||
boolean isSuccess = (
|
propfind.setReadTimeout(SYNC_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||||
status == HttpStatus.SC_MULTI_STATUS ||
|
propfind.setConnectionTimeout(SYNC_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||||
status == HttpStatus.SC_OK
|
final int status = client.executeHttpMethod(propfind);
|
||||||
);
|
|
||||||
if (isSuccess) {
|
if (status == HttpConstants.HTTP_MULTI_STATUS
|
||||||
|
|| status == HttpConstants.HTTP_OK) {
|
||||||
// Parse response
|
// Parse response
|
||||||
MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
|
final DavResource resource = propfind.getMembers().iterator().next();
|
||||||
WebdavEntry we = new WebdavEntry(resp.getResponses()[0],
|
|
||||||
client.getWebdavUri().getPath());
|
|
||||||
RemoteFile remoteFile = new RemoteFile(we);
|
|
||||||
ArrayList<Object> files = new ArrayList<Object>();
|
|
||||||
files.add(remoteFile);
|
|
||||||
|
|
||||||
// Result of the operation
|
final RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName());
|
||||||
result = new RemoteOperationResult(true, propfind);
|
|
||||||
|
ArrayList<Object> files = new ArrayList<>();
|
||||||
|
files.add(file);
|
||||||
|
|
||||||
|
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK);
|
||||||
result.setData(files);
|
result.setData(files);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(false, propfind);
|
result = new RemoteOperationResult(propfind);
|
||||||
client.exhaustResponse(propfind.getResponseBodyAsStream());
|
client.exhaustResponse(propfind.getResponseAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -109,10 +112,8 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(),
|
Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(),
|
||||||
result.getException());
|
result.getException());
|
||||||
} finally {
|
|
||||||
if (propfind != null)
|
|
||||||
propfind.releaseConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user