< prev index next >

modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java

Print this page
rev 9619 : [mq]: 9-jake.patch

@@ -53,10 +53,12 @@
 import java.io.FilePermission;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.security.AccessControlContext;

@@ -840,10 +842,14 @@
     //
     // Stylesheet loading
     //
     ////////////////////////////////////////////////////////////////////////////
 
+
+    private static final String skinPrefix = "com/sun/javafx/scene/control/skin/";
+    private static final String skinUtilsClassName = "com.sun.javafx.scene.control.skin.Utils";
+
     private static URL getURL(final String str) {
 
         // Note: this code is duplicated, more or less, in URLConverter
 
         if (str == null || str.trim().isEmpty()) return null;

@@ -853,15 +859,35 @@
             URI uri =  new URI(str.trim());
 
             // if url doesn't have a scheme
             if (uri.isAbsolute() == false) {
 
+                // FIXME: JIGSAW -- move this into a utility method, since it will
+                // likely be needed elsewhere (e.g., in URLConverter)
+                if (str.startsWith(skinPrefix) &&
+                        (str.endsWith(".css") || str.endsWith(".bss"))) {
+
+                    try {
+                        ClassLoader cl = StyleManager.class.getClassLoader();
+                        Class<?> clz = Class.forName(skinUtilsClassName, true, cl);
+                        Method m_getResource = clz.getMethod("getResource", String.class);
+                        return (URL)m_getResource.invoke(null, str.substring(skinPrefix.length()));
+                    } catch (ClassNotFoundException
+                            | NoSuchMethodException
+                            | IllegalAccessException
+                            | InvocationTargetException ex) {
+                        ex.printStackTrace();
+                        return null;
+                    }
+                }
+
                 final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                 final String path = uri.getPath();
 
                 URL resource = null;
 
+                // FIXME: JIGSAW -- The following will only find resources not in a module
                 if (path.startsWith("/")) {
                     resource = contextClassLoader.getResource(path.substring(1));
                 } else {
                     resource = contextClassLoader.getResource(path);
                 }

@@ -914,10 +940,15 @@
     public static Stylesheet loadStylesheet(final String fname) {
         try {
             return loadStylesheetUnPrivileged(fname);
         } catch (java.security.AccessControlException ace) {
 
+            // FIXME: JIGSAW -- we no longer are in a jar file, so this code path
+            // is obsolete and needs to be redone or eliminated. Fortunately, I
+            // don't think it is actually needed.
+            System.err.println("WARNING: security exception trying to load: " + fname);
+
             /*
             ** we got an access control exception, so
             ** we could be running from an applet/jnlp/or with a security manager.
             ** we'll allow the app to read a css file from our runtime jar,
             ** and give it one more chance.
< prev index next >