Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.squadd.technical; import com.squadd.javaBeans.Contact; import com.squadd.javaBeans.Group; import com.squadd.javaBeans.UserInfoBean; import com.squadd.managers.DBManager; import com.vaadin.server.Resource; import com.vaadin.server.StreamResource; import com.vaadin.server.ThemeResource; import com.vaadin.ui.Image; import java.io.File; import java.util.Date; /** * * @author SharkNado */ public class ImageGetter { //user's picture public Image get(Contact contact) { try { String path = "src\\main\\webapp\\VAADIN\\themes\\mytheme\\" + "pictures/userPic" + contact.getId() + ".png"; File file = new File(path); if (file.exists()) { Resource res = new ThemeResource("pictures/userPic" + contact.getId() + ".png"); return new Image(null, res); } else { Resource res = new ThemeResource("user_icon.png"); return new Image(null, res); } } catch (Exception e) { Resource res = new ThemeResource("user_icon.png"); return new Image(null, res); } } public String getPath(Group group) { return "src\\main\\webapp\\VAADIN\\themes\\mytheme\\" + "pictures/groupPic" + group.getGroupId() + "i" + group.getLastUploadDate().toString() + ".png"; } public Resource getResource(UserInfoBean user) { DBManager db = new DBManager(); Contact contact = db.getContactByUserId(user); try { String path = "src\\main\\webapp\\VAADIN\\themes\\mytheme\\" + "pictures/userPic" + contact.getId() + ".png"; File file = new File(path); if (file.exists()) { Resource res = new ThemeResource("pictures/userPic" + contact.getId() + ".png"); return res; } else { Resource res = new ThemeResource("user_icon.png"); return res; } } catch (Exception e) { Resource res = new ThemeResource("user_icon.png"); return res; } } public Image get(UserInfoBean user) { DBManager db = new DBManager(); Contact contact = db.getContactByUserId(user); try { String path = "src\\main\\webapp\\VAADIN\\themes\\mytheme\\" + "pictures/userPic" + contact.getId() + ".png"; File file = new File(path); if (file.exists()) { Resource res = new ThemeResource("pictures/userPic" + contact.getId() + ".png"); return new Image(null, res); } else { Resource res = new ThemeResource("user_icon.png"); return new Image(null, res); } } catch (Exception e) { Resource res = new ThemeResource("user_icon.png"); return new Image(null, res); } } //group's picture public Image get(Group group) { try { String path = new DBManager().getPathGroupImage(group); File file = new File(path); if (file.exists()) { String newPath = path.substring(path.indexOf("pictures"), path.length()); Resource res = new ThemeResource(newPath); return new Image(null, res); } else { Resource res = new ThemeResource("user_icon.png"); return new Image(null, res); } } catch (Exception e) { Resource res = new ThemeResource("user_icon.png"); return new Image(null, res); } } }