1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.oc_framework
.operations
.remote
;
20 import org
.apache
.commons
.httpclient
.HttpStatus
;
21 import org
.apache
.jackrabbit
.webdav
.client
.methods
.DeleteMethod
;
23 import android
.util
.Log
;
25 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
26 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavUtils
;
27 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
28 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
31 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
33 * @author David A. Velasco
36 public class RemoveRemoteFileOperation
extends RemoteOperation
{
37 private static final String TAG
= RemoveRemoteFileOperation
.class.getSimpleName();
39 private static final int REMOVE_READ_TIMEOUT
= 10000;
40 private static final int REMOVE_CONNECTION_TIMEOUT
= 5000;
42 private String mRemotePath
;
47 * @param remotePath RemotePath of the remote file or folder to remove from the server
49 public RemoveRemoteFileOperation(String remotePath
) {
50 mRemotePath
= remotePath
;
54 * Performs the rename operation.
56 * @param client Client object to communicate with the remote ownCloud server.
59 protected RemoteOperationResult
run(WebdavClient client
) {
60 RemoteOperationResult result
= null
;
61 DeleteMethod delete
= null
;
64 delete
= new DeleteMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mRemotePath
));
65 int status
= client
.executeMethod(delete
, REMOVE_READ_TIMEOUT
, REMOVE_CONNECTION_TIMEOUT
);
67 delete
.getResponseBodyAsString(); // exhaust the response, although not interesting
68 result
= new RemoteOperationResult((delete
.succeeded() || status
== HttpStatus
.SC_NOT_FOUND
), status
, delete
.getResponseHeaders());
69 Log
.i(TAG
, "Remove " + mRemotePath
+ ": " + result
.getLogMessage());
71 } catch (Exception e
) {
72 result
= new RemoteOperationResult(e
);
73 Log
.e(TAG
, "Remove " + mRemotePath
+ ": " + result
.getLogMessage(), e
);
77 delete
.releaseConnection();