Skip to content

Commit

Permalink
Migrated webdav properties
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <[email protected]>
  • Loading branch information
ArnyminerZ committed Dec 3, 2024
1 parent f90f8ab commit 978a5bd
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ data class CurrentUserPrincipal(
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV, "current-user-principal")

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,7 +46,7 @@ data class CurrentUserPrivilegeSet(
override fun create(parser: XmlPullParser): CurrentUserPrivilegeSet {
// <!ELEMENT current-user-privilege-set (privilege*)>
// <!ELEMENT privilege ANY>
val privs = CurrentUserPrivilegeSet()
var privs = CurrentUserPrivilegeSet()

XmlReader(parser).processTag(PRIVILEGE) {
val depth = parser.depth
Expand All @@ -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()
Expand All @@ -84,5 +84,7 @@ data class CurrentUserPrivilegeSet(

return privs
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ data class DisplayName(
): Property {

companion object {

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

}


Expand All @@ -30,4 +32,5 @@ data class DisplayName(
DisplayName(XmlReader(parser).readText())

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ data class GetContentType(
): Property {

companion object {

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

}


Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import org.xmlpull.v1.XmlPullParser
class GroupMembership: HrefListProperty() {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV, "group-membership")

}


Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/at/bitfire/dav4jvm/property/webdav/Owner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import org.xmlpull.v1.XmlPullParser
class Owner: HrefListProperty() {

companion object {

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

}


Expand All @@ -25,4 +27,4 @@ class Owner: HrefListProperty() {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Property.Name> = emptySet()
): Property {

companion object {

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

Expand All @@ -28,19 +31,16 @@ 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<Property.Name>()

override fun toString() = "[${types.joinToString(", ")}]"
}


object Factory: PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): ResourceType {
val type = ResourceType()
val types = mutableSetOf<Property.Name>()

val depth = parser.depth
var eventType = parser.eventType
Expand All @@ -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)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptySet()
): Property {

companion object {

Expand All @@ -25,10 +27,6 @@ class SupportedReportSet: Property {

}

val reports = mutableSetOf<String>()

override fun toString() = "[${reports.joinToString(", ")}]"


object Factory: PropertyFactory {

Expand All @@ -40,17 +38,17 @@ class SupportedReportSet: Property {
<!ELEMENT report ANY>
*/

val supported = SupportedReportSet()
val reports = mutableSetOf<String>()
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)
}

}
Expand Down
Loading

0 comments on commit 978a5bd

Please sign in to comment.