aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ru/sape/SapeConnection.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-06-03 17:32:55 +0300
committerGravatar Vitaly Takmazov2020-06-03 17:32:55 +0300
commitb0bdce22447ff815512ae7612dd4ab4a5d9a409a (patch)
tree9c33f07584697130a316c6db404844207494a832 /src/main/java/ru/sape/SapeConnection.java
parentcafe4644cf82267397c21433c0c8965ff90c1073 (diff)
sape: switch to xml output
Diffstat (limited to 'src/main/java/ru/sape/SapeConnection.java')
-rw-r--r--src/main/java/ru/sape/SapeConnection.java17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/main/java/ru/sape/SapeConnection.java b/src/main/java/ru/sape/SapeConnection.java
index ee5a5e5c..cec308bf 100644
--- a/src/main/java/ru/sape/SapeConnection.java
+++ b/src/main/java/ru/sape/SapeConnection.java
@@ -1,8 +1,8 @@
package ru.sape;
-import com.github.ooxi.phparser.SerializedPhpParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.juick.www.ad.models.Site;
import java.io.BufferedReader;
import java.io.IOException;
@@ -66,17 +66,16 @@ public class SapeConnection {
}
}
}
- Map<String, Object> cached;
+ Site cachedSite;
long cacheUpdated;
- @SuppressWarnings("unchecked")
- public Map<String, Object> getData() {
+ public Optional<Site> getData() {
if (cacheLifeTime <= (System.currentTimeMillis() - cacheUpdated) / 1000) {
for (String server : serverList) {
String data;
try {
- data = fetchRemoteFile(server, dispenserPath + "&charset=UTF-8");
+ data = fetchRemoteFile(server, dispenserPath + "&charset=UTF-8&as_xml=true");
} catch (IOException e1) {
continue;
}
@@ -88,7 +87,7 @@ public class SapeConnection {
}
try {
- cached = (Map<String, Object>) new SerializedPhpParser(data).parse();
+ cachedSite = Site.fromXMLData(data);
} catch (Exception e) {
logger.error("Can't parse Sape data", e);
continue;
@@ -96,14 +95,14 @@ public class SapeConnection {
cacheUpdated = System.currentTimeMillis();
- return cached;
+ return Optional.of(cachedSite);
}
logger.error("Unable to fetch Sape data");
- return Collections.emptyMap();
+ return Optional.empty();
}
- return cached;
+ return Optional.of(cachedSite);
}
}