1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.operations
;
21 import org
.apache
.jackrabbit
.webdav
.client
.methods
.DeleteMethod
;
23 import android
.util
.Log
;
25 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
26 import com
.owncloud
.android
.datamodel
.OCFile
;
28 import eu
.alefzero
.webdav
.WebdavClient
;
29 import eu
.alefzero
.webdav
.WebdavUtils
;
32 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
34 * @author David A. Velasco
36 public class RemoveFileOperation
extends RemoteOperation
{
38 private static final String TAG
= RemoveFileOperation
.class.getSimpleName();
40 private static final int REMOVE_READ_TIMEOUT
= 10000;
41 private static final int REMOVE_CONNECTION_TIMEOUT
= 5000;
44 boolean mDeleteLocalCopy
;
45 DataStorageManager mDataStorageManager
;
51 * @param fileToRemove OCFile instance describing the remote file or folder to remove from the server
52 * @param deleteLocalCopy When 'true', and a local copy of the file exists, it is also removed.
53 * @param storageManager Reference to the local database corresponding to the account where the file is contained.
55 public RemoveFileOperation(OCFile fileToRemove
, boolean deleteLocalCopy
, DataStorageManager storageManager
) {
56 mFileToRemove
= fileToRemove
;
57 mDeleteLocalCopy
= deleteLocalCopy
;
58 mDataStorageManager
= storageManager
;
63 * Getter for the file to remove (or removed, if the operation was successfully performed).
65 * @return File to remove or already removed.
67 public OCFile
getFile() {
73 * Performs the remove operation
75 * @param client Client object to communicate with the remote ownCloud server.
78 protected RemoteOperationResult
run(WebdavClient client
) {
79 RemoteOperationResult result
= null
;
80 DeleteMethod delete
= null
;
82 delete
= new DeleteMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mFileToRemove
.getRemotePath()));
83 int status
= client
.executeMethod(delete
, REMOVE_READ_TIMEOUT
, REMOVE_CONNECTION_TIMEOUT
);
84 if (delete
.succeeded()) {
85 if (mFileToRemove
.isDirectory()) {
86 mDataStorageManager
.removeDirectory(mFileToRemove
, true
, mDeleteLocalCopy
);
88 mDataStorageManager
.removeFile(mFileToRemove
, mDeleteLocalCopy
);
91 delete
.getResponseBodyAsString(); // exhaust the response, although not interesting
92 result
= new RemoteOperationResult(delete
.succeeded(), status
);
93 Log
.i(TAG
, "Remove " + mFileToRemove
.getRemotePath() + ": " + result
.getLogMessage());
95 } catch (Exception e
) {
96 result
= new RemoteOperationResult(e
);
97 Log
.e(TAG
, "Remove " + mFileToRemove
.getRemotePath() + ": " + result
.getLogMessage(), e
);
101 delete
.releaseConnection();