summaryrefslogtreecommitdiffstats
path: root/Master/Agile Software Development/TestApp/src/testapp/ItemGenerator.java
blob: 9a8855f41fe7084e4f80e0b67d24d80af073e94d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Class to use the html parser and generate items.
 */

package testapp;

import Parser.HtmlParser;
import Parser.UrlAnalyzer;
import java.util.concurrent.ExecutionException;
import javax.swing.SwingWorker;
import testapp.data.IframeItem;
import testapp.data.ImageItem;
import testapp.data.Item;
import testapp.data.ItemClassification;
import testapp.data.PageItem;
import java.util.logging.*;
import javax.swing.JPanel;
/**
 *
 * @author sven
 */
public class ItemGenerator extends SwingWorker<Item,Object> {
    private static final Logger logger = Logger.getLogger(ItemGenerator.class.getName());
    
    private String url;
    private JPanel progressBar; 

    public ItemGenerator(String url, JPanel ProgressBar) {
        this.url = url;
        this.progressBar = ProgressBar;
    }
    
    @Override
    protected Item doInBackground() throws Exception {
        // Call Parser for URL
        PageItem pi =null;
        if(UrlAnalyzer.validateURL(url))
        {
            progressBar.setVisible(true);
        String rest = UrlAnalyzer.stripProtocol(url);
        if (!rest.contains(UrlAnalyzer.PATH_SEPARATOR)) {
            url += "/";
        }
        pi = new PageItem(url,null);
        HtmlParser htmlParser=new HtmlParser();
        htmlParser.parse(pi);
        
        /*
        PageItem pi = new PageItem(url);
        pi.setClassification(ItemClassification.SUSPICIOUS);
        pi.add(new ImageItem(url+"image1").setClassification(ItemClassification.HARMLESS));
        pi.add(new ImageItem(url+"image2").setClassification(ItemClassification.CRITICAL));
        pi.add(new IframeItem(url+"if1")
                .add(new ImageItem(url+"if1img1").setClassification(ItemClassification.SUSPICIOUS))
                .add(new ImageItem(url+"if1img2").setClassification(ItemClassification.SUSPICIOUS))
        );
        pi.add(new IframeItem("NEWIFRAME").setClassification(ItemClassification.UNKNOWN));
         */
        //
        // start analyse here!!!
        //
        //pi.analyse();
        }
        else
        {
            //throw new Exception("Wrong URL format.");
        }
        return pi;
    }

    @Override
    protected void done() {
        try {
            Item rootItem = get();
            rootItem.urlToValidUrl(true);
            ItemClassification ic = rootItem.analyse();
            DOTGenerator dotGenerator = new DOTGenerator(rootItem);
            dotGenerator.execute();
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        } catch (ExecutionException ee) {
            ee.printStackTrace();
        } catch (Exception ex)
        {
            logger.log(Level.SEVERE, ex.toString());
        } 
        finally
        {
            progressBar.setVisible(false);
        }
    }
}