modules/graphics/src/main/java/com/sun/javafx/css/converters/URLConverter.java

Print this page
rev 8319 : RT-38991: [CSS] Absolute URL in stylesheet does not work


 100 
 101             // if stylesheetUri is null, then we're dealing with an in-line style.
 102             // If there is no scheme part, then the url is interpreted as being relative to the application's class-loader.
 103             URI resourceUri = new URI(resourcePath);
 104 
 105             if (resourceUri.isAbsolute()) {
 106                 return resourceUri.toURL();
 107             }
 108 
 109             URL rtJarUrl = resolveRuntimeImport(resourceUri);
 110             if (rtJarUrl != null) {
 111                 return rtJarUrl;
 112             }
 113 
 114             final String stylesheetPath = (stylesheetUrl != null) ?  stylesheetUrl.trim() : null;
 115 
 116             if (stylesheetPath != null && stylesheetPath.isEmpty() == false) {
 117 
 118                 URI stylesheetUri = new URI(stylesheetPath);
 119 
 120                 if (stylesheetUri.isOpaque() == false) {
 121 
 122                     URI resolved = stylesheetUri.resolve(resourceUri);
 123                     return resolved.toURL();
 124 
 125                 } else {
 126 
 127                     // stylesheet URI is something like jar:file:
 128                     URL url = stylesheetUri.toURL();
 129                     final String path = resourceUri.getPath();
 130                     return new URL(url, resourceUri.getPath());




 131                 }
 132             }
 133 
 134 
 135             // URL doesn't have scheme or stylesheetUrl is null
 136             final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
 137             final String path = resourceUri.getPath();
 138 
 139             URL resolved = null;
 140 
 141             if (path.startsWith("/")) {
 142                 resolved = contextClassLoader.getResource(path.substring(1));
 143             } else {
 144                 resolved = contextClassLoader.getResource(path);
 145             }
 146 
 147             return resolved;
 148 
 149 
 150         } catch (final MalformedURLException|URISyntaxException e) {




 100 
 101             // if stylesheetUri is null, then we're dealing with an in-line style.
 102             // If there is no scheme part, then the url is interpreted as being relative to the application's class-loader.
 103             URI resourceUri = new URI(resourcePath);
 104 
 105             if (resourceUri.isAbsolute()) {
 106                 return resourceUri.toURL();
 107             }
 108 
 109             URL rtJarUrl = resolveRuntimeImport(resourceUri);
 110             if (rtJarUrl != null) {
 111                 return rtJarUrl;
 112             }
 113 
 114             final String stylesheetPath = (stylesheetUrl != null) ?  stylesheetUrl.trim() : null;
 115 
 116             if (stylesheetPath != null && stylesheetPath.isEmpty() == false) {
 117 
 118                 URI stylesheetUri = new URI(stylesheetPath);
 119 
 120                 if (!resourceUri.getPath().startsWith("/")) {
 121                     // if path starts with '/', then the path is considered relative to the class-path
 122                     // and the URL is resolved with the ClassLoader getResource() call below.
 123                     if (stylesheetUri.isOpaque()) {



 124                         // stylesheet URI is something like jar:file:
 125                         URL url = stylesheetUri.toURL();

 126                         return new URL(url, resourceUri.getPath());
 127                     } else {
 128                         URI resolved = stylesheetUri.resolve(resourceUri);
 129                         return resolved.toURL();
 130                     }
 131                 }
 132             }
 133 
 134 
 135             // URL doesn't have scheme or stylesheetUrl is null
 136             final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
 137             final String path = resourceUri.getPath();
 138 
 139             URL resolved = null;
 140 
 141             if (path.startsWith("/")) {
 142                 resolved = contextClassLoader.getResource(path.substring(1));
 143             } else {
 144                 resolved = contextClassLoader.getResource(path);
 145             }
 146 
 147             return resolved;
 148 
 149 
 150         } catch (final MalformedURLException|URISyntaxException e) {