aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/BrowserApp.java
diff options
context:
space:
mode:
authorJJ2022-12-27 05:38:32 +0000
committerJJ2022-12-27 15:30:20 +0000
commitc14e53775591cb4d75b486d21f4849552d5c7c8c (patch)
treefc9d67b66107f4965f3173183ec846e4d8e090c4 /src/main/ui/BrowserApp.java
parent0e693fd4814572712a4192cb4f176e71f7a344f7 (diff)
Remove garbage serialization/logging code
Diffstat (limited to 'src/main/ui/BrowserApp.java')
-rw-r--r--src/main/ui/BrowserApp.java110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/main/ui/BrowserApp.java b/src/main/ui/BrowserApp.java
index c4bbf99..520cac8 100644
--- a/src/main/ui/BrowserApp.java
+++ b/src/main/ui/BrowserApp.java
@@ -4,11 +4,7 @@ import model.html.ElementNode;
import model.html.HtmlParser;
import model.html.TextNode;
import model.html.Node;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import persistance.JsonUtils;
-import java.io.File;
import java.nio.file.*;
import java.util.*;
@@ -18,7 +14,6 @@ import java.util.*;
public class BrowserApp {
private Scanner input;
private static final String border = "===============================================";
- private static final String storagePath = "data/apus.cache";
private String pathString;
private ArrayList<Node> parsed;
private ArrayDeque<String> tabs;
@@ -30,39 +25,10 @@ public class BrowserApp {
println("apus: currently a barebones html/css renderer");
this.input = new Scanner(System.in);
this.tabs = new ArrayDeque<>();
-
- askToRestoreTabs();
mainLoop();
}
/**
- * EFFECTS: Asks the user if they'd like to restore previously closed tabs.
- */
- private void askToRestoreTabs() {
- if (new File(storagePath).length() > 2) {
- println("Would you like to restore your previously closed tabs? (Y/N)");
- String answer;
- while (true) {
- answer = this.input.next();
- if (answer.equalsIgnoreCase("y")) {
- restoreClosedTabs();
- break;
- } else if (answer.equalsIgnoreCase("n")) {
- JsonUtils.writeToFile(new JSONArray(), storagePath);
- println("please provide a path to a file (examples located in data/*):");
- pathString = this.input.next();
- break;
- } else {
- println("Sorry, I didn't quite get that. Please try again.");
- }
- }
- } else {
- println("please provide a path to a file (examples located in data/*):");
- pathString = this.input.next();
- }
- }
-
- /**
* EFFECTS: Runs the main loop
*/
private void mainLoop() {
@@ -87,23 +53,6 @@ public class BrowserApp {
}
/**
- * EFFECTS: restores previous closed tabs from a cache file.
- */
- private void restoreClosedTabs() {
- try {
- JSONArray state = JsonUtils.readFromFile(storagePath);
- for (int i = 0; i < state.length(); i++) {
- println(state.get(i).getClass().getName());
- tabs.add((String) state.get(i));
- }
- pathString = tabs.removeLast();
- } catch (Exception e) {
- println("Restoring state from disk failed with " + e.toString());
- System.exit(0);
- }
- }
-
- /**
* EFFECTS: Barebones HTML rendering. Iterates through a list of Nodes and their children and prints any text.
*/
private void renderHtml(ArrayList<Node> html) {
@@ -135,7 +84,6 @@ public class BrowserApp {
pathString = this.tabs.removeFirst();
break;
case "quit":
- handleQuit();
System.exit(0);
break;
default:
@@ -144,64 +92,6 @@ public class BrowserApp {
}
}
- /**
- * Helper function for the quit() case.
- * EFFECTS: Asks a user whether they'd like to save their tabs, and exists the program.
- */
- private void handleQuit() {
- println("Would you like to save your currently opened tabs to disk? (Y/N)");
- String answer;
- while (true) {
- answer = this.input.next();
- if (answer.equalsIgnoreCase("y")) {
- this.tabs.add(pathString);
- JsonUtils.writeToFile(new JSONArray(tabs), storagePath);
- break;
- } else if (answer.equalsIgnoreCase("n")) {
- JsonUtils.writeToFile(new JSONArray(), storagePath);
- break;
- } else {
- println("Sorry, I didn't quite get that. Please try again.");
- }
- }
- }
-
- /**
- * EFFECTS: writes the current program configuration to the disk
- */
- private void writeToDisk() {
- ArrayList<ArrayList<JSONObject>> jsonArray = new ArrayList<>();
- for (String p : tabs) {
- ArrayList<JSONObject> jsonArrayII = new ArrayList<>();
- try {
- Path path = Paths.get(pathString);
- String file = new String(Files.readAllBytes(path));
- HtmlParser parser = new HtmlParser();
- for (Node n : parser.parseHtml(file)) {
- jsonArrayII.add(n.serialize());
- }
- } catch (Exception e) {
- System.out.printf("Failed to write to disk with %s", e);
- }
- jsonArray.add(jsonArrayII);
- }
- JsonUtils.writeToFile(new JSONArray(jsonArray), storagePath);
- }
-
- /**
- * EFFECTS: restores program state from a last written to state
- */
- private void restoreFromDisk(JSONArray state) {
- for (int i = 0; i < state.length(); i++) {
- Object tab = state.get(i);
- if (tab instanceof JSONArray) {
- for (int j = 0; j < ((JSONArray) tab).length(); j++) {
- tabs.add(((JSONArray) tab).toString());
- }
- }
- }
- }
-
private void print(String toPrint) {
System.out.print(toPrint);
}