1package com.runehive.util.tools.wiki.parser;
3import com.google.common.util.concurrent.ListeningExecutorService;
4import com.google.common.util.concurrent.MoreExecutors;
5import com.google.common.util.concurrent.ThreadFactoryBuilder;
6import com.google.gson.Gson;
7import com.google.gson.GsonBuilder;
8import com.google.gson.JsonElement;
9import org.apache.logging.log4j.LogManager;
10import org.jsoup.Jsoup;
11import org.jsoup.nodes.Document;
13import java.io.IOException;
14import java.nio.file.Files;
15import java.nio.file.Path;
16import java.nio.file.Paths;
17import java.util.LinkedList;
18import java.util.concurrent.ExecutorService;
19import java.util.concurrent.Executors;
20import java.util.concurrent.TimeUnit;
33 protected static final String
WIKI_LINK =
"http://oldschoolrunescape.wikia.com/wiki/";
38 protected static final Gson
GSON =
new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
44 protected final LinkedList<WikiTable>
tables;
49 ExecutorService delegateService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
50 new ThreadFactoryBuilder().setNameFormat(
"WikiTableParserThread").build());
55 public void begin() throws InterruptedException {
67 protected void execute(Runnable runnable) {
79 protected static void writeToJson(String name, JsonElement array) {
81 String json =
GSON.toJson(array);
88 Files.write(path, json.getBytes());
90 logger.info(
"Successfully wrote " + path);
91 }
catch (IOException e) {
119 String link =
table.getLink();
120 Document document = Jsoup.connect(link).get();
121 table.parseDocument(document);
122 }
catch (Exception e) {
123 System.out.println(
"Could not parse table from wiki for '" +
table.getLink() +
"'");
Represents a single path in the path finding system.