-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tobiasKaminsky <[email protected]>
- Loading branch information
1 parent
1f8bad5
commit b001071
Showing
7 changed files
with
168 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* | ||
* 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/>. | ||
*/ | ||
package com.nextcloud.common | ||
|
||
import android.net.Uri | ||
import com.owncloud.android.lib.common.network.WebdavUtils | ||
import okhttp3.HttpUrl | ||
import okhttp3.OkHttpClient | ||
|
||
abstract class DavMethod<T>(private val httpUrl: HttpUrl) { | ||
fun execute(nextcloudClient: NextcloudClient): T { | ||
// register custom property | ||
WebdavUtils.registerCustomFactories() | ||
|
||
return apply(nextcloudClient.disabledRedirectClient(), httpUrl, nextcloudClient.filesDavUri) | ||
} | ||
|
||
abstract fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
library/src/main/java/com/nextcloud/operations/PropFindMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* | ||
* 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/>. | ||
*/ | ||
package com.nextcloud.operations | ||
|
||
import android.net.Uri | ||
import at.bitfire.dav4jvm.DavResource | ||
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) { | ||
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() | ||
|
||
when (hrefRelation) { | ||
Response.HrefRelation.MEMBER -> result.children.add( | ||
webDavFileUtils.parseResponse(response, filesDavUri) | ||
) | ||
|
||
Response.HrefRelation.SELF -> result.root = | ||
webDavFileUtils.parseResponse(response, filesDavUri) | ||
|
||
Response.HrefRelation.OTHER -> {} | ||
else -> {} | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
library/src/main/java/com/nextcloud/operations/PropFindResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* | ||
* 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/>. | ||
*/ | ||
|
||
package com.nextcloud.operations | ||
|
||
import com.owncloud.android.lib.resources.files.model.RemoteFile | ||
|
||
data class PropFindResult( | ||
var success: Boolean = false, | ||
var root: RemoteFile = RemoteFile(), | ||
val children: MutableList<RemoteFile> = mutableListOf() | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters