summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java42
1 files changed, 37 insertions, 5 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
index 02004cc0..a6e932cc 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
@@ -9,7 +9,10 @@ import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
@@ -21,6 +24,7 @@ import javax.swing.ImageIcon;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.openslx.dozmod.Branding;
import org.openslx.dozmod.Config;
/**
@@ -49,7 +53,20 @@ public class ResourceLoader
*/
public static ImageIcon getIcon( String path, String description )
{
- URL url = ResourceLoader.class.getResource( path );
+ URL url = null;
+ if ( Branding.RESOURCE_FS_DIR != null ) {
+ File file = new File( Branding.RESOURCE_FS_DIR + path );
+ try {
+ if ( file.exists() && file.isFile() && file.canRead() ) {
+ url = file.toURI().toURL();
+ }
+ } catch ( MalformedURLException e ) {
+ LOGGER.warn( "Malformed URL: " + file.toString(), e );
+ }
+ }
+ if ( url == null ) {
+ url = ResourceLoader.class.getResource( path );
+ }
if ( url == null ) {
LOGGER.error( "Resource not found: " + path );
} else {
@@ -60,6 +77,7 @@ public class ResourceLoader
icon.getImage().getScaledInstance(Math.round(icon.getIconWidth() * scalingFactor),
Math.round(icon.getIconHeight() * scalingFactor), java.awt.Image.SCALE_SMOOTH),
description);
+ // Success ^^
} catch ( Exception e ) {
LOGGER.error( "Resource not loadable: " + path );
}
@@ -135,10 +153,18 @@ public class ResourceLoader
public static String getTextFile( String path )
{
String fileContent = null;
- try ( InputStream stream = ResourceLoader.class.getResourceAsStream( path ) ) {
- fileContent = IOUtils.toString( stream, StandardCharsets.UTF_8 );
- } catch ( Exception e ) {
- LOGGER.error( "IO error while trying to load resource '" + path + "'. See trace: ", e );
+ if ( Branding.RESOURCE_FS_DIR != null ) {
+ try ( InputStream stream = new FileInputStream( Branding.RESOURCE_FS_DIR + path ) ) {
+ fileContent = IOUtils.toString( stream, StandardCharsets.UTF_8 );
+ } catch ( Exception e ) {
+ }
+ }
+ if ( fileContent == null ) {
+ try ( InputStream stream = ResourceLoader.class.getResourceAsStream( path ) ) {
+ fileContent = IOUtils.toString( stream, StandardCharsets.UTF_8 );
+ } catch ( Exception e ) {
+ LOGGER.error( "IO error while trying to load resource '" + path + "'. See trace: ", e );
+ }
}
if ( fileContent != null ) {
@@ -150,6 +176,12 @@ public class ResourceLoader
public static InputStream getStream( String path )
{
+ if ( Branding.RESOURCE_FS_DIR != null ) {
+ try {
+ return new FileInputStream( Branding.RESOURCE_FS_DIR + path );
+ } catch (Exception e) {
+ }
+ }
return ResourceLoader.class.getResourceAsStream( path );
}