< prev index next >

modules/graphics/src/main/java/javafx/scene/image/Image.java

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


1087     }
1088 
1089     private static ImageLoader loadPlatformImage(Object platformImage) {
1090         return Toolkit.getToolkit().loadPlatformImage(platformImage);
1091     }
1092 
1093     private static String validateUrl(final String url) {
1094         if (url == null) {
1095             throw new NullPointerException("URL must not be null");
1096         }
1097 
1098         if (url.trim().isEmpty()) {
1099             throw new IllegalArgumentException("URL must not be empty");
1100         }
1101 
1102         try {
1103             if (!URL_QUICKMATCH.matcher(url).matches()) {
1104                 final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
1105                 URL resource;
1106                 if (url.charAt(0) == '/') {

1107                     resource = contextClassLoader.getResource(url.substring(1));
1108                 } else {

1109                     resource = contextClassLoader.getResource(url);
1110                 }
1111                 if (resource == null) {
1112                     throw new IllegalArgumentException("Invalid URL or resource not found");
1113                 }
1114                 return resource.toString();
1115             }
1116             // Use URL constructor for validation
1117             return new URL(url).toString();
1118         } catch (final IllegalArgumentException e) {
1119             throw new IllegalArgumentException(
1120                     constructDetailedExceptionMessage("Invalid URL", e), e);
1121         } catch (final MalformedURLException e) {
1122             throw new IllegalArgumentException(
1123                     constructDetailedExceptionMessage("Invalid URL", e), e);
1124         }
1125     }
1126 
1127     private static InputStream validateInputStream(
1128             final InputStream inputStream) {




1087     }
1088 
1089     private static ImageLoader loadPlatformImage(Object platformImage) {
1090         return Toolkit.getToolkit().loadPlatformImage(platformImage);
1091     }
1092 
1093     private static String validateUrl(final String url) {
1094         if (url == null) {
1095             throw new NullPointerException("URL must not be null");
1096         }
1097 
1098         if (url.trim().isEmpty()) {
1099             throw new IllegalArgumentException("URL must not be empty");
1100         }
1101 
1102         try {
1103             if (!URL_QUICKMATCH.matcher(url).matches()) {
1104                 final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
1105                 URL resource;
1106                 if (url.charAt(0) == '/') {
1107                     // FIXME: JIGSAW -- use Class.getResourceAsStream if resource is in a module
1108                     resource = contextClassLoader.getResource(url.substring(1));
1109                 } else {
1110                     // FIXME: JIGSAW -- use Class.getResourceAsStream if resource is in a module
1111                     resource = contextClassLoader.getResource(url);
1112                 }
1113                 if (resource == null) {
1114                     throw new IllegalArgumentException("Invalid URL or resource not found");
1115                 }
1116                 return resource.toString();
1117             }
1118             // Use URL constructor for validation
1119             return new URL(url).toString();
1120         } catch (final IllegalArgumentException e) {
1121             throw new IllegalArgumentException(
1122                     constructDetailedExceptionMessage("Invalid URL", e), e);
1123         } catch (final MalformedURLException e) {
1124             throw new IllegalArgumentException(
1125                     constructDetailedExceptionMessage("Invalid URL", e), e);
1126         }
1127     }
1128 
1129     private static InputStream validateInputStream(
1130             final InputStream inputStream) {


< prev index next >