From 978a5bd45061df02014d89ea1fd4eaa0c769ac0a Mon Sep 17 00:00:00 2001 From: Arnau Mora Gras Date: Tue, 3 Dec 2024 09:47:08 +0100 Subject: [PATCH] Migrated webdav properties Signed-off-by: Arnau Mora Gras --- .../dav4jvm/property/webdav/AddMember.kt | 8 +++- .../dav4jvm/property/webdav/CreationDate.kt | 8 +++- .../property/webdav/CurrentUserPrincipal.kt | 2 + .../webdav/CurrentUserPrivilegeSet.kt | 42 ++++++++++--------- .../dav4jvm/property/webdav/DisplayName.kt | 3 ++ .../property/webdav/GetContentLength.kt | 8 +++- .../dav4jvm/property/webdav/GetContentType.kt | 2 + .../dav4jvm/property/webdav/GetETag.kt | 6 +-- .../property/webdav/GetLastModified.kt | 6 ++- .../property/webdav/GroupMembership.kt | 2 + .../bitfire/dav4jvm/property/webdav/Owner.kt | 4 +- .../property/webdav/QuotaAvailableBytes.kt | 8 +++- .../dav4jvm/property/webdav/QuotaUsedBytes.kt | 8 +++- .../dav4jvm/property/webdav/ResourceType.kt | 16 +++---- .../property/webdav/SupportedReportSet.kt | 16 ++++--- .../dav4jvm/property/webdav/SyncToken.kt | 3 ++ 16 files changed, 93 insertions(+), 49 deletions(-) diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/AddMember.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/AddMember.kt index 2be5370..34eaeb2 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/AddMember.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/AddMember.kt @@ -18,14 +18,20 @@ import org.xmlpull.v1.XmlPullParser data class AddMember( val href: String? ): Property { + companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "add-member") + } object Factory: PropertyFactory { + override fun getName() = NAME override fun create(parser: XmlPullParser) = AddMember(XmlReader(parser).readTextProperty(DavResource.HREF)) + } -} \ No newline at end of file + +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CreationDate.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CreationDate.kt index 6695471..f7ed594 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CreationDate.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CreationDate.kt @@ -14,15 +14,21 @@ import org.xmlpull.v1.XmlPullParser data class CreationDate( var creationDate: String? ): Property { + companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "creationdate") + } object Factory: PropertyFactory { + override fun getName() = NAME override fun create(parser: XmlPullParser) = CreationDate(XmlReader(parser).readText()) + } -} \ No newline at end of file + +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrincipal.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrincipal.kt index 0b5700a..4b44870 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrincipal.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrincipal.kt @@ -19,8 +19,10 @@ data class CurrentUserPrincipal( ): Property { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "current-user-principal") + } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrivilegeSet.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrivilegeSet.kt index ce3ee57..0e5bcc7 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrivilegeSet.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/CurrentUserPrivilegeSet.kt @@ -15,11 +15,11 @@ import org.xmlpull.v1.XmlPullParser data class CurrentUserPrivilegeSet( // not all privileges from RFC 3744 are implemented by now // feel free to add more if you need them for your project - var mayRead: Boolean = false, - var mayWriteProperties: Boolean = false, - var mayWriteContent: Boolean = false, - var mayBind: Boolean = false, - var mayUnbind: Boolean = false + val mayRead: Boolean = false, + val mayWriteProperties: Boolean = false, + val mayWriteContent: Boolean = false, + val mayBind: Boolean = false, + val mayUnbind: Boolean = false ): Property { companion object { @@ -46,7 +46,7 @@ data class CurrentUserPrivilegeSet( override fun create(parser: XmlPullParser): CurrentUserPrivilegeSet { // // - val privs = CurrentUserPrivilegeSet() + var privs = CurrentUserPrivilegeSet() XmlReader(parser).processTag(PRIVILEGE) { val depth = parser.depth @@ -55,27 +55,27 @@ data class CurrentUserPrivilegeSet( if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1) when (parser.propertyName()) { READ -> - privs.mayRead = true + privs = privs.copy(mayRead = true) WRITE -> { - privs.mayBind = true - privs.mayUnbind = true - privs.mayWriteProperties = true - privs.mayWriteContent = true + privs = privs.copy(mayBind = true) + privs = privs.copy(mayUnbind = true) + privs = privs.copy(mayWriteProperties = true) + privs = privs.copy(mayWriteContent = true) } WRITE_PROPERTIES -> - privs.mayWriteProperties = true + privs = privs.copy(mayWriteProperties = true) WRITE_CONTENT -> - privs.mayWriteContent = true + privs = privs.copy(mayWriteContent = true) BIND -> - privs.mayBind = true + privs = privs.copy(mayBind = true) UNBIND -> - privs.mayUnbind = true + privs = privs.copy(mayUnbind = true) ALL -> { - privs.mayRead = true - privs.mayBind = true - privs.mayUnbind = true - privs.mayWriteProperties = true - privs.mayWriteContent = true + privs = privs.copy(mayRead = true) + privs = privs.copy(mayBind = true) + privs = privs.copy(mayUnbind = true) + privs = privs.copy(mayWriteProperties = true) + privs = privs.copy(mayWriteContent = true) } } eventType = parser.next() @@ -84,5 +84,7 @@ data class CurrentUserPrivilegeSet( return privs } + } + } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/DisplayName.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/DisplayName.kt index 4e020b5..d067cfe 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/DisplayName.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/DisplayName.kt @@ -16,8 +16,10 @@ data class DisplayName( ): Property { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "displayname") + } @@ -30,4 +32,5 @@ data class DisplayName( DisplayName(XmlReader(parser).readText()) } + } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentLength.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentLength.kt index 075d120..2cb599a 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentLength.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentLength.kt @@ -14,15 +14,21 @@ import org.xmlpull.v1.XmlPullParser data class GetContentLength( val contentLength: Long? ) : Property { + companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "getcontentlength") + } object Factory: PropertyFactory { + override fun getName() = NAME override fun create(parser: XmlPullParser) = GetContentLength(XmlReader(parser).readLong()) + } -} \ No newline at end of file + +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentType.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentType.kt index 0ad80de..62c3433 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentType.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetContentType.kt @@ -18,8 +18,10 @@ data class GetContentType( ): Property { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "getcontenttype") + } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt index 1f507f1..fca84e7 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt @@ -19,8 +19,8 @@ import org.xmlpull.v1.XmlPullParser * Can also be used to parse ETags from HTTP responses – just pass the raw ETag * header value to the constructor and then use [eTag] and [weak]. */ -class GetETag( - rawETag: String? +data class GetETag( + val rawETag: String? ): Property { companion object { @@ -65,8 +65,6 @@ class GetETag( } } - override fun toString() = "ETag(weak=${weak}, tag=$eTag)" - override fun equals(other: Any?): Boolean { if (other !is GetETag) return false diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetLastModified.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetLastModified.kt index bd0db2c..abd22eb 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetLastModified.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetLastModified.kt @@ -9,16 +9,18 @@ package at.bitfire.dav4jvm.property.webdav import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlReader -import org.xmlpull.v1.XmlPullParser import java.time.Instant +import org.xmlpull.v1.XmlPullParser data class GetLastModified( - var lastModified: Instant? + val lastModified: Instant? ): Property { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "getlastmodified") + } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GroupMembership.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GroupMembership.kt index 90f434f..349be00 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GroupMembership.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GroupMembership.kt @@ -12,8 +12,10 @@ import org.xmlpull.v1.XmlPullParser class GroupMembership: HrefListProperty() { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "group-membership") + } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/Owner.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/Owner.kt index 851b861..6ead3d8 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/Owner.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/Owner.kt @@ -12,8 +12,10 @@ import org.xmlpull.v1.XmlPullParser class Owner: HrefListProperty() { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "owner") + } @@ -25,4 +27,4 @@ class Owner: HrefListProperty() { } -} \ No newline at end of file +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaAvailableBytes.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaAvailableBytes.kt index b39bb25..e8184bb 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaAvailableBytes.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaAvailableBytes.kt @@ -14,15 +14,21 @@ import org.xmlpull.v1.XmlPullParser data class QuotaAvailableBytes( val quotaAvailableBytes: Long? ) : Property { + companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "quota-available-bytes") + } object Factory: PropertyFactory { + override fun getName() = NAME override fun create(parser: XmlPullParser) = QuotaAvailableBytes(XmlReader(parser).readLong()) + } -} \ No newline at end of file + +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaUsedBytes.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaUsedBytes.kt index 221687c..603192b 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaUsedBytes.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/QuotaUsedBytes.kt @@ -14,15 +14,21 @@ import org.xmlpull.v1.XmlPullParser data class QuotaUsedBytes( val quotaUsedBytes: Long? ) : Property { + companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "quota-used-bytes") + } object Factory: PropertyFactory { + override fun getName() = NAME override fun create(parser: XmlPullParser) = QuotaUsedBytes(XmlReader(parser).readLong()) + } -} \ No newline at end of file + +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/ResourceType.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/ResourceType.kt index a052bdc..e41bdc6 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/ResourceType.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/ResourceType.kt @@ -13,9 +13,12 @@ import at.bitfire.dav4jvm.property.caldav.NS_CALENDARSERVER import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV import org.xmlpull.v1.XmlPullParser -class ResourceType: Property { +class ResourceType( + val types: Set = emptySet() +): Property { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "resourcetype") @@ -28,11 +31,8 @@ class ResourceType: Property { val CALENDAR_PROXY_READ = Property.Name(NS_CALENDARSERVER, "calendar-proxy-read") // CalDAV Proxy val CALENDAR_PROXY_WRITE = Property.Name(NS_CALENDARSERVER, "calendar-proxy-write") // CalDAV Proxy val SUBSCRIBED = Property.Name(NS_CALENDARSERVER, "subscribed") - } - val types = mutableSetOf() - - override fun toString() = "[${types.joinToString(", ")}]" + } object Factory: PropertyFactory { @@ -40,7 +40,7 @@ class ResourceType: Property { override fun getName() = NAME override fun create(parser: XmlPullParser): ResourceType { - val type = ResourceType() + val types = mutableSetOf() val depth = parser.depth var eventType = parser.eventType @@ -57,13 +57,13 @@ class ResourceType: Property { CALENDAR_PROXY_WRITE -> typeName = CALENDAR_PROXY_WRITE SUBSCRIBED -> typeName = SUBSCRIBED } - type.types.add(typeName) + types.add(typeName) } eventType = parser.next() } assert(parser.depth == depth) - return type + return ResourceType(types) } } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SupportedReportSet.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SupportedReportSet.kt index d2c5548..cf390c0 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SupportedReportSet.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SupportedReportSet.kt @@ -11,7 +11,9 @@ import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlReader import org.xmlpull.v1.XmlPullParser -class SupportedReportSet: Property { +data class SupportedReportSet( + val reports: Set = emptySet() +): Property { companion object { @@ -25,10 +27,6 @@ class SupportedReportSet: Property { } - val reports = mutableSetOf() - - override fun toString() = "[${reports.joinToString(", ")}]" - object Factory: PropertyFactory { @@ -40,17 +38,17 @@ class SupportedReportSet: Property { */ - val supported = SupportedReportSet() + val reports = mutableSetOf() XmlReader(parser).processTag(SUPPORTED_REPORT) { processTag(REPORT) { parser.nextTag() if (parser.eventType == XmlPullParser.TEXT) - supported.reports += parser.text + reports += parser.text else if (parser.eventType == XmlPullParser.START_TAG) - supported.reports += "${parser.namespace}${parser.name}" + reports += "${parser.namespace}${parser.name}" } } - return supported + return SupportedReportSet(reports) } } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SyncToken.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SyncToken.kt index 03057cd..0138ecb 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SyncToken.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/SyncToken.kt @@ -16,8 +16,10 @@ data class SyncToken( ): Property { companion object { + @JvmField val NAME = Property.Name(NS_WEBDAV, "sync-token") + } @@ -30,4 +32,5 @@ data class SyncToken( SyncToken(XmlReader(parser).readText()) } + }