|
1 |
| -/* |
2 |
| - * |
3 |
| - * Nextcloud Android client application |
4 |
| - * |
5 |
| - * @author Tobias Kaminsky |
6 |
| - * Copyright (C) 2023 Tobias Kaminsky |
7 |
| - * Copyright (C) 2023 Nextcloud GmbH |
8 |
| - * |
9 |
| - * This program is free software: you can redistribute it and/or modify |
10 |
| - * it under the terms of the GNU Affero General Public License as published by |
11 |
| - * the Free Software Foundation, either version 3 of the License, or |
12 |
| - * (at your option) any later version. |
13 |
| - * |
14 |
| - * This program is distributed in the hope that it will be useful, |
15 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
| - * GNU Affero General Public License for more details. |
18 |
| - * |
19 |
| - * You should have received a copy of the GNU Affero General Public License |
20 |
| - * along with this program. If not, see <https://www.gnu.org/licenses/>. |
21 |
| - */ |
| 1 | +/* Nextcloud Android Library is available under MIT license |
| 2 | +* |
| 3 | +* @author Tobias Kaminsky |
| 4 | +* Copyright (C) 2023 Tobias Kaminsky |
| 5 | +* Copyright (C) 2023 Nextcloud GmbH |
| 6 | +* |
| 7 | +* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +* of this software and associated documentation files (the "Software"), to deal |
| 9 | +* in the Software without restriction, including without limitation the rights |
| 10 | +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +* copies of the Software, and to permit persons to whom the Software is |
| 12 | +* furnished to do so, subject to the following conditions: |
| 13 | +* |
| 14 | +* The above copyright notice and this permission notice shall be included in |
| 15 | +* all copies or substantial portions of the Software. |
| 16 | +* |
| 17 | +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | +* THE SOFTWARE. |
| 25 | +* |
| 26 | +*/ |
| 27 | + |
22 | 28 | package com.nextcloud.operations
|
23 | 29 |
|
24 | 30 | import android.net.Uri
|
25 | 31 | import at.bitfire.dav4jvm.DavResource
|
| 32 | +import at.bitfire.dav4jvm.Property |
26 | 33 | import at.bitfire.dav4jvm.Response
|
27 | 34 | import com.nextcloud.common.DavMethod
|
28 | 35 | import com.owncloud.android.lib.common.network.WebdavUtils
|
29 | 36 | import com.owncloud.android.lib.common.utils.WebDavFileUtils
|
30 | 37 | import okhttp3.HttpUrl
|
31 | 38 | import okhttp3.OkHttpClient
|
32 |
| -import org.apache.jackrabbit.webdav.DavConstants |
33 | 39 |
|
34 |
| -class PropFindMethod(httpUrl: HttpUrl) : DavMethod<PropFindResult>(httpUrl) { |
| 40 | +class PropFindMethod |
| 41 | +@JvmOverloads constructor( |
| 42 | + httpUrl: HttpUrl, |
| 43 | + private val propertySet: Array<Property.Name> = WebdavUtils.PROPERTYSETS.ALL, |
| 44 | + private val depth: Int = 1 |
| 45 | +) : DavMethod<PropFindResult>(httpUrl) { |
| 46 | + |
35 | 47 | override fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): PropFindResult {
|
36 | 48 | val webDavFileUtils = WebDavFileUtils()
|
37 | 49 | val result = PropFindResult()
|
38 | 50 |
|
39 |
| - DavResource(client, httpUrl) |
40 |
| - .propfind( |
41 |
| - DavConstants.DEPTH_1, |
42 |
| - *WebdavUtils.getAllPropertiesList() |
43 |
| - ) { response: Response, hrefRelation: Response.HrefRelation? -> |
44 |
| - result.success = response.isSuccess() |
| 51 | + DavResource(client, httpUrl).propfind( |
| 52 | + depth, *propertySet |
| 53 | + ) { response: Response, hrefRelation: Response.HrefRelation? -> |
| 54 | + result.success = response.isSuccess() |
45 | 55 |
|
46 |
| - when (hrefRelation) { |
47 |
| - Response.HrefRelation.MEMBER -> result.children.add( |
48 |
| - webDavFileUtils.parseResponse(response, filesDavUri) |
49 |
| - ) |
| 56 | + when (hrefRelation) { |
| 57 | + Response.HrefRelation.MEMBER -> result.children.add( |
| 58 | + webDavFileUtils.parseResponse(response, filesDavUri) |
| 59 | + ) |
50 | 60 |
|
51 |
| - Response.HrefRelation.SELF -> result.root = |
52 |
| - webDavFileUtils.parseResponse(response, filesDavUri) |
| 61 | + Response.HrefRelation.SELF -> result.root = |
| 62 | + webDavFileUtils.parseResponse(response, filesDavUri) |
53 | 63 |
|
54 |
| - Response.HrefRelation.OTHER -> {} |
55 |
| - else -> {} |
56 |
| - } |
| 64 | + Response.HrefRelation.OTHER -> {} |
| 65 | + else -> {} |
57 | 66 | }
|
| 67 | + } |
58 | 68 |
|
59 | 69 | return result
|
60 | 70 | }
|
|
0 commit comments