1 package com
.owncloud
.android
.oc_framework
.operations
.remote
;
3 import org
.apache
.http
.HttpStatus
;
4 import org
.apache
.jackrabbit
.webdav
.DavConstants
;
5 import org
.apache
.jackrabbit
.webdav
.MultiStatus
;
6 import org
.apache
.jackrabbit
.webdav
.client
.methods
.PropFindMethod
;
8 import android
.util
.Log
;
10 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
11 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavUtils
;
12 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
13 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
16 * Remote operation performing the read of remote file or folder in the ownCloud server.
18 * @author David A. Velasco
22 public class ReadRemoteFileOperation
extends RemoteOperation
{
24 private static final String TAG
= ReadRemoteFileOperation
.class.getSimpleName();
26 private String mRemotePath
;
27 private MultiStatus mDataInServer
;
29 public MultiStatus
getDataInServer() {
37 * @param remotePath Remote path of the file.
39 public ReadRemoteFileOperation(String remotePath
) {
40 mRemotePath
= remotePath
;
45 * Performs the read operation.
47 * @param client Client object to communicate with the remote ownCloud server.
50 protected RemoteOperationResult
run(WebdavClient client
) {
51 RemoteOperationResult result
= null
;
52 PropFindMethod query
= null
;
56 query
= new PropFindMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mRemotePath
),
57 DavConstants
.PROPFIND_ALL_PROP
,
58 DavConstants
.DEPTH_1
);
59 int status
= client
.executeMethod(query
);
61 // check and process response
62 if (isMultiStatus(status
)) {
63 // get data from remote folder
64 mDataInServer
= query
.getResponseBodyAsMultiStatus();
65 result
= new RemoteOperationResult(true
, status
, query
.getResponseHeaders());
67 // synchronization failed
68 client
.exhaustResponse(query
.getResponseBodyAsStream());
69 result
= new RemoteOperationResult(false
, status
, query
.getResponseHeaders());
72 } catch (Exception e
) {
73 result
= new RemoteOperationResult(e
);
78 query
.releaseConnection(); // let the connection available for other methods
79 if (result
.isSuccess()) {
80 Log
.i(TAG
, "Synchronized " + mRemotePath
+ ": " + result
.getLogMessage());
82 if (result
.isException()) {
83 Log
.e(TAG
, "Synchronized " + mRemotePath
+ ": " + result
.getLogMessage(), result
.getException());
85 Log
.e(TAG
, "Synchronized " + mRemotePath
+ ": " + result
.getLogMessage());
93 public boolean isMultiStatus(int status
) {
94 return (status
== HttpStatus
.SC_MULTI_STATUS
);