Compare commits

...

39 Commits
1.3 ... master

Author SHA1 Message Date
bvn13 0cbb67b94c Merge branch 'release/1.10.4' 2023-03-26 22:11:43 +03:00
bvn13 81585259d5 Update versions for release 2023-03-26 22:11:22 +03:00
bvn13 1452580c5f extensions support NULL values 2023-03-26 22:11:06 +03:00
bvn13 2239bd0b6e Update for next development version 2023-03-26 18:47:08 +03:00
bvn13 fa8da81778 Merge branch 'release/1.10.3' 2023-03-26 18:47:06 +03:00
bvn13 e1cff439f1 Merge tag '1.10.3' into develop
Tag release
2023-03-26 18:47:06 +03:00
bvn13 6e91251fe3 Update versions for release 2023-03-26 18:46:43 +03:00
bvn13 7115d3b2d6 fixed issue with xml signature reading 2023-03-26 18:46:28 +03:00
bvn13 c1497dc29c Update for next development version 2023-03-02 18:05:16 +03:00
bvn13 f43d17adcb Merge branch 'release/1.10.2' 2023-03-02 18:05:13 +03:00
bvn13 000b6568cf Merge tag '1.10.2' into develop
Tag release
2023-03-02 18:05:13 +03:00
bvn13 bc707c3f87 Update versions for release 2023-03-02 18:04:49 +03:00
bvn13 7c410989aa catching errors while writing date 2023-03-02 18:04:38 +03:00
bvn13 7be4a70cba Update for next development version 2023-03-02 17:43:10 +03:00
bvn13 9168ae9875 Merge branch 'release/1.10.1' 2023-03-02 17:43:07 +03:00
bvn13 b9fe91b64d Merge tag '1.10.1' into develop
Tag release
2023-03-02 17:43:07 +03:00
bvn13 4425533d55 Update versions for release 2023-03-02 17:42:39 +03:00
bvn13 3845cdcaa6 catching errors while writing date 2023-03-02 17:42:08 +03:00
bvn13 a3f11bcc3f Update for next development version 2023-03-01 23:18:37 +03:00
bvn13 5cd28903a8 Merge branch 'release/1.9' 2023-03-01 23:18:36 +03:00
bvn13 2caffadc63 Merge tag '1.9' into develop
Tag release
2023-03-01 23:18:36 +03:00
bvn13 ef995dbf2c Update versions for release 2023-03-01 23:18:05 +03:00
bvn13 7446dfe47d fixed reading camelCase extensions 2023-03-01 23:17:48 +03:00
bvn13 a54008563e Update for next development version 2023-02-13 20:05:53 +03:00
bvn13 729113b428 Merge branch 'release/1.8' 2023-02-13 20:05:51 +03:00
bvn13 4e73751f34 Merge tag '1.8' into develop
Tag release
2023-02-13 20:05:51 +03:00
bvn13 9997c7302b Update versions for release 2023-02-13 20:05:29 +03:00
bvn13 3a13dbcd50 version 1.8 - fixed and updating reading, fixed and updating writing 2023-02-13 20:05:01 +03:00
bvn13 2966a5ea61 Update for next development version 2022-12-18 13:18:40 +03:00
bvn13 7538b35b0b version 1.7 2022-12-18 13:17:58 +03:00
bvn13 17787e4281 Update for next development version 2022-12-18 13:13:47 +03:00
bvn13 2aebdfaaca version 1.6 2022-12-18 13:13:02 +03:00
bvn13 ad125f0bef Update for next development version 2022-12-18 13:06:35 +03:00
bvn13 a545819942 version 1.5 2022-12-18 13:05:05 +03:00
bvn13 064a1dc7b6 Merge pull request 'feature/1/reader' (#2) from feature/1/reader into master
Reviewed-on: #2
2022-12-18 13:03:12 +03:00
bvn13 2e2f02ca62 fixed #1 - reader implemented 2022-12-18 13:02:13 +03:00
bvn13 d2c728dc90 before refactoring 2022-12-15 19:27:01 +03:00
bvn13 68cf83f408 Update for next development version 2022-09-29 20:42:56 +03:00
bvn13 01f8a895a3 Merge tag '1.3' into develop
Tag release
2022-09-29 20:42:54 +03:00
21 changed files with 37868 additions and 121 deletions

7
.gitignore vendored
View File

@ -368,4 +368,9 @@ gradle-app.setting
**/build/
# End of https://www.toptal.com/developers/gitignore/api/java,gradle,git,intellij,linux,windows,macos,node
**/target/
**/target/
.idea/
.idea/**
GpxAndroidSdk.iml

View File

@ -1,81 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="5" platform="JVM 1.8" allPlatforms="JVM [1.8]" useProjectSettings="false">
<compilerSettings />
<compilerArguments>
<stringArguments>
<stringArg name="jvmTarget" arg="1.8" />
<stringArg name="apiVersion" arg="1.7" />
<stringArg name="languageVersion" arg="1.7" />
</stringArguments>
<arrayArguments>
<arrayArg name="pluginClasspaths" />
<arrayArg name="pluginOptions" />
</arrayArguments>
</compilerArguments>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test-junit5:1.7.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test:1.7.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.7.10" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-runner-junit5-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-api-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:1.6.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-common-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-engine-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.github.classgraph:classgraph:4.8.149" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.ajalt:mordant:1.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.ajalt:colormath:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.6.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna:5.9.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna-platform:5.9.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.10.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-discovery-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-extensions-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.11.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-common:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-dsl:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-dsl-jvm:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-agent-jvm:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-agent-api:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-agent-common:1.12.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:3.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-concurrency-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-suite-api:1.7.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-launcher:1.7.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-reflect:1.6.21" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-assertions-core-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-assertions-shared-jvm:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.github.java-diff-utils:java-diff-utils:4.12" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-assertions-api-jvm:5.4.2" level="project" />
</component>
</module>

437
README.md
View File

@ -1,22 +1,45 @@
# Android (Kotlin) SDK for manipulating GPX files
![](https://img.shields.io/maven-central/v/me.bvn13.sdk.android.gpx/GpxAndroidSdk)
## About
This is another one SDK for reading and writing (manipulating) GPX files.
Official GPX format is on [topografix](https://www.topografix.com/GPX/1/1/) site.
## Why this one?
1. This library supports GPX v1.1 format
2. This library reads and writes files in one pass
3. This library works without any external dependency
## Changelog
### 2023-03-26
1) Fixed signature reading
2) Since 1.10.4 extensions can have NULL as values
### 2023-02-13
1) Fixed missed extensions
2) ✅ Tested on reading with self written content
3) ✅ Tested on reading [OsmAnd](https://osmand.net) GPX files
### 2022-12-18
1) Implemented GPX format reader
### 2022-09-25
1) project started
2) implemented GPX format in Kotlin
3) implemented representing GPX object into String for future saving
1) Project started
2) Implemented GPX format in Kotlin
3) Implemented representing GPX object into String for future saving
## Examples
### Full example
### Writer example
```kotlin
val gpxType = GpxType(
@ -336,4 +359,410 @@ this example will be presented in GPX as following
</trkseg>
</trk>
</gpx>
```
### Reader example
```kotlin
val clock = Clock.fixed(
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
)
val gpxType = GpxType(
MetadataType("test name", description = "test description", authorName = "bvn13"),
wpt = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
),
rte = listOf(
RteType(
name = "rte name",
cmt = "cmt",
desc = "desc",
src = "src",
link = listOf(
LinkType(
href = "https://new.link.rte",
text = "new text rte",
type = "hyperlink"
)
),
number = 1234,
type = "route",
extensions = listOf(
ExtensionType(
"ext-1",
value = "value1"
)
),
rtept = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
)
)
),
trk = listOf(
TrkType(
name = "track 1",
cmt = "comment track 1",
desc = "desc track 1",
src = "src track 1",
number = 1234,
type = "type 1",
trkseg = listOf(
TrksegType(
listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
),
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
)
)
)
)
)
)
val gpxString = """
<?xml version="1.0" encoding="UTF-8"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
version="1.1"
creator="me.bvn13.sdk.android.gpx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<time>2022-09-24T15:04:00+03:00</time>
<metadata>
<name>test name</name>
<desc>test description</desc>
<author>
<name>bvn13</name>
</author>
</metadata>
<wpt lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</wpt>
<rte>
<name>rte name</name>
<cmt>cmt</cmt>
<desc>desc</desc>
<src>src</src>
<link href="https://new.link.rte">
<text>new text rte</text>
<type>hyperlink</type>
</link>
<number>1234</number>
<type>route</type>
<extensions>
<ext-1>value1</ext-1>
</extensions>
<rtept lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</rtept>
</rte>
<trk>
<name>track 1</name>
<cmt>comment track 1</cmt>
<desc>desc track 1</desc>
<src>src track 1</src>
<number>1234</number>
<type>type 1</type>
<trkseg>
<trkpt lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</trkpt>
<trkpt lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</trkpt>
</trkseg>
</trk>
</gpx>
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
val gpx = GpxType.read(gpxString.byteInputStream())
assertEquals(gpxType, gpx)
```

15
pom.xml
View File

@ -6,7 +6,7 @@
<artifactId>GpxAndroidSdk</artifactId>
<groupId>me.bvn13.sdk.android.gpx</groupId>
<version>1.3</version>
<version>1.10.4</version>
<packaging>jar</packaging>
@ -58,6 +58,11 @@
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
@ -234,7 +239,7 @@
<developmentBranch>develop</developmentBranch>
</gitFlowConfig>
<incrementVersionAtFinish>true</incrementVersionAtFinish>
<versionDigitToIncrement>2</versionDigitToIncrement>
<versionDigitToIncrement>3</versionDigitToIncrement>
</configuration>
</plugin>
</plugins>
@ -253,10 +258,10 @@
</developers>
<scm>
<connection>scm:git:git://github.com/bvn13/OpenFeign-NormalizedLogger.git</connection>
<developerConnection>scm:git:ssh://git@github.com:bvn13/OpenFeign-NormalizedLogger.git</developerConnection>
<connection>scm:git:git@github.com:bvn13/GpxAndroidSdk.git</connection>
<developerConnection>scm:git:git@github.com:bvn13/GpxAndroidSdk.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/bvn13/OpenFeign-NormalizedLogger.git</url>
<url>https://github.com/bvn13/GpxAndroidSdk</url>
</scm>
<profiles>

View File

@ -92,10 +92,29 @@ package me.bvn13.sdk.android.gpx
*
* [parameters] Map of key-value pairs
*/
class ExtensionType(val nodeName: String, val value: String? = null, val parameters: Map<String, String>? = null) {
init {
require(value != null || parameters != null) {
"value or parameters must be specified"
}
class ExtensionType(val nodeName: String,
val value: String? = null,
val parameters: Map<String, String>? = null,
val nested: List<ExtensionType>? = null) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ExtensionType
if (nodeName != other.nodeName) return false
if (value != other.value) return false
if (parameters != other.parameters) return false
if (nested != other.nested) return false
return true
}
override fun hashCode(): Int {
var result = nodeName.hashCode()
result = 31 * result + (value?.hashCode() ?: 0)
result = 31 * result + (parameters?.hashCode() ?: 0)
result = 31 * result + (nested?.hashCode() ?: 0)
return result
}
}

View File

@ -0,0 +1,94 @@
/*
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2022, bvn13
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package me.bvn13.sdk.android.gpx
import java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME
import java.time.format.DateTimeFormatterBuilder
class GpxConstant {
companion object {
const val HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
const val HEADER_EXTENDED = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
const val VERSION = "1.1"
val DTF =
DateTimeFormatterBuilder().append(ISO_LOCAL_DATE_TIME) // use the existing formatter for date time
.appendOffset("+HH:MM", "+00:00") // set 'noOffsetText' to desired '+00:00'
.toFormatter()
}
}

View File

@ -0,0 +1,492 @@
/*
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2022, bvn13
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package me.bvn13.sdk.android.gpx
import me.bvn13.sdk.android.gpx.GpxConstant.Companion.DTF
import java.io.InputStream
import java.time.OffsetDateTime
import java.util.stream.Collectors
fun GpxType.Companion.read(dis: InputStream) = GpxReader().read(dis)
fun ByteArray.asString() = String(this)
class GpxReader {
fun read(dis: InputStream): GpxType {
val container = readNotSpace(dis, Container.empty())
return when (container.byte!!.toInt()) {
'<'.code -> readBeginning(dis, container)
else -> throw IllegalArgumentException("Not a GPX/XML?")
}
}
private fun readBeginning(dis: InputStream, buffer: Container): GpxType {
val container = readByte(dis, buffer)
return when (container.byte!!.toInt()) {
'?'.code -> readSignature(dis, container)
'<'.code -> readGpx(dis, container)
else -> throw IllegalArgumentException("Wrong symbol at ${container.position} from the very beginning")
}
}
private fun readSignature(dis: InputStream, buffer: Container): GpxType {
val container = readUntil(dis, buffer, '\n')
val signaturePrepared = container.buffer.asString()
.trim()
.replace("'", "\"")
.replace(" ?", "?")
if (!signaturePrepared.startsWith("<?xml") || !signaturePrepared.endsWith("?>")) {
throw IllegalArgumentException("Wrong xml signature!")
}
return readBeginning(dis, Container.empty(container.position))
}
private fun readGpx(dis: InputStream, buffer: Container): GpxType {
var tagName: String? = null
val container = readObject(dis, buffer) {
tagName = it.buffer.asString().substring(1, it.buffer.size - 1).lowercase()
if ("gpx" != tagName) {
throw IllegalArgumentException("There must be GPX tag in given InputStream")
}
}
tagName?.let {
return assembleGpxType(container)
} ?: run {
throw IllegalArgumentException("Unable to read content")
}
}
private fun assembleGpxType(container: Container): GpxType {
if (container.objects == null) {
throw IllegalArgumentException("It was not parsed properly")
}
if (container.objects!!.size != 1) {
throw IllegalArgumentException("It was parsed ${container.objects!!.size} objects, but only 1 is expected")
}
return findObject(container.objects, "gpx").let {
return GpxType(
metadata = assembleMetadataType(it.nested),
creator = findAttributeOrNull(it.attributes, "creator")
?: throw IllegalArgumentException("Gpx.Creator not found"),
wpt = findObjectsOrNull(it.nested, "wpt")?.map { assembleWptType(it) },
rte = findObjectsOrNull(it.nested, "rte")?.map { assembleRteType(it) },
trk = findObjectsOrNull(it.nested, "trk")?.map { assembleTrkType(it) },
extensions = findObjectOrNull(it.nested, "extensions")?.let { assembleExtensionType(it) }
)
}
}
private fun assembleMetadataType(objects: List<XmlObject>?): MetadataType =
findObject(objects, "metadata")
.let {
return MetadataType(
name = findObjectOrNull(it.nested, "name")?.value
?: throw IllegalArgumentException("Gpx.Metadata.Name not found"),
description = findObjectOrNull(it.nested, "desc")?.value
?: "",
authorName = findObjectOrNull(it.nested, "author").let { author ->
findObjectOrNull(author?.nested, "name")?.value
?: ""
}
)
}
private fun assembleWptType(obj: XmlObject): WptType =
WptType(
lat = findAttribute(obj.attributes, "lat").toDouble(),
lon = findAttribute(obj.attributes, "lon").toDouble(),
ele = findObjectOrNull(obj.nested, "ele")?.value?.toDouble(),
time = findObjectOrNull(obj.nested, "time")?.value?.let { OffsetDateTime.parse(it, DTF) },
magvar = findObjectOrNull(obj.nested, "magvar")?.value?.toDouble(),
geoidheight = findObjectOrNull(obj.nested, "geoidheight")?.value?.toDouble(),
name = findObjectOrNull(obj.nested, "name")?.value,
cmt = findObjectOrNull(obj.nested, "cmt")?.value,
desc = findObjectOrNull(obj.nested, "desc")?.value,
src = findObjectOrNull(obj.nested, "src")?.value,
link = findObjectsOrNull(obj.nested, "link")?.map { assembleLinkType(it) },
sym = findObjectOrNull(obj.nested, "sym")?.value,
type = findObjectOrNull(obj.nested, "type")?.value,
fix = findObjectOrNull(obj.nested, "fix")?.value?.let { assembleFixType(it) },
sat = findObjectOrNull(obj.nested, "sat")?.value?.toInt(),
hdop = findObjectOrNull(obj.nested, "hdop")?.value?.toDouble(),
vdop = findObjectOrNull(obj.nested, "vdop")?.value?.toDouble(),
pdop = findObjectOrNull(obj.nested, "pdop")?.value?.toDouble(),
ageofgpsdata = findObjectOrNull(obj.nested, "ageofgpsdata")?.value?.toInt(),
dgpsid = findObjectOrNull(obj.nested, "dgpsid")?.value?.toInt(),
extensions = findObjectOrNull(obj.nested, "extensions")?.nested?.map { assembleExtensionType(it) }
)
private fun assembleRteType(obj: XmlObject): RteType =
RteType(
name = findObjectOrNull(obj.nested, "name")?.value,
cmt = findObjectOrNull(obj.nested, "cmt")?.value,
desc = findObjectOrNull(obj.nested, "desc")?.value,
src = findObjectOrNull(obj.nested, "src")?.value,
link = findObjectsOrNull(obj.nested, "link")?.map { assembleLinkType(it) },
number = findObjectOrNull(obj.nested, "number")?.value?.toInt(),
type = findObjectOrNull(obj.nested, "type")?.value,
extensions = findObjectOrNull(obj.nested, "extensions")?.nested?.map { assembleExtensionType(it) },
rtept = findObjectsOrNull(obj.nested, "rtept")?.map { assembleWptType(it) }
)
private fun assembleTrkType(obj: XmlObject): TrkType =
TrkType(
name = findObjectOrNull(obj.nested, "name")?.value,
cmt = findObjectOrNull(obj.nested, "cmt")?.value,
desc = findObjectOrNull(obj.nested, "desc")?.value,
src = findObjectOrNull(obj.nested, "src")?.value,
link = findObjectsOrNull(
obj.nested,
"link"
)?.let { list -> if (list.isNotEmpty()) list.map { assembleLinkType(it) } else null },
number = findObjectOrNull(obj.nested, "number")?.value?.toInt(),
type = findObjectOrNull(obj.nested, "type")?.value,
extensions = findObjectOrNull(obj.nested, "extensions")?.let { assembleExtensionType(it) },
trkseg = findObjectsOrNull(obj.nested, "trkseg")?.map { assembleTrksegType(it) }
)
private fun assembleLinkType(obj: XmlObject): LinkType =
LinkType(
href = findAttribute(obj.attributes, "href"),
text = findObjectOrNull(obj.nested, "text")?.value,
type = findObjectOrNull(obj.nested, "type")?.value
)
private fun assembleFixType(value: String): FixType =
FixType.valueOf(value.uppercase())
private fun assembleExtensionType(obj: XmlObject): ExtensionType {
val nested: List<ExtensionType>? = obj.nested?.stream()
?.map { assembleExtensionType(it) }
?.collect(Collectors.toList())
return ExtensionType(
nodeName = obj.type,
value = if (obj.value == "") null else obj.value,
parameters = if (obj.attributes.isEmpty()) null else obj.attributes.toSortedMap(),
nested = nested
)
}
private fun assembleTrksegType(obj: XmlObject): TrksegType =
TrksegType(
trkpt = findObjectsOrNull(obj.nested, "trkpt")?.map { assembleWptType(it) },
extensions = findObjectOrNull(obj.nested, "extensions")?.let { assembleExtensionType(it) }
)
private fun findObjectOrNull(objects: List<XmlObject>?, name: String): XmlObject? =
objects?.firstOrNull { o ->
o.type.lowercase() == name.lowercase()
}
private fun findObject(objects: List<XmlObject>?, name: String): XmlObject =
findObjectOrNull(objects, name)
?: throw IllegalArgumentException("$name not found")
private fun findObjectsOrNull(objects: List<XmlObject>?, name: String): List<XmlObject>? =
objects?.filter { o ->
o.type.lowercase() == name.lowercase()
}
private fun findAttributeOrNull(attributes: Map<String, String>?, name: String): String? =
attributes?.firstNotNullOf { e -> if (e.key.lowercase() == name.lowercase()) e.value else null }
private fun findAttribute(attributes: Map<String, String>?, name: String): String =
findAttributeOrNull(attributes, name)
?: throw IllegalArgumentException("Unable to find attribute $name")
private fun readObject(dis: InputStream, buffer: Container, checker: ((Container) -> Unit)? = null): Container {
if (buffer.buffer[0].toInt() != '<'.code) {
throw IllegalArgumentException("Not a tag at position ${buffer.position}")
}
var container = readUntil(dis, buffer, setOf(' ', '\n', '>'))
val tagName = container.buffer.asString().substring(1, container.buffer.size - 1)
checker?.invoke(container)
val xmlObject = XmlObject(tagName)
if (container.byte!!.toInt() != '>'.code) {
container = readAttributes(dis, container)
xmlObject.attributes = container.attributes
}
if (!container.isShortClosing) {
container = readSkipping(dis, container, SKIPPING_SET)
if (container.byte!!.toInt() == '<'.code) {
container = readNestedObjects(dis, container)
xmlObject.nested = container.objects
container = readFinishingTag(dis, container, tagName)
}
if (container.buffer.asString() != "</$tagName>") {
container = readValue(dis, container, tagName)
}
}
xmlObject.value = container.buffer.asString().replace("</$tagName>", "")
container.objects = listOf(xmlObject)
return container
}
private fun readNestedObjects(dis: InputStream, buffer: Container): Container {
val list = ArrayList<XmlObject>()
var container: Container = readByte(dis, buffer)
if (container.byte!!.toInt() == '/'.code) {
return container
}
while (true) {
val objectContainer = readObject(dis, container)
val skippingContainer = readSkipping(dis, objectContainer, SKIPPING_SET)
container = readByte(dis, skippingContainer)
objectContainer.objects?.forEach {
list.add(it)
}
if (container.byte!!.toInt() == '/'.code) {
break;
}
}
container.objects = list
return container
}
private fun readFinishingTag(dis: InputStream, buffer: Container, tagName: String): Container {
if (buffer.isShortClosing) {
return buffer
}
return readExactly(dis, buffer, "</${tagName}>")
}
private fun readValue(dis: InputStream, buffer: Container, tagName: String): Container =
readUntil(dis, buffer, "</$tagName>")
private fun readAttributes(dis: InputStream, buffer: Container): Container {
if (buffer.byte!!.toInt() == '>'.code) {
return Container.empty(buffer.position)
}
val attributes = HashMap<String, String>()
var attributeContainer: Container = Container.empty(buffer.position)
do {
attributeContainer = readAttribute(dis, attributeContainer)
attributes.putAll(attributeContainer.attributes)
} while (attributeContainer.attributes.isNotEmpty()
&& attributeContainer.byte!!.toInt() != '>'.code
)
val result = Container.emptyWithAttributes(attributeContainer.position, attributes, attributeContainer.isShortClosing)
return result
}
private fun readAttribute(dis: InputStream, buffer: Container): Container {
val nameContainer = readUntil(dis, buffer, setOf(' ', '\n', '=', '\t'))
val nameAsString = nameContainer.buffer.asString()
val name = nameAsString.substring(0, nameAsString.length - 1)
val equalsContainer = readUntil(dis, Container.empty(nameContainer.position), '"')
val valueContainer = readUntil(dis, Container.empty(equalsContainer.position), '"')
val valueAsString = valueContainer.buffer.asString()
val value = valueAsString.substring(0, valueAsString.length - 1)
val result = Container.empty(valueContainer.position)
var closingContainer = readSkipping(dis, result, SKIPPING_SET)
var isShortClosing = false
if (closingContainer.byte!!.toInt() == '/'.code) {
val endingContainer = readByte(dis, closingContainer)
if (endingContainer.byte!!.toInt() != '>'.code) {
throw IllegalArgumentException("There must be valid closing tag at ${endingContainer.position}")
}
closingContainer = endingContainer
isShortClosing = true
}
val nextBlockContainer = Container.of(closingContainer.byte!!, closingContainer.position, isShortClosing)
nextBlockContainer.attributes = mapOf(name to value)
return nextBlockContainer
}
private fun readUntil(dis: InputStream, buffer: Container, ch: Char): Container {
var container = buffer
do {
container = readByte(dis, container)
} while (container.byte!!.toInt() != ch.code)
return container
}
private fun readUntil(dis: InputStream, buffer: Container, chs: Set<Char>): Container {
val chars = chs.map { c -> c.code }
var container = buffer
do {
container = readByte(dis, container)
} while (!chars.contains(container.byte!!.toInt()))
return container
}
private fun readUntil(dis: InputStream, buffer: Container, charSequence: CharSequence): Container {
var container = Container.of(buffer.byte!!, buffer.position)
var pos = 0
do {
container = readByte(dis, container)
if (container.byte!!.toInt() == charSequence[pos].code) {
pos++
} else {
pos = 0
}
} while (pos < charSequence.length)
return container
}
private fun readSkipping(dis: InputStream, buffer: Container, chs: Set<Char>): Container {
val chars = chs.map { c -> c.code }
var container = buffer
do {
container = readByte(dis, container)
} while (chars.contains(container.byte!!.toInt()))
return Container.of(container.byte!!, container.position)
}
private fun readExactly(dis: InputStream, buffer: Container, charSequence: CharSequence): Container {
var container = buffer
do {
container = readByte(dis, container)
if (charSequence.substring(0, container.buffer.size) != container.buffer.asString()) {
throw IllegalArgumentException("Expected closing tag $charSequence at position ${buffer.position}")
}
} while (container.buffer.size < charSequence.length)
return container
}
private fun readNotSpace(dis: InputStream, buffer: Container): Container {
val container = readByte(dis, buffer)
if (container.byte!!.toInt() == ' '.code
|| container.byte.toInt() == '\n'.code
) {
return readByte(dis, container)
} else {
return container
}
}
private fun readByte(dis: InputStream, container: Container): Container {
val ba = ByteArray(1);
if (-1 == dis.read(ba, 0, 1)) {
throw InterruptedException("EOF at ${container.position}\nUnparsed data: " + String(container.buffer))
} else if (ba.size != 1) {
throw InterruptedException("Reading of 1 byte returns ${ba.size} bytes at ${container.position}")
}
return Container(container.position + 1, ba[0], container.buffer.plus(ba))
}
class Container(
val position: Long = 0,
val byte: Byte?,
val buffer: ByteArray,
val isShortClosing: Boolean = false
) {
var objects: List<XmlObject>? = null
var attributes: Map<String, String> = HashMap()
var value: String? = null
companion object {
fun empty(): Container = empty(0)
fun empty(position: Long, isShortClosing: Boolean = false) = Container(position, null, ByteArray(0), isShortClosing)
fun emptyWithAttributes(position: Long, attributes: Map<String, String>, isShortClosing: Boolean = false): Container {
val container = Container.empty(position, isShortClosing)
container.attributes = attributes
return container
}
fun of(b: Byte, position: Long, isShortClosing: Boolean = false) =
Container(position, b, ByteArray(1) { _ -> b }, isShortClosing)
fun isShortClosing(c: Container, buffer: ByteArray): Container {
val container = Container(c.position, c.byte, buffer, isShortClosing = true)
container.objects = c.objects
container.attributes = c.attributes
container.value = c.value
return container
}
}
override fun toString(): String = this.buffer.asString()
}
class XmlObject(type: String) {
val type: String
var attributes: Map<String, String> = HashMap()
var nested: List<XmlObject>? = null
var value: String? = null
init {
this.type = type
}
}
companion object {
val SKIPPING_SET = setOf(' ', '\n', '\r', '\t')
}
}

View File

@ -77,6 +77,8 @@ limitations under the License.
package me.bvn13.sdk.android.gpx
import me.bvn13.sdk.android.gpx.GpxConstant.Companion.VERSION
/**
* GPX documents contain a metadata header, followed by waypoints, routes, and tracks. You can add your own elements to the extensions section of the GPX document.
*
@ -100,5 +102,36 @@ class GpxType(
val trk: List<TrkType>? = null,
val extensions: ExtensionType? = null
) {
val version: String = "1.1"
val version: String = VERSION
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as GpxType
if (metadata != other.metadata) return false
if (creator != other.creator) return false
if (wpt != other.wpt) return false
if (rte != other.rte) return false
if (trk != other.trk) return false
if (extensions != other.extensions) return false
if (version != other.version) return false
return true
}
override fun hashCode(): Int {
var result = metadata.hashCode()
result = 31 * result + creator.hashCode()
result = 31 * result + (wpt?.hashCode() ?: 0)
result = 31 * result + (rte?.hashCode() ?: 0)
result = 31 * result + (trk?.hashCode() ?: 0)
result = 31 * result + (extensions?.hashCode() ?: 0)
result = 31 * result + version.hashCode()
return result
}
companion object { }
}

View File

@ -77,15 +77,16 @@ limitations under the License.
package me.bvn13.sdk.android.gpx
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.DTF
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.HEADER
import me.bvn13.sdk.android.gpx.GpxConstant.Companion.DTF
import me.bvn13.sdk.android.gpx.GpxConstant.Companion.HEADER
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.SCHEMA_LOCATION
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.XMLNS
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.XMLNS_XSI
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.log
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.Clock
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME
import java.time.format.DateTimeFormatterBuilder
fun GpxType.toXmlString(): String = this.toXmlString(null)
@ -102,6 +103,7 @@ fun GpxType.toXmlString(clock: Clock?): String = """
${this.wpt?.toXmlString() ?: ""}
${this.rte?.toXmlString() ?: ""}
${this.trk?.toXmlString() ?: ""}
${this.extensions?.toXmlString() ?: ""}
</gpx>
""".trim().removeEmptyStrings()
@ -142,7 +144,7 @@ fun WptType.toXmlString(nodeName: String) = """
${toXmlString(pdop, "pdop")}
${toXmlString(ageofgpsdata, "ageofgpsdata")}
${toXmlString(dgpsid, "dgpsid")}
${extensions?.toXmlString() ?: ""}
${extensions?.toXmlString(true) ?: ""}
</${nodeName}>
""".trim().removeEmptyStrings()
@ -155,8 +157,8 @@ fun RteType.toXmlString() = """
${this.link?.toXmlString() ?: ""}
${toXmlString(this.number, "number")}
${toXmlString(this.type, "type")}
${this.extensions?.toXmlString() ?: ""}
${this.rtept?.toXmlString() ?: ""}
${this.extensions?.toXmlString(true) ?: ""}
${this.rtept?.toXmlString("rtept") ?: ""}
</rte>
""".trim().removeEmptyStrings()
@ -185,13 +187,21 @@ fun FixType.toXmlString() = """
<fix>${this.value}</fix>
""".trim().removeEmptyStrings()
fun ExtensionType.toXmlString() = """
fun ExtensionType.toXmlString() =
if ((this.nested?.size ?: 0) > 0) {
"""
<${this.nodeName}${toXmlString(this.parameters)}>${this.nested?.toXmlString() ?: ""}</${this.nodeName}>
""".trim().removeEmptyStrings()
} else {
"""
<${this.nodeName}${toXmlString(this.parameters)}>${this.value ?: ""}</${this.nodeName}>
""".trim().removeEmptyStrings()
}
fun TrksegType.toXmlString() = """
<trkseg>
${this.trkpt?.toXmlString("trkpt") ?: ""}
${this.extensions?.toXmlString() ?: ""}
</trkseg>
""".trim().removeEmptyStrings()
@ -199,9 +209,17 @@ fun List<WptType>.toXmlString(nodeName: String?) = this.joinToString(prefix = "\
it.toXmlString(nodeName)
}
fun List<ExtensionType>.toXmlString() = this.joinToString(
prefix = "<extensions>\n", postfix = "\n</extensions>", separator = "\n", transform = ExtensionType::toXmlString
)
fun List<ExtensionType>.toXmlString(inGroup: Boolean = false): String {
if (inGroup) {
return this.joinToString(
prefix = "<extensions>\n", postfix = "\n</extensions>", separator = "\n", transform = ExtensionType::toXmlString
)
} else {
return this.joinToString(
prefix = "\n", postfix = "\n", separator = "\n", transform = ExtensionType::toXmlString
)
}
}
@JvmName("toXmlStringWptType")
fun List<WptType>.toXmlString() = this.joinToString(prefix = "", postfix = "", separator = "") {
@ -242,10 +260,17 @@ fun toXmlString(value: Double?, nodeName: String) = if (value != null) {
""
}
fun toXmlString(value: OffsetDateTime?, nodeName: String) = if (value != null) {
"<${nodeName}>${value.format(DTF)}</${nodeName}>"
} else {
""
fun toXmlString(value: OffsetDateTime?, nodeName: String): String {
if (value != null) {
try {
return "<${nodeName}>${value.format(DTF)}</${nodeName}>"
} catch (e: Exception) {
log.warn(String.format("Unable to format datetime value in node %s", nodeName), e)
return ""
}
} else {
return ""
}
}
fun toXmlString(value: Map<String, String>?) = value?.entries?.joinToString(separator = "") {
@ -262,14 +287,9 @@ private fun String.removeEmptyStrings() = this.lineSequence().map {
class GpxWriter {
companion object {
const val HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
const val XMLNS = "http://www.topografix.com/GPX/1/1"
const val XMLNS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
const val SCHEMA_LOCATION = "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
internal val DTF =
DateTimeFormatterBuilder().append(ISO_LOCAL_DATE_TIME) // use the existing formatter for date time
.appendOffset("+HH:MM", "+00:00") // set 'noOffsetText' to desired '+00:00'
.toFormatter()
val log: Logger = LoggerFactory.getLogger(GpxWriter.javaClass)
}
}

View File

@ -87,4 +87,23 @@ package me.bvn13.sdk.android.gpx
* [type] Mime type of content (image/jpeg)
*/
class LinkType(val href: String, val text: String? = null, val type: String? = null) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as LinkType
if (href != other.href) return false
if (text != other.text) return false
if (type != other.type) return false
return true
}
override fun hashCode(): Int {
var result = href.hashCode()
result = 31 * result + (text?.hashCode() ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
return result
}
}

