diff options
Diffstat (limited to 'src/main/model/html')
-rw-r--r-- | src/main/model/html/ElementNode.java | 9 | ||||
-rw-r--r-- | src/main/model/html/HtmlParser.java | 8 | ||||
-rw-r--r-- | src/main/model/html/TextNode.java | 9 |
3 files changed, 23 insertions, 3 deletions
diff --git a/src/main/model/html/ElementNode.java b/src/main/model/html/ElementNode.java index 16438f9..5ff4a0f 100644 --- a/src/main/model/html/ElementNode.java +++ b/src/main/model/html/ElementNode.java @@ -2,6 +2,8 @@ package model.html; import model.util.Node; import org.javatuples.Pair; +import org.json.JSONObject; +import persistance.JsonAble; import java.util.ArrayList; import java.util.Optional; @@ -9,7 +11,7 @@ import java.util.Optional; /** * This ElementNode class represents an HTML tag and nested tags. */ -public class ElementNode implements Node { +public class ElementNode implements Node, JsonAble { private String tag; private ArrayList<Pair<String,String>> attributes; @@ -67,4 +69,9 @@ public class ElementNode implements Node { public String getData() { return getTag() + " " + getAttributes().toString(); } + + @Override + public JSONObject serialize() { + return new JSONObject(this); + } } diff --git a/src/main/model/html/HtmlParser.java b/src/main/model/html/HtmlParser.java index d07a2ff..f0829f4 100644 --- a/src/main/model/html/HtmlParser.java +++ b/src/main/model/html/HtmlParser.java @@ -4,6 +4,8 @@ import java.util.*; import model.util.Node; import org.javatuples.*; +import org.json.JSONObject; +import persistance.JsonAble; /** * This class represents the state of and implements an LL(1) HTML parser. @@ -18,7 +20,7 @@ import org.javatuples.*; * SELF_CLOSING_TAG ::= 'img' | ... * (note that \forall T \in SELF_CLOSING_TAG, T \notin TAG) */ -public class HtmlParser { +public class HtmlParser implements JsonAble { /** * HTML is not nice to parse. We manage to get away with a relatively small number of parser states regardless. @@ -343,6 +345,10 @@ public class HtmlParser { return false; } } + + public JSONObject serialize() { + return new JSONObject(this); + } } /* diff --git a/src/main/model/html/TextNode.java b/src/main/model/html/TextNode.java index f6d3ce1..2e89326 100644 --- a/src/main/model/html/TextNode.java +++ b/src/main/model/html/TextNode.java @@ -1,11 +1,13 @@ package model.html; import model.util.Node; +import org.json.JSONObject; +import persistance.JsonAble; /** * This TextNode class represents raw text, with no nested tags. */ -public class TextNode implements Node { +public class TextNode implements Node, JsonAble { private String text = ""; /** @@ -24,4 +26,9 @@ public class TextNode implements Node { public String getData() { return getText(); } + + @Override + public JSONObject serialize() { + return new JSONObject(this); + } } |