* allow local file override for fn:script scheme. Scripts must be saved as "{appdir}/scripts/name.groovy"

This commit is contained in:
Reinhard Pointner 2012-07-13 04:58:46 +00:00
parent 6631740d98
commit 9effd7cc6d
1 changed files with 16 additions and 3 deletions

View File

@ -211,10 +211,23 @@ public class ArgumentProcessor {
boolean trusted = trustRemoteScript; boolean trusted = trustRemoteScript;
// special handling for endorsed online scripts // special handling for endorsed online scripts
if (uri.getScheme().endsWith("fn")) { if (uri.getScheme().equals("fn")) {
url = "http://filebot.sourceforge.net/scripts/" + uri.getAuthority() + ".groovy"; String path = "/scripts/" + uri.getAuthority() + ".groovy";
// check for local override
File local = new File(getApplicationFolder(), path);
if (local.exists()) {
CLILogger.finest(String.format("[resolve] %s => %s", uri, local));
return new Script(readAll(new InputStreamReader(new FileInputStream(local), "UTF-8")), true);
} else {
// script repository
URL remote = new URL("http", "filebot.sourceforge.net", path);
CLILogger.finest(String.format("[resolve] %s => %s", uri, remote));
url = remote.toString();
trusted = true; trusted = true;
} }
}
// fetch remote script only if modified // fetch remote script only if modified
CachedResource<String> script = new CachedResource<String>(url, String.class, 24 * 60 * 60 * 1000) { CachedResource<String> script = new CachedResource<String>(url, String.class, 24 * 60 * 60 * 1000) {