diff --git a/src/main/java/net/jrtechs/www/HtmlElement.java b/src/main/java/net/jrtechs/www/HtmlElement.java new file mode 100644 index 0000000..3e1bfa0 --- /dev/null +++ b/src/main/java/net/jrtechs/www/HtmlElement.java @@ -0,0 +1,114 @@ +package net.jrtechs.www; + +import java.util.ArrayList; +import java.util.List; + +/** + * Method for recursively defining HTML + * + * @author Jeffery Russell 5-24-18 + */ +public class HtmlElement +{ + /** Curses, I can't name it class **/ + private List clas; + + private List id; + + private List elements; + + private String tag; + + private String contents; + + + public HtmlElement(String html) + { + clas = new ArrayList<>(); + id = new ArrayList<>(); + elements = new ArrayList<>(); + + ArrayList tags = this.parseIntoTags(html); + this.pruneTags(tags); + + if(tags.size() > 0) + { + + } + } + + + private ArrayList parseIntoTags(String html) + { + html = html.replace("\n", ""); + html = html.replace("\t", ""); + + ArrayList tags = new ArrayList<>(); + String temp = ""; + for(int i = 0; i < html.length(); i++) + { + if(html.substring(i, i+1).equals("<")) + { + if(temp.length() > 0) + tags.add(temp); + temp = "<"; + } + else if (html.substring(i, i+1).equals(">")) + { + temp += html.substring(i, i+ 1); + tags.add(temp); + temp = ""; + } + else + { + temp+= html.substring(i, i+ 1); + } + } + if(temp.length() > 0) + tags.add(temp); + return tags; + } + + private void pruneTags(List tags) + { + List badStuff = new ArrayList<>(); + badStuff.add("
"); + badStuff.add(""); + badStuff.add(" badStuff.forEach(b -> + { + if(t.contains(b)) + tags.remove(t); + })); + } + + + public List getElementsWithClass(String clas) + { + List elems = new ArrayList<>(); + this.clas.stream().filter(s-> s.equals(clas)).forEach(s2->elems.add(this)); + this.elements.forEach(e -> elems.addAll(e.getElementsWithClass(clas))); + return elems; + } + + public List getElementsWithID(String ids) + { + List elems = new ArrayList<>(); + this.id.stream().filter(s-> s.equals(ids)).forEach(s2->elems.add(this)); + this.elements.forEach(e -> elems.addAll(e.getElementsWithID(ids))); + return elems; + } + + public List getElementsWithTag(String tag) + { + List elems = new ArrayList<>(); + if(this.tag.equals(tag)) + elems.add(this); + + this.elements.forEach(e -> elems.addAll(e.getElementsWithID(tag))); + return elems; + } + +} diff --git a/src/main/java/net/jrtechs/www/HtmlParser.java b/src/main/java/net/jrtechs/www/HtmlParser.java index f7dee3d..219007f 100644 --- a/src/main/java/net/jrtechs/www/HtmlParser.java +++ b/src/main/java/net/jrtechs/www/HtmlParser.java @@ -1,4 +1,6 @@ package net.jrtechs.www; -public class HtmlParser { +public class HtmlParser +{ + }