1 /* ownCloud Android client application
2 * Copyright (C) 2012 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
.operations
;
20 import org
.apache
.jackrabbit
.webdav
.client
.methods
.MkColMethod
;
22 import com
.owncloud
.android
.Log_OC
;
23 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
24 import com
.owncloud
.android
.datamodel
.OCFile
;
26 import eu
.alefzero
.webdav
.WebdavClient
;
27 import eu
.alefzero
.webdav
.WebdavUtils
;
30 * Remote operation performing the creation of a new folder in the ownCloud server.
32 * @author David A. Velasco
34 public class CreateFolderOperation
extends RemoteOperation
{
36 private static final String TAG
= CreateFolderOperation
.class.getSimpleName();
38 private static final int READ_TIMEOUT
= 10000;
39 private static final int CONNECTION_TIMEOUT
= 5000;
41 protected String mRemotePath
;
42 protected long mParentDirId
;
43 protected DataStorageManager mStorageManager
;
48 * @param remoetPath Full path to the new directory to create in the remote server.
49 * @param parentDirId Local database id for the parent folder.
50 * @param storageManager Reference to the local database corresponding to the account where the file is contained.
52 public CreateFolderOperation(String remotePath
, long parentDirId
, DataStorageManager storageManager
) {
53 mRemotePath
= remotePath
;
54 mParentDirId
= parentDirId
;
55 mStorageManager
= storageManager
;
60 * Performs the remove operation
62 * @param client Client object to communicate with the remote ownCloud server.
65 protected RemoteOperationResult
run(WebdavClient client
) {
66 RemoteOperationResult result
= null
;
67 MkColMethod mkcol
= null
;
69 mkcol
= new MkColMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mRemotePath
));
70 int status
= client
.executeMethod(mkcol
, READ_TIMEOUT
, CONNECTION_TIMEOUT
);
71 if (mkcol
.succeeded()) {
72 // Save new directory in local database
73 OCFile newDir
= new OCFile(mRemotePath
);
74 newDir
.setMimetype("DIR");
75 newDir
.setParentId(mParentDirId
);
76 newDir
.setModificationTimestamp(System
.currentTimeMillis());
77 mStorageManager
.saveFile(newDir
);
80 result
= new RemoteOperationResult(mkcol
.succeeded(), status
);
81 Log_OC
.d(TAG
, "Create directory " + mRemotePath
+ ": " + result
.getLogMessage());
82 client
.exhaustResponse(mkcol
.getResponseBodyAsStream());
84 } catch (Exception e
) {
85 result
= new RemoteOperationResult(e
);
86 Log_OC
.e(TAG
, "Create directory " + mRemotePath
+ ": " + result
.getLogMessage(), e
);
90 mkcol
.releaseConnection();