View File

@ -82,4 +82,25 @@ package me.bvn13.sdk.android.gpx
* Providing rich, meaningful information about your GPX files allows others to search for and use your GPS data.
*/
class MetadataType(val name: String, val description: String = "", val authorName: String = "") {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as MetadataType
if (name != other.name) return false
if (description != other.description) return false
if (authorName != other.authorName) return false
return true
}
override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + description.hashCode()
result = 31 * result + authorName.hashCode()
return result
}
}

View File

@ -114,4 +114,38 @@ class RteType(
"number must be non negative Integer"
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as RteType
if (name != other.name) return false
if (cmt != other.cmt) return false
if (desc != other.desc) return false
if (src != other.src) return false
if (link != other.link) return false
if (number != other.number) return false
if (type != other.type) return false
if (extensions != other.extensions) return false
if (rtept != other.rtept) return false
return true
}
override fun hashCode(): Int {
var result = name?.hashCode() ?: 0
result = 31 * result + (cmt?.hashCode() ?: 0)
result = 31 * result + (desc?.hashCode() ?: 0)
result = 31 * result + (src?.hashCode() ?: 0)
result = 31 * result + (link?.hashCode() ?: 0)
result = 31 * result + (number ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
result = 31 * result + (extensions?.hashCode() ?: 0)
result = 31 * result + (rtept?.hashCode() ?: 0)
return result
}
}

View File

@ -116,4 +116,38 @@ class TrkType(
"number must be non negative Integer"
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as TrkType
if (name != other.name) return false
if (cmt != other.cmt) return false
if (desc != other.desc) return false
if (src != other.src) return false
if (link != other.link) return false
if (number != other.number) return false
if (type != other.type) return false
if (extensions != other.extensions) return false
if (trkseg != other.trkseg) return false
return true
}
override fun hashCode(): Int {
var result = name?.hashCode() ?: 0
result = 31 * result + (cmt?.hashCode() ?: 0)
result = 31 * result + (desc?.hashCode() ?: 0)
result = 31 * result + (src?.hashCode() ?: 0)
result = 31 * result + (link?.hashCode() ?: 0)
result = 31 * result + (number ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
result = 31 * result + (extensions?.hashCode() ?: 0)
result = 31 * result + (trkseg?.hashCode() ?: 0)
return result
}
}

View File

@ -88,4 +88,21 @@ class TrksegType(
val trkpt: List<WptType>? = null,
val extensions: ExtensionType? = null
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as TrksegType
if (trkpt != other.trkpt) return false
if (extensions != other.extensions) return false
return true
}
override fun hashCode(): Int {
var result = trkpt?.hashCode() ?: 0
result = 31 * result + (extensions?.hashCode() ?: 0)
return result
}
}

View File

@ -162,4 +162,62 @@ class WptType(
"dgpsid must be in 0..1023"
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as WptType
if (lat != other.lat) return false
if (lon != other.lon) return false
if (ele != other.ele) return false
if (time != other.time) return false
if (magvar != other.magvar) return false
if (geoidheight != other.geoidheight) return false
if (name != other.name) return false
if (cmt != other.cmt) return false
if (desc != other.desc) return false
if (src != other.src) return false
if (link != other.link) return false
if (sym != other.sym) return false
if (type != other.type) return false
if (fix != other.fix) return false
if (sat != other.sat) return false
if (hdop != other.hdop) return false
if (vdop != other.vdop) return false
if (pdop != other.pdop) return false
if (ageofgpsdata != other.ageofgpsdata) return false
if (dgpsid != other.dgpsid) return false
if (extensions != other.extensions) return false
return true
}
override fun hashCode(): Int {
var result = lat.hashCode()
result = 31 * result + lon.hashCode()
result = 31 * result + (ele?.hashCode() ?: 0)
result = 31 * result + (time?.hashCode() ?: 0)
result = 31 * result + (magvar?.hashCode() ?: 0)
result = 31 * result + (geoidheight?.hashCode() ?: 0)
result = 31 * result + (name?.hashCode() ?: 0)
result = 31 * result + (cmt?.hashCode() ?: 0)
result = 31 * result + (desc?.hashCode() ?: 0)
result = 31 * result + (src?.hashCode() ?: 0)
result = 31 * result + (link?.hashCode() ?: 0)
result = 31 * result + (sym?.hashCode() ?: 0)
result = 31 * result + (type?.hashCode() ?: 0)
result = 31 * result + (fix?.hashCode() ?: 0)
result = 31 * result + (sat ?: 0)
result = 31 * result + (hdop?.hashCode() ?: 0)
result = 31 * result + (vdop?.hashCode() ?: 0)
result = 31 * result + (pdop?.hashCode() ?: 0)
result = 31 * result + (ageofgpsdata ?: 0)
result = 31 * result + (dgpsid ?: 0)
result = 31 * result + (extensions?.hashCode() ?: 0)
return result
}
}

