summaryrefslogtreecommitdiffstats
path: root/Master/Agile Software Development/TestApp/src/Parser/Visitor.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Agile Software Development/TestApp/src/Parser/Visitor.java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Agile Software Development/TestApp/src/Parser/Visitor.java')
-rw-r--r--Master/Agile Software Development/TestApp/src/Parser/Visitor.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/Master/Agile Software Development/TestApp/src/Parser/Visitor.java b/Master/Agile Software Development/TestApp/src/Parser/Visitor.java
new file mode 100644
index 0000000..e5d953c
--- /dev/null
+++ b/Master/Agile Software Development/TestApp/src/Parser/Visitor.java
@@ -0,0 +1,96 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package Parser;
+
+import org.htmlparser.Tag;
+import org.htmlparser.visitors.NodeVisitor;
+import testapp.data.FrameItem;
+import testapp.data.IframeItem;
+import testapp.data.ImageItem;
+import testapp.data.Item;
+import testapp.data.LinkItem;
+import testapp.data.ScriptItem;
+import testapp.data.StyleItem;
+import java.util.logging.*;
+
+/**
+ *
+ * @author alex
+ */
+class Visitor extends NodeVisitor {
+
+ private Item currentItem;
+
+ public Visitor(Item initialItem) {
+ currentItem = initialItem;
+ }
+
+ /// This methode will be called for every Tag found in the document
+ @Override
+ public void visitTag(Tag currentTag) {
+
+ String tagName = currentTag.getTagName();
+
+
+ /// Search for a link and create a link item
+ String hrefAttribute = currentTag.getAttribute("HREF");
+ if (hrefAttribute != null && hrefAttribute.length() > 0) {
+ if (tagName.equals("A")) {
+ LinkItem li = new LinkItem(hrefAttribute,currentItem);
+ currentItem.add(li);
+ }
+ }
+
+ /// Search for a source and create a specific item depending on the source type
+ String srcAttribute = currentTag.getAttribute("SRC");
+ if (srcAttribute != null && srcAttribute.length() > 0) {
+ if (tagName.equals("IFRAME")) {
+ IframeItem iframeItem;
+ iframeItem = new IframeItem(srcAttribute,currentItem);
+
+ //currentItem.add(iframeItem);
+ startNewHtmlParser(iframeItem);
+ } else if (tagName.equals("IMG")) {
+ ImageItem ii = new ImageItem(srcAttribute,currentItem);
+ currentItem.add(ii);
+ } else if (tagName.equals("FRAME")) {
+ FrameItem frameItem;
+ frameItem = new FrameItem(srcAttribute,currentItem);
+ currentItem.add(frameItem);
+ startNewHtmlParser(frameItem);
+ } else if (tagName.equals("SCRIPT")) {
+ JavascriptParser javascriptParser = new JavascriptParser(currentItem);
+ currentItem.add(javascriptParser.parse(srcAttribute));
+ } else if (tagName.equals("STYLE")) {
+ CssParser cssParser = new CssParser(currentItem);
+ currentItem.add(cssParser.parse(srcAttribute));
+ }
+ } else {
+ if (tagName.equals("STYLE")) {
+ StyleItem styleItem = new StyleItem("",currentItem);
+ currentItem.add(styleItem);
+ CssParser cssParser = new CssParser(styleItem);
+ cssParser.parseCode(currentTag.getText());
+ }
+
+ if (tagName.equals("SCRIPT")) {
+ ScriptItem scriptItem = new ScriptItem("",currentItem);
+ currentItem.add(scriptItem);
+ JavascriptParser javascriptParser = new JavascriptParser(scriptItem);
+ javascriptParser.parseCode(currentTag.getText(), this.currentItem.getUrl());
+ }
+ }
+
+
+ }
+
+ /// Start a new html parser for nested html pages
+ private void startNewHtmlParser(Item currentItem) {
+ ///restict the search dept of the html page to 10s external pages
+ HtmlParser htmlParser = new HtmlParser();
+ currentItem.urlToValidUrl(false);
+ htmlParser.parse(currentItem);
+ }
+}