Skip to content

Commit

Permalink
Support "text" inside "link" (metadata/wpt/author)
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Dec 19, 2024
1 parent 5efe824 commit 001e7ad
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,12 @@ object GpxUtilities {
writeCopyright(serializer, copyright)
serializer.endTag(null, "copyright")
}
writeNotNullTextWithAttribute(serializer, "link", "href", file.metadata.link)
if (file.metadata.link != null) {
serializer.startTag(null, "link")
serializer.attribute(null, "href", file.metadata.link!!)
writeNotNullText(serializer, "text", file.metadata.linkText)
serializer.endTag(null, "link")
}
if (file.metadata.time != 0L) {
writeNotNullText(serializer, "time", formatTime(file.metadata.time))
}
Expand Down Expand Up @@ -722,7 +727,12 @@ object GpxUtilities {
}
writeNotNullText(serializer, "name", p.name)
writeNotNullText(serializer, "desc", p.desc)
writeNotNullTextWithAttribute(serializer, "link", "href", p.link)
if (p.link != null) {
serializer.startTag(null, "link")
serializer.attribute(null, "href", p.link!!)
writeNotNullText(serializer, "text", p.linkText)
serializer.endTag(null, "link")
}
writeNotNullText(serializer, "type", p.category)
writeNotNullText(serializer, "cmt", p.comment)
if (!p.hdop.isNaN()) {
Expand Down Expand Up @@ -835,7 +845,12 @@ object GpxUtilities {
serializer.endTag(null, "email")
}
}
writeNotNullTextWithAttribute(serializer, "link", "href", author.link)
if (author.link != null) {
serializer.startTag(null, "link")
serializer.attribute(null, "href", author.link!!)
writeNotNullText(serializer, "text", author.linkText)
serializer.endTag(null, "link")
}
}

private fun writeCopyright(serializer: XmlSerializer, copyright: Copyright) {
Expand Down Expand Up @@ -1001,7 +1016,7 @@ object GpxUtilities {
extensionsReader: GpxExtensionsReader?,
addGeneralTrack: Boolean
): GpxFile {
val insideTagDepth = mutableMapOf("trk" to 0)
val insideTagDepth = mutableMapOf("trk" to 0, "link" to 0)
oneOffLogParseTimeErrors = true
val gpxFile = GpxFile(null)
gpxFile.metadata.time = 0
Expand Down Expand Up @@ -1164,6 +1179,11 @@ object GpxUtilities {
}

"link" -> parse.link = parser.getAttributeValue("", "href")
"text" -> {
if (insideTagDepth["link"]!! > 0) {
parse.linkText = readText(parser, "text")
}
}
"time" -> {
val text = readText(parser, "time")
parse.time = parseTime(text!!)
Expand All @@ -1188,8 +1208,12 @@ object GpxUtilities {
parse.email = "$id@$domain"
}
}

"link" -> parse.link = parser.getAttributeValue("", "href")
"text" -> {
if (insideTagDepth["link"]!! > 0) {
parse.linkText = readText(parser, "text")
}
}
}
}

Expand Down Expand Up @@ -1279,8 +1303,12 @@ object GpxUtilities {
} catch (_: NumberFormatException) {
}
}

"link" -> parse.link = parser.getAttributeValue("", "href")
"text" -> {
if (insideTagDepth["link"]!! > 0) {
parse.linkText = readText(parser, "text")
}
}
"category" -> parse.category = readText(parser, "category")
"type" -> {
if (parse.category == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ class Author : GpxExtensions {
var name: String? = null
var email: String? = null
var link: String? = null
var linkText: String? = null

constructor()

constructor(author: Author) {
name = author.name
email = author.email
link = author.link
linkText = author.linkText
copyExtensions(author)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Metadata : GpxExtensions {
var name: String? = null
var desc: String? = null
var link: String? = null
var linkText: String? = null
var keywords: String? = null
var time: Long = 0
var author: Author? = null
Expand All @@ -19,6 +20,7 @@ class Metadata : GpxExtensions {
name = source.name
desc = source.desc
link = source.link
linkText = source.linkText
keywords = source.keywords
time = source.time
val sourceAuthor = source.author
Expand Down Expand Up @@ -113,4 +115,4 @@ class Metadata : GpxExtensions {
fun getIndividualKeywords(): List<String> {
return if (keywords != null) keywords!!.split(",") else emptyList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class WptPt : GpxExtensions {
var lon: Double = 0.0
var name: String? = null
var link: String? = null
var linkText: String? = null
var category: String? = null
var desc: String? = null
var comment: String? = null
Expand All @@ -37,6 +38,7 @@ class WptPt : GpxExtensions {
lon = wptPt.lon
name = wptPt.name
link = wptPt.link
linkText = wptPt.linkText
category = wptPt.category
desc = wptPt.desc
comment = wptPt.comment
Expand Down Expand Up @@ -342,5 +344,4 @@ class WptPt : GpxExtensions {
fun setSpecialPointType(type: String?) {
getExtensionsToWrite()[GpxUtilities.POINT_TYPE_EXTENSION] = type!!
}

}
}

0 comments on commit 001e7ad

Please sign in to comment.