Skip to content

Commit

Permalink
Use packages to group properties by namespace (#32)
Browse files Browse the repository at this point in the history
* Use packages to group properties by namespace

* Adapt copyright
  • Loading branch information
rfc2822 authored Jan 17, 2024
1 parent 8d22ff2 commit 93dddcd
Show file tree
Hide file tree
Showing 59 changed files with 296 additions and 199 deletions.
22 changes: 12 additions & 10 deletions src/main/kotlin/at/bitfire/dav4jvm/DavAddressBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ package at.bitfire.dav4jvm
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.exception.DavException
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.AddressData
import at.bitfire.dav4jvm.property.GetContentType
import at.bitfire.dav4jvm.property.GetETag
import at.bitfire.dav4jvm.property.carddav.AddressData
import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV
import at.bitfire.dav4jvm.property.webdav.GetContentType
import at.bitfire.dav4jvm.property.webdav.GetETag
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand All @@ -32,9 +34,9 @@ class DavAddressBook @JvmOverloads constructor(
val MIME_VCARD3_UTF8 = "text/vcard;charset=utf-8".toMediaType()
val MIME_VCARD4 = "text/vcard;version=4.0".toMediaType()

val ADDRESSBOOK_QUERY = Property.Name(XmlUtils.NS_CARDDAV, "addressbook-query")
val ADDRESSBOOK_MULTIGET = Property.Name(XmlUtils.NS_CARDDAV, "addressbook-multiget")
val FILTER = Property.Name(XmlUtils.NS_CARDDAV, "filter")
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")
}

/**
Expand All @@ -59,8 +61,8 @@ class DavAddressBook @JvmOverloads constructor(
val writer = StringWriter()
serializer.setOutput(writer)
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.setPrefix("", NS_WEBDAV)
serializer.setPrefix("CARD", NS_CARDDAV)
serializer.insertTag(ADDRESSBOOK_QUERY) {
insertTag(PROP) {
insertTag(GetETag.NAME)
Expand Down Expand Up @@ -107,8 +109,8 @@ class DavAddressBook @JvmOverloads constructor(
val writer = StringWriter()
serializer.setOutput(writer)
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.setPrefix("", NS_WEBDAV)
serializer.setPrefix("CARD", NS_CARDDAV)
serializer.insertTag(ADDRESSBOOK_MULTIGET) {
insertTag(PROP) {
insertTag(GetContentType.NAME)
Expand Down
28 changes: 15 additions & 13 deletions src/main/kotlin/at/bitfire/dav4jvm/DavCalendar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ package at.bitfire.dav4jvm
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.exception.DavException
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.CalendarData
import at.bitfire.dav4jvm.property.GetContentType
import at.bitfire.dav4jvm.property.GetETag
import at.bitfire.dav4jvm.property.ScheduleTag
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.webdav.GetContentType
import at.bitfire.dav4jvm.property.webdav.GetETag
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand All @@ -37,13 +39,13 @@ class DavCalendar @JvmOverloads constructor(
val MIME_ICALENDAR = "text/calendar".toMediaType()
val MIME_ICALENDAR_UTF8 = "text/calendar;charset=utf-8".toMediaType()

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

val FILTER = Property.Name(XmlUtils.NS_CALDAV, "filter")
val COMP_FILTER = Property.Name(XmlUtils.NS_CALDAV, "comp-filter")
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(XmlUtils.NS_CALDAV, "time-range")
val TIME_RANGE = Property.Name(NS_CALDAV, "time-range")
const val TIME_RANGE_START = "start"
const val TIME_RANGE_END = "end"

Expand Down Expand Up @@ -82,8 +84,8 @@ class DavCalendar @JvmOverloads constructor(
val writer = StringWriter()
serializer.setOutput(writer)
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.setPrefix("", NS_WEBDAV)
serializer.setPrefix("CAL", NS_CALDAV)
serializer.insertTag(CALENDAR_QUERY) {
insertTag(PROP) {
insertTag(GetETag.NAME)
Expand Down Expand Up @@ -148,8 +150,8 @@ class DavCalendar @JvmOverloads constructor(
val writer = StringWriter()
serializer.setOutput(writer)
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.setPrefix("", NS_WEBDAV)
serializer.setPrefix("CAL", NS_CALDAV)
serializer.insertTag(CALENDAR_MULTIGET) {
insertTag(PROP) {
insertTag(GetContentType.NAME) // to determine the character set
Expand Down
13 changes: 7 additions & 6 deletions src/main/kotlin/at/bitfire/dav4jvm/DavCollection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ package at.bitfire.dav4jvm
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.exception.DavException
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.SyncToken
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.webdav.SyncToken
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
Expand All @@ -29,10 +30,10 @@ open class DavCollection @JvmOverloads constructor(
): DavResource(httpClient, location, log) {

companion object {
val SYNC_COLLECTION = Property.Name(XmlUtils.NS_WEBDAV, "sync-collection")
val SYNC_LEVEL = Property.Name(XmlUtils.NS_WEBDAV, "sync-level")
val LIMIT = Property.Name(XmlUtils.NS_WEBDAV, "limit")
val NRESULTS = Property.Name(XmlUtils.NS_WEBDAV, "nresults")
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")
}

/**
Expand Down Expand Up @@ -87,7 +88,7 @@ open class DavCollection @JvmOverloads constructor(
val writer = StringWriter()
serializer.setOutput(writer)
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("", NS_WEBDAV)
serializer.insertTag(SYNC_COLLECTION) {
insertTag(SyncToken.NAME) {
if (syncToken != null)
Expand Down
25 changes: 14 additions & 11 deletions src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import at.bitfire.dav4jvm.exception.NotFoundException
import at.bitfire.dav4jvm.exception.PreconditionFailedException
import at.bitfire.dav4jvm.exception.ServiceUnavailableException
import at.bitfire.dav4jvm.exception.UnauthorizedException
import at.bitfire.dav4jvm.property.SyncToken
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.webdav.SyncToken
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType
Expand Down Expand Up @@ -63,12 +66,12 @@ open class DavResource @JvmOverloads constructor(
const val HTTP_MULTISTATUS = 207
val MIME_XML = "application/xml; charset=utf-8".toMediaType()

val PROPFIND = Property.Name(XmlUtils.NS_WEBDAV, "propfind")
val PROPERTYUPDATE = Property.Name(XmlUtils.NS_WEBDAV, "propertyupdate")
val SET = Property.Name(XmlUtils.NS_WEBDAV, "set")
val REMOVE = Property.Name(XmlUtils.NS_WEBDAV, "remove")
val PROP = Property.Name(XmlUtils.NS_WEBDAV, "prop")
val HREF = Property.Name(XmlUtils.NS_WEBDAV, "href")
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 HREF = Property.Name(NS_WEBDAV, "href")

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

Expand All @@ -84,7 +87,7 @@ open class DavResource @JvmOverloads constructor(
val serializer = XmlUtils.newSerializer()
val writer = StringWriter()
serializer.setOutput(writer)
serializer.setPrefix("d", XmlUtils.NS_WEBDAV)
serializer.setPrefix("d", NS_WEBDAV)
serializer.startDocument("UTF-8", null)
serializer.insertTag(PROPERTYUPDATE) {
// DAV:set
Expand Down Expand Up @@ -486,9 +489,9 @@ open class DavResource @JvmOverloads constructor(
val serializer = XmlUtils.newSerializer()
val writer = StringWriter()
serializer.setOutput(writer)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.setPrefix("", NS_WEBDAV)
serializer.setPrefix("CAL", NS_CALDAV)
serializer.setPrefix("CARD", NS_CARDDAV)
serializer.startDocument("UTF-8", null)
serializer.insertTag(PROPFIND) {
insertTag(PROP) {
Expand Down
15 changes: 7 additions & 8 deletions src/main/kotlin/at/bitfire/dav4jvm/Error.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm

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

Expand All @@ -23,7 +22,7 @@ class Error(

companion object {

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

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

// some pre-defined errors

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

}

Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/at/bitfire/dav4jvm/PropStat.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm

import at.bitfire.dav4jvm.Response.Companion.STATUS
import at.bitfire.dav4jvm.XmlUtils.propertyName
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import okhttp3.Protocol
import okhttp3.internal.http.StatusLine
import org.xmlpull.v1.XmlPullParser
Expand All @@ -30,7 +29,7 @@ data class PropStat(
companion object {

@JvmField
val NAME = Property.Name(XmlUtils.NS_WEBDAV, "propstat")
val NAME = Property.Name(NS_WEBDAV, "propstat")

private val ASSUMING_OK = StatusLine(Protocol.HTTP_1_1, 200, "Assuming OK")
private val INVALID_STATUS = StatusLine(Protocol.HTTP_1_1, 500, "Invalid status line")
Expand Down
38 changes: 35 additions & 3 deletions src/main/kotlin/at/bitfire/dav4jvm/PropertyRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,39 @@

package at.bitfire.dav4jvm

import at.bitfire.dav4jvm.property.*
import at.bitfire.dav4jvm.property.caldav.CalendarColor
import at.bitfire.dav4jvm.property.caldav.CalendarData
import at.bitfire.dav4jvm.property.caldav.CalendarDescription
import at.bitfire.dav4jvm.property.caldav.CalendarHomeSet
import at.bitfire.dav4jvm.property.caldav.CalendarProxyReadFor
import at.bitfire.dav4jvm.property.caldav.CalendarProxyWriteFor
import at.bitfire.dav4jvm.property.caldav.CalendarTimezone
import at.bitfire.dav4jvm.property.caldav.CalendarUserAddressSet
import at.bitfire.dav4jvm.property.caldav.GetCTag
import at.bitfire.dav4jvm.property.caldav.ScheduleTag
import at.bitfire.dav4jvm.property.caldav.Source
import at.bitfire.dav4jvm.property.caldav.SupportedCalendarComponentSet
import at.bitfire.dav4jvm.property.caldav.SupportedCalendarData
import at.bitfire.dav4jvm.property.carddav.AddressData
import at.bitfire.dav4jvm.property.carddav.AddressbookDescription
import at.bitfire.dav4jvm.property.carddav.AddressbookHomeSet
import at.bitfire.dav4jvm.property.carddav.SupportedAddressData
import at.bitfire.dav4jvm.property.webdav.AddMember
import at.bitfire.dav4jvm.property.webdav.CreationDate
import at.bitfire.dav4jvm.property.webdav.CurrentUserPrincipal
import at.bitfire.dav4jvm.property.webdav.CurrentUserPrivilegeSet
import at.bitfire.dav4jvm.property.webdav.DisplayName
import at.bitfire.dav4jvm.property.webdav.GetContentLength
import at.bitfire.dav4jvm.property.webdav.GetContentType
import at.bitfire.dav4jvm.property.webdav.GetETag
import at.bitfire.dav4jvm.property.webdav.GetLastModified
import at.bitfire.dav4jvm.property.webdav.GroupMembership
import at.bitfire.dav4jvm.property.webdav.Owner
import at.bitfire.dav4jvm.property.webdav.QuotaAvailableBytes
import at.bitfire.dav4jvm.property.webdav.QuotaUsedBytes
import at.bitfire.dav4jvm.property.webdav.ResourceType
import at.bitfire.dav4jvm.property.webdav.SupportedReportSet
import at.bitfire.dav4jvm.property.webdav.SyncToken
import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException
import java.util.logging.Level
Expand Down Expand Up @@ -44,8 +76,8 @@ object PropertyRegistry {
GetETag.Factory,
GetLastModified.Factory,
GroupMembership.Factory,
MaxICalendarSize.Factory,
MaxVCardSize.Factory,
at.bitfire.dav4jvm.property.caldav.MaxResourceSize.Factory,
at.bitfire.dav4jvm.property.carddav.MaxResourceSize.Factory,
Owner.Factory,
QuotaAvailableBytes.Factory,
QuotaUsedBytes.Factory,
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/at/bitfire/dav4jvm/Response.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm

import at.bitfire.dav4jvm.Dav4jvm.log
import at.bitfire.dav4jvm.XmlUtils.propertyName
import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.webdav.ResourceType
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Protocol
Expand Down Expand Up @@ -94,10 +93,10 @@ data class Response(

companion object {

val RESPONSE = Property.Name(XmlUtils.NS_WEBDAV, "response")
val MULTISTATUS = Property.Name(XmlUtils.NS_WEBDAV, "multistatus")
val STATUS = Property.Name(XmlUtils.NS_WEBDAV, "status")
val LOCATION = Property.Name(XmlUtils.NS_WEBDAV, "location")
val RESPONSE = Property.Name(NS_WEBDAV, "response")
val MULTISTATUS = Property.Name(NS_WEBDAV, "multistatus")
val STATUS = Property.Name(NS_WEBDAV, "status")
val LOCATION = Property.Name(NS_WEBDAV, "location")

/**
* Parses an XML response element and calls the [callback] for it (when it has a `<href>`).
Expand Down
6 changes: 0 additions & 6 deletions src/main/kotlin/at/bitfire/dav4jvm/XmlUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import java.io.IOException

object XmlUtils {

const val NS_WEBDAV = "DAV:"
const val NS_CALDAV = "urn:ietf:params:xml:ns:caldav"
const val NS_CARDDAV = "urn:ietf:params:xml:ns:carddav"
const val NS_APPLE_ICAL = "http://apple.com/ns/ical/"
const val NS_CALENDARSERVER = "http://calendarserver.org/ns/"

private val factory: XmlPullParserFactory
init {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm.exception

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm.property
package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.Dav4jvm
import at.bitfire.dav4jvm.Property
Expand All @@ -20,7 +20,7 @@ data class CalendarColor(

companion object {
@JvmField
val NAME = Property.Name(XmlUtils.NS_APPLE_ICAL, "calendar-color")
val NAME = Property.Name(NS_APPLE_ICAL, "calendar-color")

private val PATTERN = Pattern.compile("#?(\\p{XDigit}{6})(\\p{XDigit}{2})?")!!

Expand Down
Loading

0 comments on commit 93dddcd

Please sign in to comment.