summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util
diff options
context:
space:
mode:
authorJonathan Bauer2014-10-29 14:12:58 +0100
committerJonathan Bauer2014-10-29 14:12:58 +0100
commit0ae7108128bf638078b79bf9b0087923e58c0079 (patch)
tree3be630aa40fcbf59418b91200923384addad3dd9 /dozentenmodul/src/main/java/util
parentAusgaben etwas verkürzt (diff)
downloadtutor-module-0ae7108128bf638078b79bf9b0087923e58c0079.tar.gz
tutor-module-0ae7108128bf638078b79bf9b0087923e58c0079.tar.xz
tutor-module-0ae7108128bf638078b79bf9b0087923e58c0079.zip
[client] support for loading text files through the ResouceLoader
this will be needed to read the vmx-template from resources/
Diffstat (limited to 'dozentenmodul/src/main/java/util')
-rw-r--r--dozentenmodul/src/main/java/util/ResourceLoader.java27
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.";
+ }
+ }
}