diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Agile Software Development/TestApp/src/testapp/data/ImageItem.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Agile Software Development/TestApp/src/testapp/data/ImageItem.java')
| -rw-r--r-- | Master/Agile Software Development/TestApp/src/testapp/data/ImageItem.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/Master/Agile Software Development/TestApp/src/testapp/data/ImageItem.java b/Master/Agile Software Development/TestApp/src/testapp/data/ImageItem.java new file mode 100644 index 0000000..0014b81 --- /dev/null +++ b/Master/Agile Software Development/TestApp/src/testapp/data/ImageItem.java @@ -0,0 +1,102 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package testapp.data; + +import java.awt.Image; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.logging.*; +import javax.imageio.ImageIO; + + + +/** + * + * @author sven + */ +public class ImageItem extends Item{ + + private static final Logger logger = Logger.getLogger(ImageItem.class.getName()); + + public ImageItem(String url, Item parent) { + super(url, parent); + itemType = ItemType.IMAGE; + } + +// public ImageItem(String url) { +// super(url); +// itemType = ItemType.IMAGE; +// } + + @Override + public ItemClassification analyse() { + + // if (!url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith("ftp://")) + // url="http://"+url; + doAnalyse(); + + try { + + // Bild auf Größe abfragen, wenn kleiner als 5x5 Pixel --> Critical + // Wenn größer und von fremden Server --> Suspicous + // Wenn lokal, dann ist auch die Größe egal --> Harmless + logger.log(Level.INFO, this.url.toString()); + URL imgUrl = new URL(this.url); + logger.log(Level.INFO, imgUrl.toString()); + Image image=null; + try { + image = ImageIO.read(imgUrl); + } catch(Exception exception) { + logger.log(Level.WARNING, "Couldn't verify image "+imgUrl); + setClassification(ItemClassification.SUSPICIOUS); + } + + //System.out.println("Höhe "+image.getHeight(null)+" Breite "+image.getWidth(null)); + if (image != null) { + if ( (image.getHeight(null) <= 5) && (image.getWidth(null) <= 5) && (itemPlace != ItemPlace.LOCAL) ) { + setClassification(ItemClassification.CRITICAL); + } + else if (itemPlace == ItemPlace.REMOTE) + { + setClassification(ItemClassification.SUSPICIOUS); + } + else if (itemPlace == ItemPlace.LOCAL) + { + setClassification(ItemClassification.HARMLESS); + } + } else { + setClassification(ItemClassification.UNKNOWN); + } + } catch (IOException ex) { + logger.log(Level.SEVERE, ex.toString()); + } + + logger.log(Level.INFO, "Place: " + this.itemPlace); + return itemClassification; + } + + @Override + protected HashMap<String, String> getAttributes() { + if (attributes == null) { + attributes = new HashMap<String,String>(); + } + attributes.put("shape", "octagon"); + attributes.put("style", "filled"); + attributes.put("fontname", "Verdana"); + attributes.put("fontsize", "10"); + return attributes; + } + + @Override + protected String getGraphNodetext() { + if (this.filename.compareTo("")!=0) + return this.filename; + else + return this.getUrl(); + } + +} |
