mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Migrate webdav wrappers to kotlin
This commit is contained in:
parent
c5fd59c825
commit
7f2d94bc78
@ -21,12 +21,10 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
import java.net.URL;
|
||||
import okhttp3.Response
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Copy calls wrapper
|
||||
@ -34,24 +32,17 @@ import java.net.URL;
|
||||
* @author Christian Schabesberger
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class CopyMethod extends DavMethod {
|
||||
|
||||
final String destinationUrl;
|
||||
final boolean forceOverride;
|
||||
|
||||
public CopyMethod(URL url, String destinationUrl, boolean forceOverride) {
|
||||
super(url);
|
||||
this.destinationUrl = destinationUrl;
|
||||
this.forceOverride = forceOverride;
|
||||
class CopyMethod(
|
||||
val url: URL?,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.copy(destinationUrl, forceOverride) { response: Response ->
|
||||
mResponse = response
|
||||
}
|
||||
return super.getStatusCode()
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onExecute() throws Exception {
|
||||
mDavResource.copy(destinationUrl, forceOverride, response -> {
|
||||
mResponse = response;
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
return super.getStatusCode();
|
||||
}
|
||||
}
|
@ -21,13 +21,12 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
/**
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class DavConstants {
|
||||
public static final int DEPTH_0 = 0;
|
||||
public static final int DEPTH_1 = 1;
|
||||
object DavConstants {
|
||||
const val DEPTH_0 = 0
|
||||
const val DEPTH_1 = 1
|
||||
}
|
@ -21,12 +21,10 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
import java.net.URL;
|
||||
import okhttp3.Response
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* MkCol calls wrapper
|
||||
@ -34,18 +32,12 @@ import java.net.URL;
|
||||
* @author Christian Schabesberger
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class MkColMethod extends DavMethod {
|
||||
public MkColMethod(URL url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onExecute() throws Exception {
|
||||
mDavResource.mkCol(null, response -> {
|
||||
mResponse = response;
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
return super.getStatusCode();
|
||||
class MkColMethod(url: URL?) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.mkCol(null) { response: Response ->
|
||||
mResponse = response
|
||||
}
|
||||
return super.getStatusCode()
|
||||
}
|
||||
}
|
@ -21,13 +21,11 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import kotlin.Unit;
|
||||
|
||||
import java.net.URL;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants
|
||||
import okhttp3.Response
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Move calls wrapper
|
||||
@ -35,27 +33,23 @@ import java.net.URL;
|
||||
* @author Christian Schabesberger
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class MoveMethod extends DavMethod {
|
||||
final String destinationUrl;
|
||||
final boolean forceOverride;
|
||||
|
||||
public MoveMethod(URL url, String destinationUrl, boolean forceOverride) {
|
||||
super(url);
|
||||
this.destinationUrl = destinationUrl;
|
||||
this.forceOverride = forceOverride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onExecute() throws Exception {
|
||||
class MoveMethod(
|
||||
url: URL?,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean
|
||||
) :
|
||||
DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.move(
|
||||
destinationUrl,
|
||||
forceOverride,
|
||||
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
|
||||
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> {
|
||||
mResponse = response;
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
return super.getStatusCode();
|
||||
destinationUrl,
|
||||
forceOverride,
|
||||
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
|
||||
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER)
|
||||
) { response: Response ->
|
||||
mResponse = response
|
||||
}
|
||||
return super.getStatusCode()
|
||||
}
|
||||
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2020 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import at.bitfire.dav4jvm.Property;
|
||||
import at.bitfire.dav4jvm.Response;
|
||||
import at.bitfire.dav4jvm.exception.DavException;
|
||||
import kotlin.Unit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Propfind calls wrapper
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class PropfindMethod extends DavMethod {
|
||||
|
||||
// request
|
||||
private final int mDepth;
|
||||
private final Property.Name[] mPropertiesToRequest;
|
||||
|
||||
// response
|
||||
private final List<Response> mMembers;
|
||||
private Response mRoot;
|
||||
|
||||
public PropfindMethod(URL url, int depth, Property.Name[] propertiesToRequest) {
|
||||
super(url);
|
||||
mDepth = depth;
|
||||
mPropertiesToRequest = propertiesToRequest;
|
||||
mMembers = new ArrayList<>();
|
||||
mRoot = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onExecute() throws IOException, DavException {
|
||||
mDavResource.propfind(mDepth, mPropertiesToRequest,
|
||||
(Response response, Response.HrefRelation hrefRelation) -> {
|
||||
switch (hrefRelation) {
|
||||
case MEMBER:
|
||||
mMembers.add(response);
|
||||
break;
|
||||
case SELF:
|
||||
mRoot = response;
|
||||
break;
|
||||
case OTHER:
|
||||
default:
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}, response -> {
|
||||
mResponse = response;
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
return getStatusCode();
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return mDepth;
|
||||
}
|
||||
|
||||
public List<Response> getMembers() {
|
||||
return mMembers;
|
||||
}
|
||||
|
||||
public Response getRoot() {
|
||||
return mRoot;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2020 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
import at.bitfire.dav4android.Property
|
||||
import at.bitfire.dav4android.Response
|
||||
import at.bitfire.dav4android.Response.HrefRelation
|
||||
import at.bitfire.dav4android.exception.DavException
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* Propfind calls wrapper
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
class PropfindMethod(
|
||||
url: URL?,
|
||||
// request
|
||||
val depth: Int,
|
||||
private val mPropertiesToRequest: Array<Property.Name>
|
||||
) : DavMethod(url) {
|
||||
|
||||
// response
|
||||
private val mMembers: MutableList<Response>
|
||||
var root: Response?
|
||||
private set
|
||||
|
||||
@Throws(IOException::class, DavException::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.propfind(
|
||||
depth = depth,
|
||||
reqProp = *mPropertiesToRequest,
|
||||
callback = { response: Response, hrefRelation: HrefRelation? ->
|
||||
when (hrefRelation) {
|
||||
HrefRelation.MEMBER -> mMembers.add(response)
|
||||
HrefRelation.SELF -> this.root = response
|
||||
HrefRelation.OTHER -> {
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}, rawCallback = { response: okhttp3.Response ->
|
||||
mResponse = response
|
||||
})
|
||||
return statusCode
|
||||
}
|
||||
|
||||
val members: List<Response>
|
||||
get() = mMembers
|
||||
|
||||
init {
|
||||
mMembers = ArrayList()
|
||||
this.root = null
|
||||
}
|
||||
}
|
@ -21,41 +21,30 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.lib.common.http.methods.webdav
|
||||
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import at.bitfire.dav4jvm.exception.HttpException;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import kotlin.Unit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import at.bitfire.dav4android.exception.HttpException
|
||||
import com.owncloud.android.lib.common.http.HttpConstants
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Put calls wrapper
|
||||
*
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class PutMethod extends DavMethod {
|
||||
|
||||
public PutMethod(URL url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
public int onExecute() throws IOException, HttpException {
|
||||
class PutMethod(url: URL?) : DavMethod(url) {
|
||||
@Throws(IOException::class, HttpException::class)
|
||||
public override fun onExecute(): Int {
|
||||
mDavResource.put(
|
||||
mRequestBody,
|
||||
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
||||
super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER),
|
||||
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
|
||||
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> {
|
||||
mResponse = response;
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
return super.getStatusCode();
|
||||
mRequestBody,
|
||||
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
|
||||
super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER),
|
||||
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
|
||||
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER)
|
||||
) { response: Response ->
|
||||
mResponse = response
|
||||
}
|
||||
return super.getStatusCode()
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
@ -30,7 +30,6 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.DavConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.DavUtils;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
Loading…
x
Reference in New Issue
Block a user