mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 08:26:10 +00:00
add crete remote folder operation
This commit is contained in:
parent
cb08fe32a4
commit
019383378d
@ -0,0 +1,24 @@
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import at.bitfire.dav4android.exception.UnauthorizedException;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class MkColMethod extends DavMethod {
|
||||
public MkColMethod(HttpUrl httpUrl) {
|
||||
super(httpUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() throws Exception {
|
||||
try {
|
||||
mDavResource.mkCol(null);
|
||||
|
||||
mRequest = mDavResource.getRequest();
|
||||
mResponse = mDavResource.getResponse();
|
||||
|
||||
} catch (UnauthorizedException davException) {
|
||||
// Do nothing, we will use the 401 code to handle the situation
|
||||
}
|
||||
return super.getStatusCode();
|
||||
}
|
||||
}
|
@ -24,9 +24,10 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.MkColMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
@ -34,6 +35,10 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
|
||||
/**
|
||||
* Remote operation performing the creation of a new folder in the ownCloud server.
|
||||
@ -95,23 +100,26 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
|
||||
|
||||
private RemoteOperationResult createFolder(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
MkColMethod mkcol = null;
|
||||
RemoteOperationResult result;
|
||||
try {
|
||||
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
|
||||
result = new RemoteOperationResult(mkcol.succeeded(), mkcol);
|
||||
final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(client.getWebdavUri()
|
||||
+ WebdavUtils.encodePath(mRemotePath)));
|
||||
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||
final int status = client.executeHttpMethod(mkcol);
|
||||
|
||||
result = (status == HttpConstants.HTTP_CREATED)
|
||||
? new RemoteOperationResult(ResultCode.OK)
|
||||
: new RemoteOperationResult(mkcol);
|
||||
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
||||
client.exhaustResponse(mkcol.getResponseBodyAsStream());
|
||||
client.exhaustResponse(mkcol.getResponseAsStream());
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
||||
|
||||
} finally {
|
||||
if (mkcol != null)
|
||||
mkcol.releaseConnection();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user