Skip to content

Commit e9f15e4

Browse files
ArnyminerZCopilot
andauthored
Create specific HREF definition for HrefListProperty (#105)
* Create specific `HREF` definition for `HrefListProperty` * Update src/main/kotlin/at/bitfire/dav4jvm/property/common/HrefListProperty.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Deprecate HREF Signed-off-by: Arnau Mora <arnyminerz@proton.me> * Remove `HREF` Signed-off-by: Arnau Mora <arnyminerz@proton.me> --------- Signed-off-by: Arnau Mora <arnyminerz@proton.me> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent dfe4fa1 commit e9f15e4

File tree

12 files changed

+35
-42
lines changed

12 files changed

+35
-42
lines changed

src/main/kotlin/at/bitfire/dav4jvm/ktor/DavAddressBook.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ import at.bitfire.dav4jvm.XmlUtils
1515
import at.bitfire.dav4jvm.XmlUtils.insertTag
1616
import at.bitfire.dav4jvm.property.carddav.AddressData
1717
import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV
18+
import at.bitfire.dav4jvm.property.common.HrefListProperty
1819
import at.bitfire.dav4jvm.property.webdav.GetContentType
1920
import at.bitfire.dav4jvm.property.webdav.GetETag
2021
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
21-
import io.ktor.client.HttpClient
22-
import io.ktor.client.request.prepareRequest
23-
import io.ktor.client.request.setBody
24-
import io.ktor.client.request.url
25-
import io.ktor.http.ContentType
26-
import io.ktor.http.HttpHeaders
27-
import io.ktor.http.HttpMethod
28-
import io.ktor.http.Url
29-
import io.ktor.util.logging.Logger
22+
import io.ktor.client.*
23+
import io.ktor.client.request.*
24+
import io.ktor.http.*
25+
import io.ktor.util.logging.*
3026
import org.slf4j.LoggerFactory
3127
import java.io.StringWriter
3228

@@ -133,7 +129,7 @@ class DavAddressBook @JvmOverloads constructor(
133129
}
134130
}
135131
for (url in urls)
136-
insertTag(HREF) {
132+
insertTag(HrefListProperty.HREF) {
137133
text(url.encodedPath)
138134
}
139135
}

src/main/kotlin/at/bitfire/dav4jvm/ktor/DavCalendar.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@ import at.bitfire.dav4jvm.XmlUtils.insertTag
1616
import at.bitfire.dav4jvm.property.caldav.CalendarData
1717
import at.bitfire.dav4jvm.property.caldav.NS_CALDAV
1818
import at.bitfire.dav4jvm.property.caldav.ScheduleTag
19+
import at.bitfire.dav4jvm.property.common.HrefListProperty
1920
import at.bitfire.dav4jvm.property.webdav.GetContentType
2021
import at.bitfire.dav4jvm.property.webdav.GetETag
2122
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
22-
import io.ktor.client.HttpClient
23-
import io.ktor.client.request.prepareRequest
24-
import io.ktor.client.request.setBody
25-
import io.ktor.client.request.url
26-
import io.ktor.http.ContentType
27-
import io.ktor.http.HttpHeaders
28-
import io.ktor.http.HttpMethod
29-
import io.ktor.http.Url
30-
import io.ktor.util.logging.Logger
23+
import io.ktor.client.*
24+
import io.ktor.client.request.*
25+
import io.ktor.http.*
26+
import io.ktor.util.logging.*
3127
import org.slf4j.LoggerFactory
3228
import java.io.StringWriter
3329
import java.time.Instant
3430
import java.time.ZoneOffset
3531
import java.time.ZonedDateTime
3632
import java.time.format.DateTimeFormatter
37-
import java.util.Locale
33+
import java.util.*
3834

3935
@Suppress("unused")
4036
class DavCalendar @JvmOverloads constructor(
@@ -175,7 +171,7 @@ class DavCalendar @JvmOverloads constructor(
175171
}
176172
}
177173
for (url in urls)
178-
insertTag(HREF) {
174+
insertTag(HrefListProperty.HREF) {
179175
serializer.text(url.encodedPath)
180176
}
181177
}

