diff options
| author | Michael Wilson | 2014-10-29 16:51:08 +0100 |
|---|---|---|
| committer | Michael Wilson | 2014-10-29 16:51:08 +0100 |
| commit | 482c5e566987b7405e6eb1cee6e8c8b113b9a55d (patch) | |
| tree | 283d44d005cb1edca63d9c25fb67f9798fa0c8c8 /dozentenmodul/src/main/java/util/ResourceLoader.java | |
| parent | -- (diff) | |
| parent | Merge branch 'master' of git.openslx.org:openslx-ng/tutor-module (diff) | |
| download | tutor-module-482c5e566987b7405e6eb1cee6e8c8b113b9a55d.tar.gz tutor-module-482c5e566987b7405e6eb1cee6e8c8b113b9a55d.tar.xz tutor-module-482c5e566987b7405e6eb1cee6e8c8b113b9a55d.zip | |
Merge branch 'master' of ssh://git.openslx.org/openslx-ng/tutor-module
Diffstat (limited to 'dozentenmodul/src/main/java/util/ResourceLoader.java')
| -rw-r--r-- | dozentenmodul/src/main/java/util/ResourceLoader.java | 27 |
1 files changed, 22 insertions, 5 deletions
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."; + } + } } |
