Browse Source

Import optimisations, XML parser should handle special characters properly

master
Janis 10 months ago
parent
commit
7d412dcb06
7 changed files with 10 additions and 23 deletions
  1. +0
    -1
      src/app/pott/kaffeepott/collector/Config.kt
  2. +0
    -1
      src/app/pott/kaffeepott/collector/args/Argparser.kt
  3. +0
    -1
      src/app/pott/kaffeepott/collector/core/DayOfWeeks.kt
  4. +3
    -10
      src/app/pott/kaffeepott/collector/osmweb/OSMAdapter.kt
  5. +4
    -4
      src/app/pott/kaffeepott/collector/osmweb/QueryBuilder.kt
  6. +0
    -1
      src/app/pott/kaffeepott/collector/osmweb/parser/OutdoorSeatingMatcher.kt
  7. +3
    -5
      src/app/pott/kaffeepott/collector/osmweb/parser/ResultParser.kt

+ 0
- 1
src/app/pott/kaffeepott/collector/Config.kt View File

@@ -1,7 +1,6 @@
package app.pott.kaffeepott.collector

import java.io.FileInputStream
import java.io.IOException
import java.io.InputStreamReader
import java.nio.file.Files
import java.nio.file.Path


+ 0
- 1
src/app/pott/kaffeepott/collector/args/Argparser.kt View File

@@ -3,7 +3,6 @@ package app.pott.kaffeepott.collector.args
import app.pott.kaffeepott.collector.Config
import app.pott.kaffeepott.collector.core.LatLng
import app.pott.kaffeepott.collector.core.LatLngBounds
import java.lang.NumberFormatException
import java.nio.file.Paths
import kotlin.system.exitProcess



+ 0
- 1
src/app/pott/kaffeepott/collector/core/DayOfWeeks.kt View File

@@ -1,7 +1,6 @@
package app.pott.kaffeepott.collector.core

import app.pott.kaffeepott.collector.Constants
import java.lang.IllegalArgumentException
import java.time.DayOfWeek

fun parseDay(name: String): DayOfWeek {


+ 3
- 10
src/app/pott/kaffeepott/collector/osmweb/OSMAdapter.kt View File

@@ -1,14 +1,9 @@
package app.pott.kaffeepott.collector.osmweb

import app.pott.kaffeepott.collector.Constants
import app.pott.kaffeepott.collector.core.LatLngBounds
import app.pott.kaffeepott.collector.osmweb.parser.ResultParser
import app.pott.kaffeepott.collector.core.Ticket
import java.io.BufferedReader
import app.pott.kaffeepott.collector.osmweb.parser.ResultParser
import java.io.IOException
import java.net.HttpURLConnection
import java.nio.charset.Charset
import kotlin.collections.ArrayList

class OSMAdapter {

@@ -17,12 +12,10 @@ class OSMAdapter {

fun query(area: LatLngBounds, amenity: String = "cafe"): List<Ticket> {
return try {
val connection = queryBuilder.buildQuery(area, amenity).openConnection() as HttpURLConnection
connection.requestMethod = "GET"
resultParser.parse(connection.inputStream.bufferedReader(Charset.forName(Constants.OSMConstants.CHARSET)).use(BufferedReader::readText))
resultParser.parse(queryBuilder.buildQuery(area, amenity))
} catch (ioException: IOException) {
ioException.printStackTrace()
ArrayList()
listOf()
}
}



+ 4
- 4
src/app/pott/kaffeepott/collector/osmweb/QueryBuilder.kt View File

@@ -2,15 +2,15 @@ package app.pott.kaffeepott.collector.osmweb

import app.pott.kaffeepott.collector.Constants
import app.pott.kaffeepott.collector.core.LatLngBounds
import java.net.URI
import java.net.URL
import java.net.URLEncoder

class QueryBuilder {

fun buildQuery(area: LatLngBounds, amenity: String): URL {
return URL("${Constants.OSMConstants.SCHEME}://${Constants.OSMConstants.DOMAIN}:" +
"${Constants.OSMConstants.PORT}${Constants.OSMConstants.PATH}?${Constants.OSMConstants.QUERY}" +
URLEncoder.encode(getQuery(area, amenity), Constants.OSMConstants.CHARSET))
return URI(Constants.OSMConstants.SCHEME, null, Constants.OSMConstants.DOMAIN,
Constants.OSMConstants.PORT, Constants.OSMConstants.PATH, Constants.OSMConstants.QUERY +
getQuery(area, amenity), null).toURL()
}

private fun getQuery(area: LatLngBounds, amenity: String): String {


+ 0
- 1
src/app/pott/kaffeepott/collector/osmweb/parser/OutdoorSeatingMatcher.kt View File

@@ -1,7 +1,6 @@
package app.pott.kaffeepott.collector.osmweb.parser

import app.pott.kaffeepott.collector.Constants
import app.pott.kaffeepott.collector.core.Badge

class OutdoorSeatingMatcher : BadgeMatcher {



+ 3
- 5
src/app/pott/kaffeepott/collector/osmweb/parser/ResultParser.kt View File

@@ -1,18 +1,16 @@
package app.pott.kaffeepott.collector.osmweb.parser

import app.pott.kaffeepott.collector.core.Ticket
import org.xml.sax.InputSource
import java.io.StringReader
import java.net.URL
import javax.xml.parsers.SAXParserFactory

class ResultParser {

fun parse(xml: String): List<Ticket> {
println("Parsing OSM data")
fun parse(url: URL): List<Ticket> {
val saxParserFactory = SAXParserFactory.newInstance()
saxParserFactory.isValidating = true
val contentHandler = SAXContentHandler()
saxParserFactory.newSAXParser().parse(InputSource(StringReader(xml)), contentHandler)
saxParserFactory.newSAXParser().parse(url.toString(), contentHandler)
return contentHandler.tickets
}
}

Loading…
Cancel
Save