From 7f2d94bc7842ea3cc59a134f89fc474612db1caf Mon Sep 17 00:00:00 2001 From: agarcia Date: Thu, 25 Jun 2020 21:59:05 +0200 Subject: [PATCH] Migrate webdav wrappers to kotlin --- .../webdav/{CopyMethod.java => CopyMethod.kt} | 39 +++----- .../{DavConstants.java => DavConstants.kt} | 9 +- .../{MkColMethod.java => MkColMethod.kt} | 30 +++--- .../webdav/{MoveMethod.java => MoveMethod.kt} | 50 +++++----- .../http/methods/webdav/PropfindMethod.java | 94 ------------------- .../http/methods/webdav/PropfindMethod.kt | 78 +++++++++++++++ .../webdav/{PutMethod.java => PutMethod.kt} | 47 ++++------ .../files/ReadRemoteFileOperation.java | 1 - .../files/ReadRemoteFolderOperation.java | 1 - 9 files changed, 148 insertions(+), 201 deletions(-) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/{CopyMethod.java => CopyMethod.kt} (66%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/{DavConstants.java => DavConstants.kt} (87%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/{MkColMethod.java => MkColMethod.kt} (75%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/{MoveMethod.java => MoveMethod.kt} (59%) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/{PutMethod.java => PutMethod.kt} (59%) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt similarity index 66% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt index 718f948c..a49f7b6a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt @@ -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(); - } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavConstants.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavConstants.kt similarity index 87% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavConstants.java rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavConstants.kt index 67fd90ba..03e36bdb 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavConstants.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavConstants.kt @@ -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 } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.kt similarity index 75% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.kt index 9c4a3e34..ddcd85c2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.kt @@ -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); +class MkColMethod(url: URL?) : DavMethod(url) { + @Throws(Exception::class) + public override fun onExecute(): Int { + mDavResource.mkCol(null) { response: Response -> + mResponse = response + } + return super.getStatusCode() } - - @Override - public int onExecute() throws Exception { - mDavResource.mkCol(null, response -> { - mResponse = response; - return Unit.INSTANCE; - }); - - return super.getStatusCode(); - } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt similarity index 59% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt index a57a86b1..d2c45cfa 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt @@ -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() } -} \ No newline at end of file + +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java deleted file mode 100644 index 319b051c..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java +++ /dev/null @@ -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 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 getMembers() { - return mMembers; - } - - public Response getRoot() { - return mRoot; - } -} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt new file mode 100644 index 00000000..2a2913c0 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt @@ -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 +) : DavMethod(url) { + + // response + private val mMembers: MutableList + 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 + get() = mMembers + + init { + mMembers = ArrayList() + this.root = null + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt similarity index 59% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt index cb93bc87..55736a6e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.kt @@ -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() } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index 9149e6d3..64c4481e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -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; diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index 838cfa00..f77c68c9 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -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;