Commit 6ec5b007 authored by Ricki Hirner's avatar Ricki Hirner 🐑
Browse files

Add AddMember property (RFC 5995); make some protected properties read-only

parent c1a23985
Pipeline #163146269 passed with stages
in 2 minutes and 1 second
......@@ -22,6 +22,7 @@ object PropertyRegistry {
private fun registerDefaultFactories() {
register(listOf(
AddMember.Factory(),
AddressbookDescription.Factory(),
AddressbookHomeSet.Factory(),
AddressData.Factory(),
......
......@@ -60,13 +60,25 @@ object XmlUtils {
return text
}
@Throws(IOException::class, XmlPullParserException::class)
fun readTextProperty(parser: XmlPullParser, name: Property.Name): String? {
val depth = parser.depth
var eventType = parser.eventType
var result: String? = null
while (!((eventType == XmlPullParser.END_TAG || eventType == XmlPullParser.END_DOCUMENT) && parser.depth == depth)) {
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1 && parser.propertyName() == name)
result = parser.nextText()
eventType = parser.next()
}
return result
}
@Throws(IOException::class, XmlPullParserException::class)
fun readTextPropertyList(parser: XmlPullParser, name: Property.Name, list: MutableCollection<String>) {
val depth = parser.depth
var eventType = parser.eventType
while (!((eventType == XmlPullParser.END_TAG || eventType == XmlPullParser.END_DOCUMENT) && parser.depth == depth)) {
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1 &&
Property.Name(parser.namespace, parser.name) == name)
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1 && parser.propertyName() == name)
list.add(parser.nextText())
eventType = parser.next()
}
......
/*
* 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.property
import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlUtils
import org.xmlpull.v1.XmlPullParser
/**
* Defined in RFC 5995 3.2.1 DAV:add-member Property (Protected).
*/
data class AddMember(
val href: String?
): Property {
companion object {
@JvmField
val NAME = Property.Name(XmlUtils.NS_WEBDAV, "add-member")
}
class Factory: PropertyFactory {
override fun getName() = NAME
override fun create(parser: XmlPullParser) =
AddMember(XmlUtils.readTextProperty(parser, DavResource.HREF))
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ class GetETag(
response.header("ETag")?.let { GetETag(it) }
}
var eTag: String?
val eTag: String?
init {
/* entity-tag = [ weak ] opaque-tag
......
......@@ -6,6 +6,7 @@
package at.bitfire.dav4jvm.property
import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlUtils
......@@ -22,7 +23,7 @@ abstract class HrefListProperty: Property {
abstract class Factory: PropertyFactory {
fun create(parser: XmlPullParser, list: HrefListProperty): HrefListProperty {
XmlUtils.readTextPropertyList(parser, Property.Name(XmlUtils.NS_WEBDAV, "href"), list.hrefs)
XmlUtils.readTextPropertyList(parser, DavResource.HREF, list.hrefs)
return list
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment