org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider Java Examples

The following examples show how to use org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Global.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
public Require installRequire(Context cx, List<String> modulePath,
                              boolean sandboxed) {
    RequireBuilder rb = new RequireBuilder();
    rb.setSandboxed(sandboxed);
    List<URI> uris = new ArrayList<URI>();
    if (modulePath != null) {
        for (String path : modulePath) {
            try {
                URI uri = new URI(path);
                if (!uri.isAbsolute()) {
                    // call resolve("") to canonify the path
                    uri = new File(path).toURI().resolve("");
                }
                if (!uri.toString().endsWith("/")) {
                    // make sure URI always terminates with slash to
                    // avoid loading from unintended locations
                    uri = new URI(uri + "/");
                }
                uris.add(uri);
            } catch (URISyntaxException usx) {
                throw new RuntimeException(usx);
            }
        }
    }
    rb.setModuleScriptProvider(
            new SoftCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(uris, null)));
    Require require = rb.createRequire(cx, this);
    require.install(this);
    return require;
}
 
Example #2
Source File: RequireJarTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed)
        throws URISyntaxException
{
    return new Require(cx, cx.initStandardObjects(), 
            new StrongCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(Collections.singleton(
                            getDirectory()), null)), null, null, true);
}
 
Example #3
Source File: Global.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public Require installRequire(Context cx, List<String> modulePath,
                              boolean sandboxed) {
    RequireBuilder rb = new RequireBuilder();
    rb.setSandboxed(sandboxed);
    List<URI> uris = new ArrayList<URI>();
    if (modulePath != null) {
        for (String path : modulePath) {
            try {
                URI uri = new URI(path);
                if (!uri.isAbsolute()) {
                    // call resolve("") to canonify the path
                    uri = new File(path).toURI().resolve("");
                }
                if (!uri.toString().endsWith("/")) {
                    // make sure URI always terminates with slash to
                    // avoid loading from unintended locations
                    uri = new URI(uri + "/");
                }
                uris.add(uri);
            } catch (URISyntaxException usx) {
                throw new RuntimeException(usx);
            }
        }
    }
    rb.setModuleScriptProvider(
            new SoftCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(uris, null)));
    Require require = rb.createRequire(cx, this);
    require.install(this);
    return require;
}
 
Example #4
Source File: RequireTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed)
        throws URISyntaxException
{
    return new Require(cx, cx.initStandardObjects(),
            new StrongCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(Collections.singleton(
                            getDirectory()), null)), null, null, true);
}
 
Example #5
Source File: RequireJarTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed)
        throws URISyntaxException
{
    return new Require(cx, cx.initStandardObjects(),
            new StrongCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(Collections.singleton(
                            getDirectory()), null)), null, null, true);
}
 
Example #6
Source File: ComplianceTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private static Require createRequire(File dir, Context cx, Scriptable scope)
throws URISyntaxException
{
    return new Require(cx, scope, new StrongCachingModuleScriptProvider(
            new UrlModuleSourceProvider(
                    Collections.singleton(dir.getAbsoluteFile().toURI()),
                    Collections.singleton(new URI(ComplianceTest.class.getResource(".").toExternalForm() + "/")))),
                    null, null, false);
}