@Override protected ModuleSource loadFromPrivilegedLocations(String moduleId, Object validator) throws IOException, URISyntaxException { String moduleIdWithExtension = moduleId; if (!moduleIdWithExtension.endsWith(".js")) { moduleIdWithExtension += ".js"; } if (mModules.contains(moduleIdWithExtension)) { return new ModuleSource(new InputStreamReader(mContext.getAssets().open(MODULES_PATH + "/" + moduleIdWithExtension)), null, URI.create(moduleIdWithExtension), mBaseURI, validator); } return super.loadFromPrivilegedLocations(moduleId, validator); }
@SuppressWarnings("nls") public ModuleSource loadFromScriptableObject(String moduleId) throws UnsupportedEncodingException, URISyntaxException { Object object = scriptable.get(moduleId, scriptable); if(object !=null) { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(object.toString().getBytes("UTF-8")); Reader reader = new InputStreamReader(byteArrayInputStream); URI uri = new URI("#" + moduleId); return new ModuleSource(reader, null, uri, null, null); } return null; }
@Override protected ModuleSource loadFromUri(URI uri, URI base, Object validator) throws IOException, URISyntaxException { try { LOGGER.info(format("Loading js module [%s]", uri.toString())); return new ModuleSource(getReader(uri.toString()), null, uri, base, validator); } catch (Exception ex) { LOGGER.warn(format("Loading js module [%s] failed.", uri.toString())); return null; } }
@Override protected ModuleSource loadFromFallbackLocations(String moduleId, Object validator) throws IOException, URISyntaxException { LOGGER.info(String.format("Loading js module from fallback location %s", moduleId)); return new ModuleSource(getReader(moduleId), null, new URI(moduleId), new URI("./"), validator); }
@Override public ModuleSource loadSource(String moduleId, Scriptable paths, Object validator) throws IOException, URISyntaxException { return loadFromScriptableObject(moduleId); }
@Override public ModuleSource loadSource(URI uri, URI baseUri, Object validator) throws IOException, URISyntaxException { return null; }