diff --git a/source/net/sourceforge/filebot/cli/ArgumentBean.java b/source/net/sourceforge/filebot/cli/ArgumentBean.java index d8d2e983..420aa2f4 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentBean.java +++ b/source/net/sourceforge/filebot/cli/ArgumentBean.java @@ -7,8 +7,8 @@ import static net.sourceforge.tuned.FileUtilities.*; import java.io.File; import java.io.FileNotFoundException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -143,16 +143,23 @@ public class ArgumentBean { } - public URL getScriptLocation() { + public URI getScriptLocation() { try { - return new URL(script); - } catch (MalformedURLException eu) { + return new URI(script); + } catch (URISyntaxException eu) { + if (script.startsWith("script://")) { + try { + return new URI("script", script.substring(9), null, null, null); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); + } + } try { File file = new File(script); - if (!file.exists()) + if (!file.exists()) { throw new FileNotFoundException(file.getPath()); - - return file.toURI().toURL(); + } + return file.toURI(); } catch (Exception e) { throw new IllegalArgumentException(e); } diff --git a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java index 4e183c13..cee0a3cd 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentProcessor.java +++ b/source/net/sourceforge/filebot/cli/ArgumentProcessor.java @@ -91,7 +91,7 @@ public class ArgumentProcessor { Bindings bindings = new SimpleBindings(); bindings.put("args", args.getFiles(false)); - Analytics.trackEvent("CLI", "ExecuteScript", args.getScriptLocation().getProtocol()); + Analytics.trackEvent("CLI", "ExecuteScript", args.getScriptLocation().getScheme()); ScriptShell shell = new ScriptShell(cli, args, args.trustScript, AccessController.getContext()); shell.run(args.getScriptLocation(), bindings); } diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.java b/source/net/sourceforge/filebot/cli/ScriptShell.java index 993407a2..2cad7ca0 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.java +++ b/source/net/sourceforge/filebot/cli/ScriptShell.java @@ -10,9 +10,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.FilePermission; import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; import java.lang.reflect.ReflectPermission; import java.net.SocketPermission; -import java.net.URL; +import java.net.URI; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.security.AccessControlContext; @@ -95,9 +97,17 @@ class ScriptShell { } - public Object run(URL scriptLocation, Bindings bindings) throws Throwable { - if (scriptLocation.getProtocol().equals("file")) { - return run(new File(scriptLocation.toURI()), bindings); + public Object run(URI scriptLocation, Bindings bindings) throws Throwable { + if (scriptLocation.getScheme().equals("file")) { + return run(new InputStreamReader(new FileInputStream(new File(scriptLocation)), "UTF-8"), bindings); + } + + if (scriptLocation.getScheme().equals("system")) { + return run(new InputStreamReader(System.in), bindings); + } + + if (scriptLocation.getScheme().equals("script")) { + return run(new StringReader(scriptLocation.getAuthority()), bindings); } // fetch remote script only if modified @@ -112,9 +122,8 @@ class ScriptShell { } - public Object run(File scriptFile, Bindings bindings) throws Throwable { - String script = readAll(new InputStreamReader(new FileInputStream(scriptFile), "UTF-8")); - return evaluate(script, bindings); + public Object run(Reader script, Bindings bindings) throws Throwable { + return evaluate(readAll(script), bindings); }