Skip to content

Commit

Permalink
LogosVersemapDownloader: Load from archive.org
Browse files Browse the repository at this point in the history
As the wiki is currently being migrated and it seems that the verse maps
page may be down for a while...
  • Loading branch information
schierlm committed Nov 22, 2024
1 parent 0ad40c6 commit 21aa480
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.DeflaterInputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.InflaterOutputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -102,7 +106,7 @@ public static void main(String[] args) throws Exception {
if (versemap.exists())
return;
System.out.println("Downloading Logos verse map...");
try (InputStream in = new URL("https://wiki.logos.com/Bible_Verse_Maps").openStream();
try (InputStream in = new URL("https://web.archive.org/web/20240226003157id_/https://wiki.logos.com/Bible_Verse_Maps").openStream();
Writer w = new OutputStreamWriter(new FileOutputStream(versemap), StandardCharsets.ISO_8859_1)) {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
builder.setEntityResolver(new EntityResolver() {
Expand All @@ -117,6 +121,12 @@ public InputSource resolveEntity(String publicId, String systemId)
int len;
while ((len = in.read(buf)) != -1)
baos.write(buf, 0, len);
if (baos.toByteArray()[0] == 0x1f && (baos.toByteArray()[1] & 0xFF) == 0x8b) {
GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));
baos = new ByteArrayOutputStream();
while ((len = zin.read(buf)) != -1)
baos.write(buf, 0, len);
}
String xml = new String(baos.toByteArray(), StandardCharsets.UTF_8);
xml = xml.replaceAll("<script type=\"text/javascript\">\\(?window.*?</script>", "").replace("createCookie&authorizationHeader=", "").replaceAll("<script async charset=\"utf-8\"", "<script charset=\"utf-8\"");
parseVerseMap(builder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))), w);
Expand Down

0 comments on commit 21aa480

Please sign in to comment.