Skip to content

Commit

Permalink
Add oc/nc counterpart for remaining methods
Browse files Browse the repository at this point in the history
- added classes to retrieve extended properties
- moved WebdavUtils helper to Kotlin object
- renamed some methods to reflect property name
- adjusted nullability of attributes to better match pre-existing values
- minor refactoring
- added missing licences
- replaced client with library licence
- removed initial Dav4JVM.kt test cases

Signed-off-by: ZetaTom <[email protected]>
  • Loading branch information
ZetaTom committed Feb 13, 2024
1 parent d9ac37d commit bf6cc1b
Show file tree
Hide file tree
Showing 43 changed files with 2,096 additions and 1,031 deletions.
285 changes: 0 additions & 285 deletions library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt

This file was deleted.

86 changes: 48 additions & 38 deletions library/src/main/java/com/nextcloud/operations/PropFindMethod.kt
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 Nextcloud 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.nextcloud.operations

import android.net.Uri
import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.Response
import com.nextcloud.common.DavMethod
import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.common.utils.WebDavFileUtils
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import org.apache.jackrabbit.webdav.DavConstants

class PropFindMethod(httpUrl: HttpUrl) : DavMethod<PropFindResult>(httpUrl) {
class PropFindMethod
@JvmOverloads constructor(
httpUrl: HttpUrl,
private val propertySet: Array<Property.Name> = WebdavUtils.PROPERTYSETS.ALL,
private val depth: Int = 1
) : DavMethod<PropFindResult>(httpUrl) {

override fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): PropFindResult {
val webDavFileUtils = WebDavFileUtils()
val result = PropFindResult()

DavResource(client, httpUrl)
.propfind(
DavConstants.DEPTH_1,
*WebdavUtils.getAllPropertiesList()
) { response: Response, hrefRelation: Response.HrefRelation? ->
result.success = response.isSuccess()
DavResource(client, httpUrl).propfind(
depth, *propertySet
) { response: Response, hrefRelation: Response.HrefRelation? ->
result.success = response.isSuccess()

when (hrefRelation) {
Response.HrefRelation.MEMBER -> result.children.add(
webDavFileUtils.parseResponse(response, filesDavUri)
)
when (hrefRelation) {
Response.HrefRelation.MEMBER -> result.children.add(
webDavFileUtils.parseResponse(response, filesDavUri)
)

Response.HrefRelation.SELF -> result.root =
webDavFileUtils.parseResponse(response, filesDavUri)
Response.HrefRelation.SELF -> result.root =
webDavFileUtils.parseResponse(response, filesDavUri)

Response.HrefRelation.OTHER -> {}
else -> {}
}
Response.HrefRelation.OTHER -> {}
else -> {}
}
}

return result
}
Expand Down
Loading

0 comments on commit bf6cc1b

Please sign in to comment.