[libbluray-devel] Workaround for unimplemented VFS: translate relative paths to urls when loading images

hpi1 git at videolan.org
Sat Mar 30 01:39:09 CET 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Mar 30 00:16:00 2013 +0200| [5495b98896d1a558a59244840ab68cdcab0af50f] | committer: hpi1

Workaround for unimplemented VFS: translate relative paths to urls when loading images

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=5495b98896d1a558a59244840ab68cdcab0af50f
---

 .../bdj/java-j2me/java/awt/BDToolkit.java          |   21 ++++++++++++++++++++
 .../bdj/java-j2se/java/awt/BDToolkit.java          |   20 +++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java b/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
index d6c67a1..5e74d3e 100644
--- a/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
+++ b/src/libbluray/bdj/java-j2me/java/awt/BDToolkit.java
@@ -32,11 +32,16 @@ import sun.awt.image.ByteArrayImageSource;
 import sun.awt.image.FileImageSource;
 import sun.awt.image.URLImageSource;
 
+import org.videolan.BDJXletContext;
+import org.videolan.Logger;
+
 class BDToolkit extends Toolkit {
     private EventQueue eventQueue = new EventQueue();
     private BDGraphicsEnvironment localEnv = new BDGraphicsEnvironment();
     private BDGraphicsConfiguration defaultGC = (BDGraphicsConfiguration)localEnv.getDefaultScreenDevice().getDefaultConfiguration();
     private static Hashtable cachedImages = new Hashtable();
+    private static final Logger logger = Logger.getLogger(BDToolkit.class.getName());
+
     public BDToolkit () {}
 
     public static void setFocusedWindow(Window window) {
@@ -112,6 +117,22 @@ class BDToolkit extends Toolkit {
     }
 
     public Image createImage(String filename) {
+        if (filename.charAt(0) != '/') {
+            BDJXletContext ctx = BDJXletContext.getCurrentContext();
+            if (ctx != null) {
+                ClassLoader cldr = (ClassLoader)ctx.getClassLoader();
+                URL url = cldr.getResource(filename);
+                if (url != null) {
+                    logger.warning("" + filename + " translated to " + url);
+                    return createImage(url);
+                } else {
+                    logger.error("ClassLoader failed to translate " + filename);
+                }
+            } else {
+                logger.error("createImage(" + filename + "): no XletContext available!\n" + logger.dumpStack());
+            }
+        }
+
         ImageProducer ip = new FileImageSource(filename);
         Image newImage = createImage(ip);
         return newImage;
diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java b/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
index 6e6f16a..dba8074 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/BDToolkit.java
@@ -37,11 +37,15 @@ import sun.awt.KeyboardFocusManagerPeerProvider;
 import java.awt.peer.BDFramePeer;
 import java.awt.peer.BDKeyboardFocusManagerPeer;
 
+import org.videolan.BDJXletContext;
+import org.videolan.Logger;
+
 public class BDToolkit extends Toolkit implements KeyboardFocusManagerPeerProvider {
     private EventQueue eventQueue = new EventQueue();
     private BDGraphicsEnvironment localEnv = new BDGraphicsEnvironment();
     private BDGraphicsConfiguration defaultGC = (BDGraphicsConfiguration)localEnv.getDefaultScreenDevice().getDefaultConfiguration();
     private static Hashtable cachedImages = new Hashtable();
+    private static final Logger logger = Logger.getLogger(BDToolkit.class.getName());
 
     public BDToolkit () {
     }
@@ -124,6 +128,22 @@ public class BDToolkit extends Toolkit implements KeyboardFocusManagerPeerProvid
     }
 
     public Image createImage(String filename) {
+        if (filename.charAt(0) != '/') {
+            BDJXletContext ctx = BDJXletContext.getCurrentContext();
+            if (ctx != null) {
+                ClassLoader cldr = (ClassLoader)ctx.getClassLoader();
+                URL url = cldr.getResource(filename);
+                if (url != null) {
+                    logger.warning("" + filename + " translated to " + url);
+                    return createImage(url);
+                } else {
+                    logger.error("ClassLoader failed to translate " + filename);
+                }
+            } else {
+                logger.error("createImage(" + filename + "): no XletContext available!\n" + logger.dumpStack());
+            }
+        }
+
         ImageProducer ip = new FileImageSource(filename);
         Image newImage = createImage(ip);
         return newImage;



More information about the libbluray-devel mailing list