Files
agendula/dav/src/main/kotlin/at/bitfire/dav4jvm/PropertyRegistry.kt
T
makiolaj 5a81d3c2f5 sync(chunk 2a): vendor dav4jvm 2.2.1 as :dav
JitPack-only publishing conflicts with FAIL_ON_PROJECT_REPOS, artifacts are
unsigned and not immutable, and upstream shipped two breaking majors 19 days
apart. 2.2.1 is the last OkHttp release: 3.0.0 moved to Ktor and 4.x needs
Java 21, and SYNC.md's whole auth section is written in OkHttp terms, so 4.x
would have invalidated it. A plain JVM module, not an Android library — the
tree has no Android imports and keeping it that way keeps the floret-kit
extraction a file move.

Four changes from upstream, all in dav/PROVENANCE.md:
- commons-lang3 dropped (one import, one call). The replacement requires the
  whole string to be consumed, as DateUtils did: pattern 1 ends in a literal
  'GMT', so SimpleDateFormat would match "...GMT+02:00" as a prefix and throw
  the offset away.
- HTTP dates were parsed and formatted in the device's local zone — the GMT in
  the format string is a quoted literal and timeZone was never set, so every
  getlastmodified was out by the local UTC offset. Upstream tests dates
  nowhere. The formatter is also no longer shared and mutable.
- dav4jvm#209: permanent redirects now reach the caller via
  DavResource.permanentLocation, cleared per request so it never describes an
  earlier one.
- xpp3 is compileOnly; Android supplies org.xmlpull.v1.

SYNC.md's other claimed defect, "does not follow 303", is not true of 2.2.1 —
pinned by a test rather than removed from the notes.

CI names :dav:test explicitly; testDebugUnitTest is Android-only and would
have run none of the vendored suite. lintDebug added to the per-chunk checks
after it caught a literal byte-order mark left by chunk 1.
2026-09-04 17:12:27 +02:00

96 lines
3.0 KiB
Kotlin

/*
* 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.*
import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException
import java.util.logging.Level
object PropertyRegistry {
private val factories = mutableMapOf<Property.Name, PropertyFactory>()
init {
Dav4jvm.log.info("Registering DAV property factories")
registerDefaultFactories()
}
private fun registerDefaultFactories() {
register(listOf(
AddMember.Factory,
AddressbookDescription.Factory,
AddressbookHomeSet.Factory,
AddressData.Factory,
CalendarColor.Factory,
CalendarData.Factory,
CalendarDescription.Factory,
CalendarHomeSet.Factory,
CalendarProxyReadFor.Factory,
CalendarProxyWriteFor.Factory,
CalendarTimezone.Factory,
CalendarUserAddressSet.Factory,
CreationDate.Factory,
CurrentUserPrincipal.Factory,
CurrentUserPrivilegeSet.Factory,
DisplayName.Factory,
GetContentLength.Factory,
GetContentType.Factory,
GetCTag.Factory,
GetETag.Factory,
GetLastModified.Factory,
GroupMembership.Factory,
MaxICalendarSize.Factory,
MaxVCardSize.Factory,
Owner.Factory,
QuotaAvailableBytes.Factory,
QuotaUsedBytes.Factory,
ResourceType.Factory,
ScheduleTag.Factory,
Source.Factory,
SupportedAddressData.Factory,
SupportedCalendarComponentSet.Factory,
SupportedCalendarData.Factory,
SupportedReportSet.Factory,
SyncToken.Factory
))
}
/**
* Registers a property factory, so that objects for all WebDAV properties which are handled
* by this factory can be created.
*
* @param factory property factory to be registered
*/
fun register(factory: PropertyFactory) {
Dav4jvm.log.fine("Registering ${factory::class.java.name} for ${factory.getName()}")
factories[factory.getName()] = factory
}
/**
* Registers some property factories, so that objects for all WebDAV properties which are handled
* by these factories can be created.
* @param factories property factories to be registered
*/
fun register(factories: Iterable<PropertyFactory>) {
factories.forEach {
register(it)
}
}
fun create(name: Property.Name, parser: XmlPullParser) =
try {
factories[name]?.create(parser)
} catch (e: XmlPullParserException) {
Dav4jvm.log.log(Level.WARNING, "Couldn't parse $name", e)
null
}
}