mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 16:36:13 +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;
|
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.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.network.WebdavUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
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.common.utils.Log_OC;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
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.
|
* 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) {
|
private RemoteOperationResult createFolder(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result;
|
||||||
MkColMethod mkcol = null;
|
|
||||||
try {
|
try {
|
||||||
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(client.getWebdavUri()
|
||||||
client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
|
+ WebdavUtils.encodePath(mRemotePath)));
|
||||||
result = new RemoteOperationResult(mkcol.succeeded(), mkcol);
|
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());
|
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
||||||
client.exhaustResponse(mkcol.getResponseBodyAsStream());
|
client.exhaustResponse(mkcol.getResponseAsStream());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
||||||
|
|
||||||
} finally {
|
|
||||||
if (mkcol != null)
|
|
||||||
mkcol.releaseConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user