[libbluray-devel] BDJXletContext: added helpers to get current Xlet resources

hpi1 git at videolan.org
Mon Jan 20 14:39:41 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Jan 20 14:05:29 2014 +0200| [96d9d5d1008f297ece0e1d44b3444a656235d5c1] | committer: hpi1

BDJXletContext: added helpers to get current Xlet resources

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

 src/libbluray/bdj/java/java/awt/BDToolkitBase.java |   16 +++-------
 .../bdj/java/org/videolan/BDJXletContext.java      |   33 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/src/libbluray/bdj/java/java/awt/BDToolkitBase.java b/src/libbluray/bdj/java/java/awt/BDToolkitBase.java
index 995df97..4998343 100644
--- a/src/libbluray/bdj/java/java/awt/BDToolkitBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDToolkitBase.java
@@ -132,18 +132,10 @@ abstract class BDToolkitBase extends Toolkit {
 
     public Image createImage(String filename) {
         if (!new File(filename).exists()) {
-            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());
+            URL url = BDJXletContext.getCurrentResource(filename);
+            if (url != null) {
+                logger.warning("" + filename + " translated to " + url);
+                return createImage(url);
             }
         }
 
diff --git a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
index 09aaf43..9759276 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJXletContext.java
@@ -21,6 +21,7 @@ package org.videolan;
 
 import java.awt.Container;
 import java.awt.EventQueue;
+import java.net.URL;
 import java.util.LinkedList;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -97,6 +98,38 @@ public class BDJXletContext implements javax.tv.xlet.XletContext, javax.microedi
         return loader;
     }
 
+    public static ClassLoader getCurrentClassLoader() {
+        BDJXletContext ctx = BDJXletContext.getCurrentContext();
+        if (ctx == null) {
+            logger.error("getCurrentClassLoader(): no context: " + Logger.dumpStack());
+            return null;
+        }
+
+        ClassLoader cldr = (ClassLoader)ctx.getClassLoader();
+        if (cldr == null) {
+            logger.error("getCurrentClassLoader(): no class loader: " + Logger.dumpStack());
+            return null;
+        }
+
+        return cldr;
+    }
+
+    public static URL getCurrentResource(String path)
+    {
+        ClassLoader cldr = (ClassLoader)BDJXletContext.getCurrentClassLoader();
+        if (cldr == null) {
+            return null;
+        }
+
+        URL url = cldr.getResource(path);
+        if (url == null) {
+            logger.error("getCurrentResource(): " + path + " not found: " + Logger.dumpStack());
+            return null;
+        }
+
+        return url;
+    }
+
     protected AppProxy getAppProxy() {
         return AppsDatabase.getAppsDatabase().getAppProxy(appid);
     }



More information about the libbluray-devel mailing list