Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 51333c81 authored by Ricki Hirner's avatar Ricki Hirner Committed by GitHub
Browse files

Use centralized classes for property names (#126)

* Refactor WebDAV namespace and element constants into a dedicated object

- Move WebDAV namespace constant to a new `WebDAV` object
- Update all references to use the new `WebDAV` object for namespace and element constants
- Rename `namespace.kt` to `WebDAV.kt` to reflect its new purpose

* Update WebDAV property names to use centralized constants in WebDAV class

* Refactor CalDAV property names and remove redundant constants

- Move all CalDAV property names to a centralized `CalDAV` object.
- Remove redundant constants and use the centralized `CalDAV` object for property names.
- Update all references to use the new `CalDAV` object for consistency and maintainability.

* Refactor CardDAV property references to use CardDAV object

* Refactor WebDAV Push properties to use centralized namespace constants

- Move `NS_WEBDAV_PUSH` and property names to `WebDAVPush` object
- Update all property classes to reference `WebDAVPush` for namespace and property names
- Rename `namespace.kt` to `WebDAVPush.kt`
- Update tests to import `WebDAVPush` and use its constants

* Minor changes
parent 84f9d206
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@

package at.bitfire.dav4jvm

import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.webdav.WebDAV
import org.xmlpull.v1.XmlPullParser
import java.io.Serializable

@@ -28,7 +28,7 @@ data class Error(

    companion object {

        val NAME = Property.Name(NS_WEBDAV, "error")
        val NAME = Property.Name(WebDAV.NS_WEBDAV, "error")

        fun parseError(parser: XmlPullParser): List<Error> {
            val names = mutableSetOf<Property.Name>()
@@ -47,8 +47,8 @@ data class Error(

        // some pre-defined errors

        val NEED_PRIVILEGES = Error(Property.Name(NS_WEBDAV, "need-privileges"))
        val VALID_SYNC_TOKEN = Error(Property.Name(NS_WEBDAV, "valid-sync-token"))
        val NEED_PRIVILEGES = Error(Property.Name(WebDAV.NS_WEBDAV, "need-privileges"))
        val VALID_SYNC_TOKEN = Error(Property.Name(WebDAV.NS_WEBDAV, "valid-sync-token"))

    }

+16 −23
Original line number Diff line number Diff line
@@ -14,11 +14,8 @@ import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.XmlUtils
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.property.carddav.AddressData
import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV
import at.bitfire.dav4jvm.property.common.HrefListProperty
import at.bitfire.dav4jvm.property.webdav.GetContentType
import at.bitfire.dav4jvm.property.webdav.GetETag
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.carddav.CardDAV
import at.bitfire.dav4jvm.property.webdav.WebDAV
import io.ktor.client.HttpClient
import io.ktor.client.request.header
import io.ktor.client.request.prepareRequest
@@ -60,13 +57,13 @@ class DavAddressBook(
        val writer = StringWriter()
        serializer.setOutput(writer)
        serializer.startDocument("UTF-8", null)
        serializer.setPrefix("", NS_WEBDAV)
        serializer.setPrefix("CARD", NS_CARDDAV)
        serializer.insertTag(ADDRESSBOOK_QUERY) {
            insertTag(PROP) {
                insertTag(GetETag.NAME)
        serializer.setPrefix("", WebDAV.NS_WEBDAV)
        serializer.setPrefix("CARD", CardDAV.NS_CARDDAV)
        serializer.insertTag(CardDAV.AddressbookQuery) {
            insertTag(WebDAV.Prop) {
                insertTag(WebDAV.GetETag)
            }
            insertTag(FILTER)
            insertTag(CardDAV.Filter)
        }
        serializer.endDocument()

@@ -118,13 +115,13 @@ class DavAddressBook(
        val writer = StringWriter()
        serializer.setOutput(writer)
        serializer.startDocument("UTF-8", null)
        serializer.setPrefix("", NS_WEBDAV)
        serializer.setPrefix("CARD", NS_CARDDAV)
        serializer.insertTag(ADDRESSBOOK_MULTIGET) {
            insertTag(PROP) {
                insertTag(GetContentType.NAME)
                insertTag(GetETag.NAME)
                insertTag(AddressData.NAME) {
        serializer.setPrefix("", WebDAV.NS_WEBDAV)
        serializer.setPrefix("CARD", CardDAV.NS_CARDDAV)
        serializer.insertTag(CardDAV.AddressbookMultiget) {
            insertTag(WebDAV.Prop) {
                insertTag(WebDAV.GetContentType)
                insertTag(WebDAV.GetETag)
                insertTag(CardDAV.AddressData) {
                    if (contentType != null)
                        attribute(null, AddressData.CONTENT_TYPE, contentType)
                    if (version != null)
@@ -132,7 +129,7 @@ class DavAddressBook(
                }
            }
            for (url in urls)
                insertTag(HrefListProperty.HREF) {
                insertTag(WebDAV.Href) {
                    text(url.encodedPath)
                }
        }
@@ -161,10 +158,6 @@ class DavAddressBook(
        val MIME_VCARD3_UTF8 = ContentType.parse("text/vcard;charset=utf-8")
        val MIME_VCARD4 = ContentType.parse("text/vcard;version=4.0")

        val ADDRESSBOOK_QUERY = Property.Name(NS_CARDDAV, "addressbook-query")
        val ADDRESSBOOK_MULTIGET = Property.Name(NS_CARDDAV, "addressbook-multiget")
        val FILTER = Property.Name(NS_CARDDAV, "filter")

    }

}
 No newline at end of file
+20 −30
Original line number Diff line number Diff line
@@ -13,13 +13,9 @@ package at.bitfire.dav4jvm.ktor
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.XmlUtils
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.property.caldav.CalDAV
import at.bitfire.dav4jvm.property.caldav.CalendarData
import at.bitfire.dav4jvm.property.caldav.NS_CALDAV
import at.bitfire.dav4jvm.property.caldav.ScheduleTag
import at.bitfire.dav4jvm.property.common.HrefListProperty
import at.bitfire.dav4jvm.property.webdav.GetContentType
import at.bitfire.dav4jvm.property.webdav.GetETag
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.webdav.WebDAV
import io.ktor.client.HttpClient
import io.ktor.client.request.header
import io.ktor.client.request.prepareRequest
@@ -81,19 +77,19 @@ class DavCalendar(
        val writer = StringWriter()
        serializer.setOutput(writer)
        serializer.startDocument("UTF-8", null)
        serializer.setPrefix("", NS_WEBDAV)
        serializer.setPrefix("CAL", NS_CALDAV)
        serializer.insertTag(CALENDAR_QUERY) {
            insertTag(PROP) {
                insertTag(GetETag.NAME)
            }
            insertTag(FILTER) {
                insertTag(COMP_FILTER) {
        serializer.setPrefix("", WebDAV.NS_WEBDAV)
        serializer.setPrefix("CAL", CalDAV.NS_CALDAV)
        serializer.insertTag(CalDAV.CalendarQuery) {
            insertTag(WebDAV.Prop) {
                insertTag(WebDAV.GetETag)
            }
            insertTag(CalDAV.Filter) {
                insertTag(CalDAV.CompFilter) {
                    attribute(null, COMP_FILTER_NAME, "VCALENDAR")
                    insertTag(COMP_FILTER) {
                    insertTag(CalDAV.CompFilter) {
                        attribute(null, COMP_FILTER_NAME, component)
                        if (start != null || end != null) {
                            insertTag(TIME_RANGE) {
                            insertTag(CalDAV.TimeRange) {
                                if (start != null)
                                    attribute(null, TIME_RANGE_START, timeFormatUTC.format(
                                        ZonedDateTime.ofInstant(start, ZoneOffset.UTC)
@@ -157,14 +153,14 @@ class DavCalendar(
        val writer = StringWriter()
        serializer.setOutput(writer)
        serializer.startDocument("UTF-8", null)
        serializer.setPrefix("", NS_WEBDAV)
        serializer.setPrefix("CAL", NS_CALDAV)
        serializer.insertTag(CALENDAR_MULTIGET) {
            insertTag(PROP) {
                insertTag(GetContentType.NAME)     // to determine the character set
                insertTag(GetETag.NAME)
                insertTag(ScheduleTag.NAME)
                insertTag(CalendarData.NAME) {
        serializer.setPrefix("", WebDAV.NS_WEBDAV)
        serializer.setPrefix("CAL", CalDAV.NS_CALDAV)
        serializer.insertTag(CalDAV.CalendarMultiget) {
            insertTag(WebDAV.Prop) {
                insertTag(WebDAV.GetContentType)     // to determine the character set
                insertTag(WebDAV.GetETag)
                insertTag(CalDAV.ScheduleTag)
                insertTag(CalDAV.CalendarData) {
                    if (contentType != null)
                        attribute(null, CalendarData.CONTENT_TYPE, contentType)
                    if (version != null)
@@ -172,7 +168,7 @@ class DavCalendar(
                }
            }
            for (url in urls)
                insertTag(HrefListProperty.HREF) {
                insertTag(WebDAV.Href) {
                    serializer.text(url.encodedPath)
                }
        }
@@ -198,13 +194,7 @@ class DavCalendar(
        val MIME_ICALENDAR = ContentType.parse("text/calendar")
        val MIME_ICALENDAR_UTF8 = ContentType.parse("text/calendar;charset=utf-8")

        val CALENDAR_QUERY = Property.Name(NS_CALDAV, "calendar-query")
        val CALENDAR_MULTIGET = Property.Name(NS_CALDAV, "calendar-multiget")

        val FILTER = Property.Name(NS_CALDAV, "filter")
        val COMP_FILTER = Property.Name(NS_CALDAV, "comp-filter")
        const val COMP_FILTER_NAME = "name"
        val TIME_RANGE = Property.Name(NS_CALDAV, "time-range")
        const val TIME_RANGE_START = "start"
        const val TIME_RANGE_END = "end"

+8 −19
Original line number Diff line number Diff line
@@ -13,8 +13,7 @@ package at.bitfire.dav4jvm.ktor
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.XmlUtils
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.webdav.SyncToken
import at.bitfire.dav4jvm.property.webdav.WebDAV
import io.ktor.client.HttpClient
import io.ktor.client.request.header
import io.ktor.client.request.prepareRequest
@@ -73,22 +72,22 @@ open class DavCollection @JvmOverloads constructor(
        val writer = StringWriter()
        serializer.setOutput(writer)
        serializer.startDocument("UTF-8", null)
        serializer.setPrefix("", NS_WEBDAV)
        serializer.insertTag(SYNC_COLLECTION) {
            insertTag(SyncToken.Companion.NAME) {
        serializer.setPrefix("", WebDAV.NS_WEBDAV)
        serializer.insertTag(WebDAV.SyncCollection) {
            insertTag(WebDAV.SyncToken) {
                if (syncToken != null)
                    text(syncToken)
            }
            insertTag(SYNC_LEVEL) {
            insertTag(WebDAV.SyncLevel) {
                text(if (infiniteDepth) "infinite" else "1")
            }
            if (limit != null)
                insertTag(LIMIT) {
                    insertTag(NRESULTS) {
                insertTag(WebDAV.Limit) {
                    insertTag(WebDAV.NResults) {
                        text(limit.toString())
                    }
                }
            insertTag(PROP) {
            insertTag(WebDAV.Prop) {
                for (prop in properties)
                    insertTag(prop)
            }
@@ -111,14 +110,4 @@ open class DavCollection @JvmOverloads constructor(
        return result ?: emptyList()
    }


    companion object {

        val SYNC_COLLECTION = Property.Name(NS_WEBDAV, "sync-collection")
        val SYNC_LEVEL = Property.Name(NS_WEBDAV, "sync-level")
        val LIMIT = Property.Name(NS_WEBDAV, "limit")
        val NRESULTS = Property.Name(NS_WEBDAV, "nresults")

    }

}
 No newline at end of file
+17 −25
Original line number Diff line number Diff line
@@ -16,14 +16,12 @@ import at.bitfire.dav4jvm.XmlUtils
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.XmlUtils.propertyName
import at.bitfire.dav4jvm.ktor.DavResource.Companion.MAX_REDIRECTS
import at.bitfire.dav4jvm.ktor.Response.Companion.MULTISTATUS
import at.bitfire.dav4jvm.ktor.Response.Companion.RESPONSE
import at.bitfire.dav4jvm.ktor.exception.DavException
import at.bitfire.dav4jvm.ktor.exception.HttpException
import at.bitfire.dav4jvm.property.caldav.NS_CALDAV
import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.caldav.CalDAV
import at.bitfire.dav4jvm.property.carddav.CardDAV
import at.bitfire.dav4jvm.property.webdav.SyncToken
import at.bitfire.dav4jvm.property.webdav.WebDAV
import io.ktor.client.HttpClient
import io.ktor.client.plugins.compression.compress
import io.ktor.client.request.header
@@ -93,12 +91,6 @@ open class DavResource(

        val MIME_XML_UTF8 = ContentType.Application.Xml.withCharset(Charsets.UTF_8)

        val PROPFIND = Property.Name(NS_WEBDAV, "propfind")
        val PROPERTYUPDATE = Property.Name(NS_WEBDAV, "propertyupdate")
        val SET = Property.Name(NS_WEBDAV, "set")
        val REMOVE = Property.Name(NS_WEBDAV, "remove")
        val PROP = Property.Name(NS_WEBDAV, "prop")

        val XML_SIGNATURE = "<?xml".encodeToByteString()


@@ -113,14 +105,14 @@ open class DavResource(
            val serializer = XmlUtils.newSerializer()
            val writer = StringWriter()
            serializer.setOutput(writer)
            serializer.setPrefix("d", NS_WEBDAV)
            serializer.setPrefix("d", WebDAV.NS_WEBDAV)
            serializer.startDocument("UTF-8", null)
            serializer.insertTag(PROPERTYUPDATE) {
            serializer.insertTag(WebDAV.PropertyUpdate) {
                // DAV:set
                if (setProperties.isNotEmpty()) {
                    serializer.insertTag(SET) {
                    serializer.insertTag(WebDAV.Set) {
                        for (prop in setProperties) {
                            serializer.insertTag(PROP) {
                            serializer.insertTag(WebDAV.Prop) {
                                serializer.insertTag(prop.key) {
                                    text(prop.value)
                                }
@@ -131,9 +123,9 @@ open class DavResource(

                // DAV:remove
                if (removeProperties.isNotEmpty()) {
                    serializer.insertTag(REMOVE) {
                    serializer.insertTag(WebDAV.Remove) {
                        for (prop in removeProperties) {
                            insertTag(PROP) {
                            insertTag(WebDAV.Prop) {
                                insertTag(prop)
                            }
                        }
@@ -513,12 +505,12 @@ open class DavResource(
        val serializer = XmlUtils.newSerializer()
        val writer = StringWriter()
        serializer.setOutput(writer)
        serializer.setPrefix("", NS_WEBDAV)
        serializer.setPrefix("CAL", NS_CALDAV)
        serializer.setPrefix("CARD", NS_CARDDAV)
        serializer.setPrefix("", WebDAV.NS_WEBDAV)
        serializer.setPrefix("CAL", CalDAV.NS_CALDAV)
        serializer.setPrefix("CARD", CardDAV.NS_CARDDAV)
        serializer.startDocument("UTF-8", null)
        serializer.insertTag(PROPFIND) {
            insertTag(PROP) {
        serializer.insertTag(WebDAV.PropFind) {
            insertTag(WebDAV.Prop) {
                for (prop in reqProp)
                    insertTag(prop)
            }
@@ -769,7 +761,7 @@ open class DavResource(
                var eventType = parser.eventType
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    if (eventType == XmlPullParser.START_TAG && parser.depth == 1)
                        if (parser.propertyName() == MULTISTATUS) {
                        if (parser.propertyName() == WebDAV.MultiStatus) {
                            return parseMultiStatus(parser, callback)
                            // further <multistatus> elements are ignored
                        }
@@ -797,9 +789,9 @@ open class DavResource(
        while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
            if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1)
                when (parser.propertyName()) {
                    RESPONSE ->
                    WebDAV.Response ->
                        Response.parse(parser, location, callback)
                    SyncToken.NAME ->
                    WebDAV.SyncToken ->
                        XmlReader(parser).readText()?.let {
                            responseProperties += SyncToken(it)
                        }
Loading