Commit e8d42d93 authored by Ricki Hirner's avatar Ricki Hirner

PropertyCollection -= operator, documentation, optimization

parent 92e56c2f
Pipeline #9099037 passed with stage
in 4 minutes and 31 seconds
......@@ -69,6 +69,7 @@ class DavAddressBook @JvmOverloads constructor(
assertMultiStatus(response)
members.clear()
related.clear()
response.body()?.charStream()?.use { processMultiStatus(it) }
}
......@@ -122,6 +123,7 @@ class DavAddressBook @JvmOverloads constructor(
assertMultiStatus(response)
members.clear()
related.clear()
response.body()?.charStream()?.use { processMultiStatus(it) }
}
......
......@@ -90,6 +90,7 @@ class DavCalendar @JvmOverloads constructor(
assertMultiStatus(response)
members.clear()
related.clear()
response.body()?.charStream()?.use { processMultiStatus(it) }
}
......@@ -137,6 +138,7 @@ class DavCalendar @JvmOverloads constructor(
assertMultiStatus(response)
members.clear()
related.clear()
response.body()?.charStream()?.use { processMultiStatus(it) }
}
......
......@@ -16,5 +16,4 @@ open class DavCollection(
httpClient: OkHttpClient,
location: HttpUrl,
log: Logger = Constants.log
): DavResource(httpClient, location, log) {
}
): DavResource(httpClient, location, log)
\ No newline at end of file
......@@ -85,7 +85,8 @@ open class DavResource @JvmOverloads constructor(
}
/**
* Sends a MKCOL request to this resource.
* Sends a MKCOL request to this resource. Response body will be closed unless
* an exception is thrown.
* @throws IOException on I/O error
* @throws HttpException on HTTP error
*/
......@@ -135,7 +136,7 @@ open class DavResource @JvmOverloads constructor(
val eTag = response.header("ETag")
if (TextUtils.isEmpty(eTag))
properties.remove(GetETag.NAME)
properties -= GetETag.NAME
else
properties[GetETag.NAME] = GetETag(eTag)
......@@ -184,7 +185,7 @@ open class DavResource @JvmOverloads constructor(
val eTag = response.header("ETag")
if (TextUtils.isEmpty(eTag))
properties.remove(GetETag.NAME)
properties -= GetETag.NAME
else
properties[GetETag.NAME] = GetETag(eTag)
......@@ -277,6 +278,7 @@ open class DavResource @JvmOverloads constructor(
related.clear()
}
// process and close multi-status response body
response.body()?.charStream()?.use { processMultiStatus(it) }
}
......@@ -285,7 +287,9 @@ open class DavResource @JvmOverloads constructor(
/**
* Checks the status from an HTTP response and throws an exception in case of an error.
* @param closeBody whether [response] shall be closed by this method
* @param closeBody whether [response] shall be closed by this method, unless an exception
* is thrown. When an exception is thrown, the body is not closed to allow
* reading for debugging.
* @throws HttpException in case of an HTTP error
*/
protected fun checkStatus(response: Response, closeBody: Boolean) {
......@@ -297,6 +301,7 @@ open class DavResource @JvmOverloads constructor(
/**
* Checks the status from an HTTP [StatusLine] and throws an exception in case of an error.
* The response body is not being closed.
* @throws HttpException in case of an HTTP error
*/
protected fun checkStatus(status: StatusLine) =
......@@ -304,6 +309,7 @@ open class DavResource @JvmOverloads constructor(
/**
* Checks the status from an HTTP response and throws an exception in case of an error.
* The response body is not being closed.
* @throws HttpException in case of an HTTP error
*/
protected fun checkStatus(code: Int, message: String?, response: Response?) {
......
......@@ -47,7 +47,7 @@ class PropertyCollection {
nsProperties[name.name] = property
}
fun remove(name: Property.Name) {
operator fun minusAssign(name: Property.Name) {
if (!properties.isInitialized())
return
......@@ -85,7 +85,7 @@ class PropertyCollection {
else {
// prop == null
if (removeNullValues)
remove(name)
this -= name
else if (get(name) == null) // never overwrite non-null values
set(name, null)
}
......
......@@ -18,7 +18,7 @@ object PropertyRegistry {
init {
Constants.log.info("Registering DAV property factories");
for (factory in ServiceLoader.load(PropertyFactory::class.java)) {
Constants.log.fine("Registering " + factory::class.java.name + " for " + factory.getName())
Constants.log.fine("Registering ${factory::class.java.name} for ${factory.getName()}")
register(factory)
}
}
......
......@@ -66,7 +66,7 @@ object XmlUtils {
var eventType = parser.eventType
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
if (eventType == XmlPullParser.START_TAG && parser.depth == depth+1 &&
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1 &&
Property.Name(parser.namespace, parser.name) == name)
list.add(parser.nextText())
eventType = parser.next()
......
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