From f15018253c0fc652d01bc3c9edb363c1ee7e19e4 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 14 Jun 2024 09:16:42 -0300 Subject: [PATCH] Prevent NoClassDefFound error when a WebDAV server returns GetLastModified which happens in the case of dufs (see last commit) --- .../seedvault/plugins/webdav/WebDavStorage.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt index 1793320c..12893a3d 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt @@ -9,8 +9,12 @@ import android.util.Log import at.bitfire.dav4jvm.BasicDigestAuthHandler import at.bitfire.dav4jvm.DavCollection import at.bitfire.dav4jvm.MultiResponseCallback +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.PropertyRegistry import at.bitfire.dav4jvm.Response import at.bitfire.dav4jvm.Response.HrefRelation.SELF +import at.bitfire.dav4jvm.XmlUtils.NS_WEBDAV import at.bitfire.dav4jvm.exception.HttpException import at.bitfire.dav4jvm.property.DisplayName import at.bitfire.dav4jvm.property.ResourceType @@ -27,6 +31,7 @@ import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.internal.closeQuietly import okio.BufferedSink +import org.xmlpull.v1.XmlPullParser import java.io.IOException import java.io.InputStream import java.io.OutputStream @@ -69,6 +74,10 @@ internal abstract class WebDavStorage( protected val baseUrl = webDavConfig.url protected val url = "${webDavConfig.url}/$root" + init { + PropertyRegistry.register(GetLastModified.Factory) + } + @Throws(IOException::class) protected suspend fun getOutputStream(location: HttpUrl): OutputStream { val davCollection = DavCollection(okHttpClient, location) @@ -237,3 +246,19 @@ internal abstract class WebDavStorage( } } + +/** + * A fake version of [at.bitfire.dav4jvm.property.GetLastModified] which we register + * so we don't need to depend on `org.apache.commons.lang3` which is used for date parsing. + */ +class GetLastModified : Property { + companion object { + @JvmField + val NAME = Property.Name(NS_WEBDAV, "getlastmodified") + } + + object Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): GetLastModified? = null + } +}