Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2015-12-01 14:16:51 +0000
committerTom Schindl2015-12-01 14:17:24 +0000
commitbe3fc273a0f981f7c16ff28f4e97c6d9bbce0898 (patch)
treef474e27dbe65da2dd559aea62d82e49a61604640
parent0d12ddbcffa4de56a3c702a1d5bc163dd57518b4 (diff)
downloadorg.eclipse.efxclipse-be3fc273a0f981f7c16ff28f4e97c6d9bbce0898.tar.gz
org.eclipse.efxclipse-be3fc273a0f981f7c16ff28f4e97c6d9bbce0898.tar.xz
org.eclipse.efxclipse-be3fc273a0f981f7c16ff28f4e97c6d9bbce0898.zip
Bug 483378 - Add support to convert eg OSGi-URLs to the local filesystem
-rw-r--r--bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/URLResolver.java10
-rw-r--r--bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/Util.java16
-rw-r--r--bundles/runtime/org.eclipse.fx.osgi.util/src/org/eclipse/fx/osgi/util/internal/FileLocatorURLResolver.java13
3 files changed, 37 insertions, 2 deletions
diff --git a/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/URLResolver.java b/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/URLResolver.java
index 1c8a26c9c..62d1b9971 100644
--- a/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/URLResolver.java
+++ b/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/URLResolver.java
@@ -35,4 +35,14 @@ public interface URLResolver extends Predicate<@NonNull URL> {
* @return the local path
*/
public @NonNull Path resolveToLocalPath(URL url);
+
+ /**
+ * Convert the url to a local url which eg can be fed into a JavaFX media
+ * player
+ *
+ * @param url
+ * the url
+ * @return the path
+ */
+ public @NonNull URL resolveToLocalURL(URL url);
}
diff --git a/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/Util.java b/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/Util.java
index 1f91cd6a7..7e559c2f3 100644
--- a/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/Util.java
+++ b/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/Util.java
@@ -314,6 +314,7 @@ public class Util {
* <code>true</code> if the url can not be converted to a local
* the content is copied to the local filesystem
* @return the path
+ * @since 2.2.0
*/
public static Optional<Resource> getLocalPath(@NonNull URL url, boolean copyIfNeeded) {
return lookupServiceList(URLResolver.class)
@@ -323,6 +324,21 @@ public class Util {
.orElseGet(() -> copyIfNeeded ? ExExecutor.executeSupplier( () -> Util.copyToTempFile(url), "Unable to copy resource") : Optional.empty()); //$NON-NLS-1$
}
+ /**
+ * Convert an URL to a path on the local filesystem
+ *
+ * @param url
+ * the url
+ * @return the path
+ * @since 2.2.0
+ */
+ public static Optional<URL> getLocalURL(@NonNull URL url) {
+ return lookupServiceList(URLResolver.class)
+ .stream()
+ .filter(r -> r.test(url)).findFirst()
+ .map(r -> r.resolveToLocalURL(url));
+ }
+
private static Resource copyToTempFile(@NonNull URL url) throws IOException {
Path path = Files.createTempFile("tmp", Paths.get(url.getPath()).getFileName().toString()); //$NON-NLS-1$
diff --git a/bundles/runtime/org.eclipse.fx.osgi.util/src/org/eclipse/fx/osgi/util/internal/FileLocatorURLResolver.java b/bundles/runtime/org.eclipse.fx.osgi.util/src/org/eclipse/fx/osgi/util/internal/FileLocatorURLResolver.java
index a927d8267..a8484733f 100644
--- a/bundles/runtime/org.eclipse.fx.osgi.util/src/org/eclipse/fx/osgi/util/internal/FileLocatorURLResolver.java
+++ b/bundles/runtime/org.eclipse.fx.osgi.util/src/org/eclipse/fx/osgi/util/internal/FileLocatorURLResolver.java
@@ -29,7 +29,7 @@ public class FileLocatorURLResolver implements URLResolver {
@Override
public boolean test(@NonNull URL t) {
try {
- return FileLocator.toFileURL(t) != null;
+ return FileLocator.resolve(t) != null;
} catch (IOException e) {
return false;
}
@@ -45,4 +45,13 @@ public class FileLocatorURLResolver implements URLResolver {
}
}
-}
+ @SuppressWarnings("null")
+ @Override
+ public @NonNull URL resolveToLocalURL(URL url) {
+ try {
+ return FileLocator.resolve(url);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+} \ No newline at end of file

Back to the top