diff options
Diffstat (limited to 'Master/Agile Software Development/TestApp/src/testapp/ItemGenerator.java')
| -rw-r--r-- | Master/Agile Software Development/TestApp/src/testapp/ItemGenerator.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Master/Agile Software Development/TestApp/src/testapp/ItemGenerator.java b/Master/Agile Software Development/TestApp/src/testapp/ItemGenerator.java new file mode 100644 index 0000000..9a8855f --- /dev/null +++ b/Master/Agile Software Development/TestApp/src/testapp/ItemGenerator.java @@ -0,0 +1,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); + } + } +} |
