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 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
.MkColMethod
;
23 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
24 import com
.owncloud
.android
.datamodel
.OCFile
;
26 import android
.util
.Log
;
28 import eu
.alefzero
.webdav
.WebdavClient
;
29 import eu
.alefzero
.webdav
.WebdavUtils
;
32 * Remote operation performing the creation of a new folder in the ownCloud server.
34 * @author David A. Velasco
36 public class CreateFolderOperation
extends RemoteOperation
{
38 private static final String TAG
= CreateFolderOperation
.class.getSimpleName();
40 private static final int READ_TIMEOUT
= 10000;
41 private static final int CONNECTION_TIMEOUT
= 5000;
43 protected String mRemotePath
;
44 protected long mParentDirId
;
45 protected DataStorageManager mStorageManager
;
50 * @param remoetPath Full path to the new directory to create in the remote server.
51 * @param parentDirId Local database id for the parent folder.
52 * @param storageManager Reference to the local database corresponding to the account where the file is contained.
54 public CreateFolderOperation(String remotePath
, long parentDirId
, DataStorageManager storageManager
) {
55 mRemotePath
= remotePath
;
56 mParentDirId
= parentDirId
;
57 mStorageManager
= storageManager
;
62 * Performs the remove operation
64 * @param client Client object to communicate with the remote ownCloud server.
67 protected RemoteOperationResult
run(WebdavClient client
) {
68 RemoteOperationResult result
= null
;
69 MkColMethod mkcol
= null
;
71 mkcol
= new MkColMethod(client
.getBaseUri() + WebdavUtils
.encodePath(mRemotePath
));
72 int status
= client
.executeMethod(mkcol
, READ_TIMEOUT
, CONNECTION_TIMEOUT
);
73 if (mkcol
.succeeded()) {
74 // Save new directory in local database
75 OCFile newDir
= new OCFile(mRemotePath
);
76 newDir
.setMimetype("DIR");
77 newDir
.setParentId(mParentDirId
);
78 mStorageManager
.saveFile(newDir
);
81 result
= new RemoteOperationResult(mkcol
.succeeded(), status
);
82 Log
.d(TAG
, "Create directory " + mRemotePath
+ ": " + result
.getLogMessage());
83 client
.exhaustResponse(mkcol
.getResponseBodyAsStream());
85 } catch (Exception e
) {
86 result
= new RemoteOperationResult(e
);
87 Log
.e(TAG
, "Create directory " + mRemotePath
+ ": " + result
.getLogMessage(), e
);
91 mkcol
.releaseConnection();