View File

@ -0,0 +1,591 @@
/*
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2022, bvn13
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package me.bvn13.sdk.android.gpx
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import java.time.*
import kotlin.test.assertEquals
class GpxReaderTest {
@DisplayName("test GPX Reader")
@Test
fun testReader() {
val clock = Clock.fixed(
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
)
val gpxType = GpxType(
MetadataType("test name", description = "test description", authorName = "bvn13"),
wpt = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
),
rte = listOf(
RteType(
name = "rte name",
cmt = "cmt",
desc = "desc",
src = "src",
link = listOf(
LinkType(
href = "https://new.link.rte",
text = "new text rte",
type = "hyperlink"
)
),
number = 1234,
type = "route",
extensions = listOf(
ExtensionType(
"ext-1",
value = "value1"
)
),
rtept = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
)
)
),
trk = listOf(
TrkType(
name = "track 1",
cmt = "comment track 1",
desc = "desc track 1",
src = "src track 1",
number = 1234,
type = "type 1",
trkseg = listOf(
TrksegType(
listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
),
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
)
)
)
)
)
)
val gpxString = """
<?xml version="1.0" encoding="UTF-8"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
version="1.1"
creator="me.bvn13.sdk.android.gpx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<time>2022-09-24T15:04:00+03:00</time>
<metadata>
<name>test name</name>
<desc>test description</desc>
<author>
<name>bvn13</name>
</author>
</metadata>
<wpt lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</wpt>
<rte>
<name>rte name</name>
<cmt>cmt</cmt>
<desc>desc</desc>
<src>src</src>
<link href="https://new.link.rte">
<text>new text rte</text>
<type>hyperlink</type>
</link>
<number>1234</number>
<type>route</type>
<extensions>
<ext-1>value1</ext-1>
</extensions>
<rtept lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</rtept>
</rte>
<trk>
<name>track 1</name>
<cmt>comment track 1</cmt>
<desc>desc track 1</desc>
<src>src track 1</src>
<number>1234</number>
<type>type 1</type>
<trkseg>
<trkpt lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</trkpt>
<trkpt lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
<geoidheight>45.0</geoidheight>
<name>test point 1</name>
<cmt>comment 1</cmt>
<desc>description of point 1</desc>
<src>source 1</src>
<link href="http://link-to.site.href">
<text>text</text>
<type>hyperlink</type>
</link>
<link href="http://link2-to.site.href">
<text>text2</text>
<type>hyperlink2</type>
</link>
<sym>sym 1</sym>
<type>type 1</type>
<fix>dgps</fix>
<sat>1</sat>
<hdop>55.0</hdop>
<vdop>66.0</vdop>
<pdop>77.0</pdop>
<ageofgpsdata>44</ageofgpsdata>
<dgpsid>88</dgpsid>
<extensions>
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</trkpt>
</trkseg>
</trk>
</gpx>
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
val gpx = GpxType.read(gpxString.byteInputStream())
assertEquals(gpxType, gpx)
}
@DisplayName("Read test.gpx (generated in OsmAnd Android application)")
@Test
fun readTestGpx() {
val gpxType = GpxType.read(javaClass.classLoader.getResource("test.gpx").openStream())
Assertions.assertEquals(1011, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.size ?: 0)
Assertions.assertEquals(1, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.get(0)?.extensions?.size ?: 0)
Assertions.assertEquals(2, gpxType.trk?.get(0)?.trkseg?.get(0)?.extensions?.nested?.size ?: 0)
Assertions.assertEquals(223, gpxType.trk?.get(0)?.trkseg?.get(0)?.extensions?.nested?.get(0)?.nested?.size ?: 0)
Assertions.assertEquals(159, gpxType.trk?.get(0)?.trkseg?.get(0)?.extensions?.nested?.get(1)?.nested?.size ?: 0)
Assertions.assertEquals(1, gpxType.extensions?.nested?.size ?: 0)
}
@DisplayName("Read track-2023-03-01--21-21-54.gpx")
@Test
fun readTestGpx_v_1_9() {
val gpxType = GpxType.read(javaClass.classLoader.getResource("track-2023-03-01--21-21-54.gpx").openStream())
Assertions.assertEquals(20, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.size ?: 0)
Assertions.assertEquals(4, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.get(0)?.extensions?.size ?: 0)
}
@DisplayName("Read track-2023-03-09--21-10-54.gpx")
@Test
fun readTestGpx_v_1_10_3() {
val gpxType = GpxType.read(javaClass.classLoader.getResource("track-2023-03-09--21-10-54.gpx").openStream())
Assertions.assertEquals(4, gpxType.trk?.get(0)?.trkseg?.get(0)?.trkpt?.get(0)?.extensions?.size ?: 0)
}
@DisplayName("test xml signature")
@Test
fun testXmlSignature() {
val gpx = """<gpx
xmlns="http://www.topografix.com/GPX/1/1"
version="1.1"
creator="me.bvn13.sdk.android.gpx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<time>2022-09-24T15:04:00+03:00</time>
<metadata>
<name>test name</name>
<desc></desc>
<author>
<name></name>
</author>
</metadata>
<trk>
<name>track1</name>
<trkseg>
<trkpt lat="123.0" lon="321.0">
</trkpt>
</trkseg>
</trk>
</gpx>"""
GpxType.read("""
<?xml version="1.0" standalone="yes" encoding="UTF-8"?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
GpxType.read("""
<?xml version="1.0" encoding="UTF-8"?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
GpxType.read(
"""
<?xml version="1.0"?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
GpxType.read(
"""
<?xml?>
$gpx
""".trim()
.lineSequence()
.map {
it.trim()
}
.joinToString("\n")
.byteInputStream()
)
}
}

View File

@ -146,7 +146,7 @@ class GpxWriterTest {
@DisplayName("test maximum")
@Test
fun maximumTest() {
fun testMaximum() {
val clock = Clock.fixed(
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
)
@ -432,7 +432,7 @@ class GpxWriterTest {
<extensions>
<ext-1>value1</ext-1>
</extensions>
<wpt lat="14.64736838389662" lon="7.93212890625">
<rtept lat="14.64736838389662" lon="7.93212890625">
<ele>10.0</ele>
<time>2022-09-24T15:04:00+03:00</time>
<magvar>3.0</magvar>
@ -462,7 +462,7 @@ class GpxWriterTest {
<extension1 first="second" third="fours"></extension1>
<extension2 aa="bb" cc="dd"></extension2>
</extensions>
</wpt>
</rtept>
</rte>
<trk>
<name>track 1</name>

View File

@ -0,0 +1,546 @@
/*
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2022, bvn13
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package me.bvn13.sdk.android.gpx
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.time.*
class ReadWriteTest {
@DisplayName("Read-Write test")
@Test
fun testReadWrite() {
val clock = Clock.fixed(
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
)
val gpxType = GpxType(
MetadataType("test name", description = "test description", authorName = "bvn13"),
wpt = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
),
rte = listOf(
RteType(
name = "rte name",
cmt = "cmt",
desc = "desc",
src = "src",
link = listOf(
LinkType(
href = "https://new.link.rte",
text = "new text rte",
type = "hyperlink"
)
),
number = 1234,
type = "route",
extensions = listOf(
ExtensionType(
"ext-1",
value = "value1"
)
),
rtept = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
)
)
),
trk = listOf(
TrkType(
name = "track 1",
cmt = "comment track 1",
desc = "desc track 1",
src = "src track 1",
number = 1234,
type = "type 1",
trkseg = listOf(
TrksegType(
listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
),
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1",
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
),
ExtensionType(
"extension2",
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
)
)
)
)
)
)
)
)
)
val gpx = gpxType.toXmlString(clock)
val deserializedGpxType = GpxType.read(ByteArrayInputStream(gpx.toByteArray()))
Assertions.assertEquals(gpxType, deserializedGpxType)
}
@DisplayName("Write and Read extension without params, nested objects and value")
@Test
fun testEmptyException() {
val clock = Clock.fixed(
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
)
val gpxType = GpxType(
MetadataType("test name", description = "test description", authorName = "bvn13"),
wpt = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1"
),
ExtensionType(
"extension2"
)
)
)
),
rte = listOf(
RteType(
name = "rte name",
cmt = "cmt",
desc = "desc",
src = "src",
link = listOf(
LinkType(
href = "https://new.link.rte",
text = "new text rte",
type = "hyperlink"
)
),
number = 1234,
type = "route",
extensions = listOf(
ExtensionType(
"ext-1",
value = "value1"
)
),
rtept = listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1"
),
ExtensionType(
"extension2"
)
)
)
)
)
),
trk = listOf(
TrkType(
name = "track 1",
cmt = "comment track 1",
desc = "desc track 1",
src = "src track 1",
number = 1234,
type = "type 1",
trkseg = listOf(
TrksegType(
listOf(
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1"
),
ExtensionType(
"extension2"
)
)
),
WptType(
lat = 14.64736838389662,
lon = 7.93212890625,
ele = 10.toDouble(),
time = OffsetDateTime.now(clock),
magvar = 3.toDouble(),
geoidheight = 45.toDouble(),
name = "test point 1",
cmt = "comment 1",
desc = "description of point 1",
link = listOf(
LinkType(
href = "http://link-to.site.href",
text = "text",
type = "hyperlink"
),
LinkType(
href = "http://link2-to.site.href",
text = "text2",
type = "hyperlink2"
)
),
src = "source 1",
sym = "sym 1",
type = "type 1",
fix = FixType.DGPS,
sat = 1,
hdop = 55.toDouble(),
vdop = 66.toDouble(),
pdop = 77.toDouble(),
ageofgpsdata = 44,
dgpsid = 88,
extensions = listOf(
ExtensionType(
"extension1"
),
ExtensionType(
"extension2"
)
)
)
)
)
)
)
)
)
val gpx = gpxType.toXmlString(clock)
val deserializedGpxType = GpxType.read(ByteArrayInputStream(gpx.toByteArray()))
Assertions.assertEquals(gpxType, deserializedGpxType)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,221 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
version="1.1"
creator="me.bvn13.sdk.android.gpx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<time>2023-03-01T21:22:03.369+03:00</time>
<metadata>
<name>2023-03-01T21:22:02.89</name>
<desc></desc>
<author>
<name></name>
</author>
</metadata>
<trk>
<name>Track 1</name>
<TRKSEG>
<trkpt lat="55.8819464" lon="37.637977">
<ele>169.1999969482422</ele>
<time>7592-05-31T11:41:07+03:00</time>
<extensions>
<speed>1.0133984</speed>
<timeNanos>177426232867134</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819464" lon="37.637977">
<ele>169.1999969482422</ele>
<time>7592-05-31T11:41:07+03:00</time>
<extensions>
<speed>1.0133984</speed>
<timeNanos>177426232867134</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819464" lon="37.637977">
<ele>169.1999969482422</ele>
<time>7592-05-31T11:41:07+03:00</time>
<extensions>
<speed>1.0133984</speed>
<timeNanos>177426232867134</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819464" lon="37.637977">
<ele>169.1999969482422</ele>
<time>7592-05-31T11:41:07+03:00</time>
<extensions>
<speed>1.0133984</speed>
<timeNanos>177426232867134</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819464" lon="37.637977">
<ele>169.1999969482422</ele>
<time>7592-05-31T11:41:07+03:00</time>
<extensions>
<speed>1.0133984</speed>
<timeNanos>177426232867134</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819588" lon="37.6375427">
<ele>170.39999389648438</ele>
<time>7592-12-14T07:05:54+03:00</time>
<extensions>
<speed>1.0500889</speed>
<timeNanos>177443237154632</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819588" lon="37.6375427">
<ele>170.39999389648438</ele>
<time>7592-12-14T07:05:54+03:00</time>
<extensions>
<speed>1.0500889</speed>
<timeNanos>177443237154632</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819588" lon="37.6375427">
<ele>170.39999389648438</ele>
<time>7592-12-14T07:05:54+03:00</time>
<extensions>
<speed>1.0500889</speed>
<timeNanos>177443237154632</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819588" lon="37.6375427">
<ele>170.39999389648438</ele>
<time>7592-12-14T07:05:54+03:00</time>
<extensions>
<speed>1.0500889</speed>
<timeNanos>177443237154632</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8819588" lon="37.6375427">
<ele>170.39999389648438</ele>
<time>7592-12-14T07:05:54+03:00</time>
<extensions>
<speed>1.0500889</speed>
<timeNanos>177443237154632</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8820349" lon="37.6369261">
<ele>170.39999389648438</ele>
<time>7593-12-31T05:02:57+03:00</time>
<extensions>
<speed>1.0334443</speed>
<timeNanos>177476234577543</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8820349" lon="37.6369261">
<ele>170.39999389648438</ele>
<time>7593-12-31T05:02:57+03:00</time>
<extensions>
<speed>1.0334443</speed>
<timeNanos>177476234577543</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8820349" lon="37.6369261">
<ele>170.39999389648438</ele>
<time>7593-12-31T05:02:57+03:00</time>
<extensions>
<speed>1.0334443</speed>
<timeNanos>177476234577543</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8820349" lon="37.6369261">
<ele>170.39999389648438</ele>
<time>7593-12-31T05:02:57+03:00</time>
<extensions>
<speed>1.0334443</speed>
<timeNanos>177476234577543</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8820349" lon="37.6369261">
<ele>170.39999389648438</ele>
<time>7593-12-31T05:02:57+03:00</time>
<extensions>
<speed>1.0334443</speed>
<timeNanos>177476234577543</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8821806" lon="37.6368125">
<ele>170.6999969482422</ele>
<time>7594-07-27T10:48:08+03:00</time>
<extensions>
<speed>0.123607546</speed>
<timeNanos>177494226488478</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8821806" lon="37.6368125">
<ele>170.6999969482422</ele>
<time>7594-07-27T10:48:08+03:00</time>
<extensions>
<speed>0.123607546</speed>
<timeNanos>177494226488478</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8821806" lon="37.6368125">
<ele>170.6999969482422</ele>
<time>7594-07-27T10:48:08+03:00</time>
<extensions>
<speed>0.123607546</speed>
<timeNanos>177494226488478</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8821806" lon="37.6368125">
<ele>170.6999969482422</ele>
<time>7594-07-27T10:48:08+03:00</time>
<extensions>
<speed>0.123607546</speed>
<timeNanos>177494226488478</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
<trkpt lat="55.8821806" lon="37.6368125">
<ele>170.6999969482422</ele>
<time>7594-07-27T10:48:08+03:00</time>
<extensions>
<speed>0.123607546</speed>
<timeNanos>177494226488478</timeNanos>
<speedAccuracyMetersPerSecond>0.15</speedAccuracyMetersPerSecond>
<degrees>5.0</degrees>
</extensions>
</trkpt>
</TRKSEG>
</trk>
</gpx>

File diff suppressed because it is too large Load Diff