/*
* 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- {
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);
}
}
}