Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 7f2d94b

Browse files
committed
Migrate webdav wrappers to kotlin
1 parent c5fd59c commit 7f2d94b

File tree

9 files changed

+148
-201
lines changed

9 files changed

+148
-201
lines changed
Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,28 @@
2121
* THE SOFTWARE.
2222
*
2323
*/
24+
package com.owncloud.android.lib.common.http.methods.webdav
2425

25-
package com.owncloud.android.lib.common.http.methods.webdav;
26-
27-
import kotlin.Unit;
28-
29-
import java.net.URL;
26+
import okhttp3.Response
27+
import java.net.URL
3028

3129
/**
3230
* Copy calls wrapper
3331
*
3432
* @author Christian Schabesberger
3533
* @author David González Verdugo
3634
*/
37-
public class CopyMethod extends DavMethod {
38-
39-
final String destinationUrl;
40-
final boolean forceOverride;
41-
42-
public CopyMethod(URL url, String destinationUrl, boolean forceOverride) {
43-
super(url);
44-
this.destinationUrl = destinationUrl;
45-
this.forceOverride = forceOverride;
35+
class CopyMethod(
36+
val url: URL?,
37+
private val destinationUrl: String,
38+
private val forceOverride: Boolean
39+
) : DavMethod(url) {
40+
@Throws(Exception::class)
41+
public override fun onExecute(): Int {
42+
mDavResource.copy(destinationUrl, forceOverride) { response: Response ->
43+
mResponse = response
44+
}
45+
return super.getStatusCode()
4646
}
4747

48-
@Override
49-
public int onExecute() throws Exception {
50-
mDavResource.copy(destinationUrl, forceOverride, response -> {
51-
mResponse = response;
52-
return Unit.INSTANCE;
53-
});
54-
55-
return super.getStatusCode();
56-
}
57-
}
48+
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
* THE SOFTWARE.
2222
*
2323
*/
24-
25-
package com.owncloud.android.lib.common.http.methods.webdav;
24+
package com.owncloud.android.lib.common.http.methods.webdav
2625

2726
/**
2827
* @author David González Verdugo
2928
*/
30-
public class DavConstants {
31-
public static final int DEPTH_0 = 0;
32-
public static final int DEPTH_1 = 1;
29+
object DavConstants {
30+
const val DEPTH_0 = 0
31+
const val DEPTH_1 = 1
3332
}
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,23 @@
2121
* THE SOFTWARE.
2222
*
2323
*/
24+
package com.owncloud.android.lib.common.http.methods.webdav
2425

25-
package com.owncloud.android.lib.common.http.methods.webdav;
26-
27-
import kotlin.Unit;
28-
29-
import java.net.URL;
26+
import okhttp3.Response
27+
import java.net.URL
3028

3129
/**
3230
* MkCol calls wrapper
3331
*
3432
* @author Christian Schabesberger
3533
* @author David González Verdugo
3634
*/
37-
public class MkColMethod extends DavMethod {
38-
public MkColMethod(URL url) {
39-
super(url);
40-
}
41-
42-
@Override
43-
public int onExecute() throws Exception {
44-
mDavResource.mkCol(null, response -> {
45-
mResponse = response;
46-
return Unit.INSTANCE;
47-
});
48-
49-
return super.getStatusCode();
35+
class MkColMethod(url: URL?) : DavMethod(url) {
36+
@Throws(Exception::class)
37+
public override fun onExecute(): Int {
38+
mDavResource.mkCol(null) { response: Response ->
39+
mResponse = response
40+
}
41+
return super.getStatusCode()
5042
}
51-
}
43+
}
Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,35 @@
2121
* THE SOFTWARE.
2222
*
2323
*/
24+
package com.owncloud.android.lib.common.http.methods.webdav
2425

25-
package com.owncloud.android.lib.common.http.methods.webdav;
26-
27-
import com.owncloud.android.lib.common.http.HttpConstants;
28-
import kotlin.Unit;
29-
30-
import java.net.URL;
26+
import com.owncloud.android.lib.common.http.HttpConstants
27+
import okhttp3.Response
28+
import java.net.URL
3129

3230
/**
3331
* Move calls wrapper
3432
*
3533
* @author Christian Schabesberger
3634
* @author David González Verdugo
3735
*/
38-
public class MoveMethod extends DavMethod {
39-
final String destinationUrl;
40-
final boolean forceOverride;
41-
42-
public MoveMethod(URL url, String destinationUrl, boolean forceOverride) {
43-
super(url);
44-
this.destinationUrl = destinationUrl;
45-
this.forceOverride = forceOverride;
46-
}
47-
48-
@Override
49-
public int onExecute() throws Exception {
36+
class MoveMethod(
37+
url: URL?,
38+
private val destinationUrl: String,
39+
private val forceOverride: Boolean
40+
) :
41+
DavMethod(url) {
42+
@Throws(Exception::class)
43+
public override fun onExecute(): Int {
5044
mDavResource.move(
51-
destinationUrl,
52-
forceOverride,
53-
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
54-
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> {
55-
mResponse = response;
56-
return Unit.INSTANCE;
57-
});
58-
59-
return super.getStatusCode();
45+
destinationUrl,
46+
forceOverride,
47+
super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER),
48+
super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER)
49+
) { response: Response ->
50+
mResponse = response
51+
}
52+
return super.getStatusCode()
6053
}
61-
}
54+
55+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2020 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
24+
package com.owncloud.android.lib.common.http.methods.webdav
25+
26+
import at.bitfire.dav4android.Property
27+
import at.bitfire.dav4android.Response
28+
import at.bitfire.dav4android.Response.HrefRelation
29+
import at.bitfire.dav4android.exception.DavException
30+
import java.io.IOException
31+
import java.net.URL
32+
import java.util.ArrayList
33+
34+
/**
35+
* Propfind calls wrapper
36+
*
37+
* @author David González Verdugo
38+
*/
39+
class PropfindMethod(
40+
url: URL?,
41+
// request
42+
val depth: Int,
43+
private val mPropertiesToRequest: Array<Property.Name>
44+
) : DavMethod(url) {
45+
46+
// response
47+
private val mMembers: MutableList<Response>
48+
var root: Response?
49+
private set
50+
51+
@Throws(IOException::class, DavException::class)
52+
public override fun onExecute(): Int {
53+
mDavResource.propfind(
54+
depth = depth,
55+
reqProp = *mPropertiesToRequest,
56+
callback = { response: Response, hrefRelation: HrefRelation? ->
57+
when (hrefRelation) {
58+
HrefRelation.MEMBER -> mMembers.add(response)
59+
HrefRelation.SELF -> this.root = response
60+
HrefRelation.OTHER -> {
61+
}
62+
else -> {
63+
}
64+
}
65+
}, rawCallback = { response: okhttp3.Response ->
66+
mResponse = response
67+
})
68+
return statusCode
69+
}
70+
71+
val members: List<Response>
72+
get() = mMembers
73+
74+
init {
75+
mMembers = ArrayList()
76+
this.root = null
77+
}
78+
}

0 commit comments

Comments
 (0)