From 0ae7108128bf638078b79bf9b0087923e58c0079 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 29 Oct 2014 14:12:58 +0100 Subject: [client] support for loading text files through the ResouceLoader this will be needed to read the vmx-template from resources/ --- .../src/main/java/util/ResourceLoader.java | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'dozentenmodul/src/main/java/util/ResourceLoader.java') diff --git a/dozentenmodul/src/main/java/util/ResourceLoader.java b/dozentenmodul/src/main/java/util/ResourceLoader.java index 49c54d9d..7c3c9c62 100644 --- a/dozentenmodul/src/main/java/util/ResourceLoader.java +++ b/dozentenmodul/src/main/java/util/ResourceLoader.java @@ -1,7 +1,5 @@ package util; -import gui.intro.Login_GUI; - import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; @@ -12,6 +10,7 @@ import java.net.URL; import javax.swing.ImageIcon; +import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; /** @@ -25,7 +24,7 @@ public class ResourceLoader { * Logger for this class */ private final static Logger LOGGER = Logger.getLogger(ResourceLoader.class); - + /** * Load the given resource as an ImageIcon. * This is guaranteed to never throw an Exception and always return @@ -65,8 +64,7 @@ public class ResourceLoader { * @param path Resource path to load * @return ImageIcon instance */ - public static ImageIcon getIcon(String path) - { + public static ImageIcon getIcon(String path) { return getIcon(path, path); } @@ -101,4 +99,23 @@ public class ResourceLoader { return new ImageIcon(image, "ERROR"); } + /** + * Tries to load the given resource as File + * @param path Resource path to load + * @return the file of the loaded resource + */ + public static String getTextFile(String path) { + String fileContent = null; + try { + fileContent = IOUtils.toString(ResourceLoader.class.getResourceAsStream(path)); + } catch (Exception e) { + LOGGER.error("IO error while trying to load resource '" + path + "'. See trace: ", e); + } + + if (fileContent != null) { + return fileContent; + } else { + return "Resource '" + path + "' not found."; + } + } } -- cgit v1.2.3-55-g7522