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
.WebdavEntry
;
12 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavUtils
;
13 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
14 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
16 public class ReadRemoteFileOperation
extends RemoteOperation
{
18 private static final String TAG
= ReadRemoteFileOperation
.class.getSimpleName();
20 private String mRemotePath
;
21 private WebdavEntry mWe
;
23 public WebdavEntry
getWEntry() {
27 public ReadRemoteFileOperation(String remotePath
) {
28 mRemotePath
= remotePath
;
32 protected RemoteOperationResult
run(WebdavClient client
) {
33 RemoteOperationResult result
= null
;
34 PropFindMethod query
= null
;
38 query
= new PropFindMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mRemotePath
),
39 DavConstants
.PROPFIND_ALL_PROP
,
40 DavConstants
.DEPTH_1
);
41 int status
= client
.executeMethod(query
);
43 // check and process response
44 if (isMultiStatus(status
)) {
45 MultiStatus dataInServer
= query
.getResponseBodyAsMultiStatus();
46 // parse data from remote folder
47 mWe
= new WebdavEntry(dataInServer
.getResponses()[0], client
.getBaseUri().getPath());
48 result
= new RemoteOperationResult(true
, status
, query
.getResponseHeaders());
50 // synchronization failed
51 client
.exhaustResponse(query
.getResponseBodyAsStream());
52 result
= new RemoteOperationResult(false
, status
, query
.getResponseHeaders());
55 } catch (Exception e
) {
56 result
= new RemoteOperationResult(e
);
61 query
.releaseConnection(); // let the connection available for other methods
62 if (result
.isSuccess()) {
63 Log
.i(TAG
, "Synchronized " + mRemotePath
+ ": " + result
.getLogMessage());
65 if (result
.isException()) {
66 Log
.e(TAG
, "Synchronized " + mRemotePath
+ ": " + result
.getLogMessage(), result
.getException());
68 Log
.e(TAG
, "Synchronized " + mRemotePath
+ ": " + result
.getLogMessage());
76 public boolean isMultiStatus(int status
) {
77 return (status
== HttpStatus
.SC_MULTI_STATUS
);