1 /* ownCloud webDAV Library for Android is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package com
.owncloud
.android
.oc_framework
.operations
.remote
;
27 import org
.apache
.commons
.httpclient
.HttpStatus
;
28 import org
.apache
.jackrabbit
.webdav
.client
.methods
.DeleteMethod
;
30 import android
.util
.Log
;
32 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
33 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavUtils
;
34 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
35 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
38 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
40 * @author David A. Velasco
43 public class RemoveRemoteFileOperation
extends RemoteOperation
{
44 private static final String TAG
= RemoveRemoteFileOperation
.class.getSimpleName();
46 private static final int REMOVE_READ_TIMEOUT
= 10000;
47 private static final int REMOVE_CONNECTION_TIMEOUT
= 5000;
49 private String mRemotePath
;
54 * @param remotePath RemotePath of the remote file or folder to remove from the server
56 public RemoveRemoteFileOperation(String remotePath
) {
57 mRemotePath
= remotePath
;
61 * Performs the rename operation.
63 * @param client Client object to communicate with the remote ownCloud server.
66 protected RemoteOperationResult
run(WebdavClient client
) {
67 RemoteOperationResult result
= null
;
68 DeleteMethod delete
= null
;
71 delete
= new DeleteMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mRemotePath
));
72 int status
= client
.executeMethod(delete
, REMOVE_READ_TIMEOUT
, REMOVE_CONNECTION_TIMEOUT
);
74 delete
.getResponseBodyAsString(); // exhaust the response, although not interesting
75 result
= new RemoteOperationResult((delete
.succeeded() || status
== HttpStatus
.SC_NOT_FOUND
), status
, delete
.getResponseHeaders());
76 Log
.i(TAG
, "Remove " + mRemotePath
+ ": " + result
.getLogMessage());
78 } catch (Exception e
) {
79 result
= new RemoteOperationResult(e
);
80 Log
.e(TAG
, "Remove " + mRemotePath
+ ": " + result
.getLogMessage(), e
);
84 delete
.releaseConnection();