src/main/kotlin/at/bitfire/dav4jvm/ktor/DavResource.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ open class DavResource @JvmOverloads constructor(
100100
val SET = Property.Name(NS_WEBDAV, "set")
101101
val REMOVE = Property.Name(NS_WEBDAV, "remove")
102102
val PROP = Property.Name(NS_WEBDAV, "prop")
103-
val HREF = Property.Name(NS_WEBDAV, "href")
104103

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

src/main/kotlin/at/bitfire/dav4jvm/ktor/Response.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ package at.bitfire.dav4jvm.ktor
1313
import at.bitfire.dav4jvm.Error
1414
import at.bitfire.dav4jvm.Property
1515
import at.bitfire.dav4jvm.XmlUtils.propertyName
16+
import at.bitfire.dav4jvm.property.common.HrefListProperty
1617
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
1718
import at.bitfire.dav4jvm.property.webdav.ResourceType
18-
import io.ktor.http.HttpStatusCode
19-
import io.ktor.http.URLBuilder
20-
import io.ktor.http.Url
21-
import io.ktor.http.isSuccess
22-
import io.ktor.http.takeFrom
19+
import io.ktor.http.*
2320
import org.xmlpull.v1.XmlPullParser
2421
import java.util.logging.Logger
2522

@@ -131,7 +128,7 @@ data class Response(
131128
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
132129
if (eventType == XmlPullParser.START_TAG && parser.depth == depth+1)
133130
when (parser.propertyName()) {
134-
DavResource.Companion.HREF -> {
131+
HrefListProperty.HREF -> {
135132
var sHref = parser.nextText()
136133
var hierarchical = false
137134
if (!sHref.startsWith("/")) {

src/main/kotlin/at/bitfire/dav4jvm/okhttp/DavAddressBook.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import at.bitfire.dav4jvm.XmlUtils
1515
import at.bitfire.dav4jvm.XmlUtils.insertTag
1616
import at.bitfire.dav4jvm.property.carddav.AddressData
1717
import at.bitfire.dav4jvm.property.carddav.NS_CARDDAV
18+
import at.bitfire.dav4jvm.property.common.HrefListProperty
1819
import at.bitfire.dav4jvm.property.webdav.GetContentType
1920
import at.bitfire.dav4jvm.property.webdav.GetETag
2021
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
@@ -128,7 +129,7 @@ class DavAddressBook @JvmOverloads constructor(
128129
}
129130
}
130131
for (url in urls)
131-
insertTag(HREF) {
132+
insertTag(HrefListProperty.HREF) {
132133
text(url.encodedPath)
133134
}
134135
}

src/main/kotlin/at/bitfire/dav4jvm/okhttp/DavCalendar.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import at.bitfire.dav4jvm.okhttp.exception.HttpException
1818
import at.bitfire.dav4jvm.property.caldav.CalendarData
1919
import at.bitfire.dav4jvm.property.caldav.NS_CALDAV
2020
import at.bitfire.dav4jvm.property.caldav.ScheduleTag
21+
import at.bitfire.dav4jvm.property.common.HrefListProperty
2122
import at.bitfire.dav4jvm.property.webdav.GetContentType
2223
import at.bitfire.dav4jvm.property.webdav.GetETag
2324
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
@@ -32,7 +33,7 @@ import java.time.Instant
3233
import java.time.ZoneOffset
3334
import java.time.ZonedDateTime
3435
import java.time.format.DateTimeFormatter
35-
import java.util.Locale
36+
import java.util.*
3637
import java.util.logging.Logger
3738

3839
@Suppress("unused")
@@ -172,7 +173,7 @@ class DavCalendar @JvmOverloads constructor(
172173
}
173174
}
174175
for (url in urls)
175-
insertTag(HREF) {
176+
insertTag(HrefListProperty.HREF) {
176177
serializer.text(url.encodedPath)
177178
}
178179
}

src/main/kotlin/at/bitfire/dav4jvm/okhttp/DavResource.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ open class DavResource @JvmOverloads constructor(
8080
val SET = Property.Name(NS_WEBDAV, "set")
8181
val REMOVE = Property.Name(NS_WEBDAV, "remove")
8282
val PROP = Property.Name(NS_WEBDAV, "prop")
83-
val HREF = Property.Name(NS_WEBDAV, "href")
8483

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

src/main/kotlin/at/bitfire/dav4jvm/okhttp/Response.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package at.bitfire.dav4jvm.okhttp
1313
import at.bitfire.dav4jvm.Error
1414
import at.bitfire.dav4jvm.Property
1515
import at.bitfire.dav4jvm.XmlUtils.propertyName
16+
import at.bitfire.dav4jvm.property.common.HrefListProperty
1617
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
1718
import at.bitfire.dav4jvm.property.webdav.ResourceType
1819
import okhttp3.HttpUrl
@@ -131,7 +132,7 @@ data class Response(
131132
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
132133
if (eventType == XmlPullParser.START_TAG && parser.depth == depth+1)
133134
when (parser.propertyName()) {
134-
DavResource.HREF -> {
135+
HrefListProperty.HREF -> {
135136
var sHref = parser.nextText()
136137
if (!sHref.startsWith("/")) {
137138
/* According to RFC 4918 8.3 URL Handling, only absolute paths are allowed as relative

src/main/kotlin/at/bitfire/dav4jvm/property/common/HrefListProperty.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
package at.bitfire.dav4jvm.property.common
1212

13-
import at.bitfire.dav4jvm.ktor.DavResource
1413
import at.bitfire.dav4jvm.Property
1514
import at.bitfire.dav4jvm.PropertyFactory
1615
import at.bitfire.dav4jvm.XmlReader
16+
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
1717
import org.xmlpull.v1.XmlPullParser
1818

1919
/**
@@ -30,7 +30,7 @@ abstract class HrefListProperty(
3030
@Deprecated("hrefs is no longer mutable.", level = DeprecationLevel.ERROR)
3131
fun create(parser: XmlPullParser, list: HrefListProperty): HrefListProperty {
3232
val hrefs = list.hrefs.toMutableList()
33-
XmlReader(parser).readTextPropertyList(DavResource.Companion.HREF, hrefs)
33+
XmlReader(parser).readTextPropertyList(HREF, hrefs)
3434
return list
3535
}
3636

@@ -39,10 +39,14 @@ abstract class HrefListProperty(
3939
constructor: (hrefs: List<String>
4040
) -> PropertyType): PropertyType {
4141
val hrefs = mutableListOf<String>()
42-
XmlReader(parser).readTextPropertyList(DavResource.Companion.HREF, hrefs)
42+
XmlReader(parser).readTextPropertyList(HREF, hrefs)
4343
return constructor(hrefs)
4444
}
4545

4646
}
4747

48+
companion object {
49+
val HREF = Property.Name(NS_WEBDAV, "href")
50+
}
51+
4852
}

src/main/kotlin/at/bitfire/dav4jvm/property/webdav/AddMember.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
package at.bitfire.dav4jvm.property.webdav
1212

13-
import at.bitfire.dav4jvm.ktor.DavResource
1413
import at.bitfire.dav4jvm.Property
1514
import at.bitfire.dav4jvm.PropertyFactory
1615
import at.bitfire.dav4jvm.XmlReader
16+
import at.bitfire.dav4jvm.property.common.HrefListProperty
1717
import org.xmlpull.v1.XmlPullParser
1818

1919
/**
@@ -34,7 +34,7 @@ data class AddMember(
3434

3535
override fun getName() = NAME
3636

37-
override fun create(parser: XmlPullParser) = AddMember(XmlReader(parser).readTextProperty(DavResource.HREF))
37+
override fun create(parser: XmlPullParser) = AddMember(XmlReader(parser).readTextProperty(HrefListProperty.HREF))
3838

3939
}
4040

0 commit comments

Comments
 (0)