ClosureDependencyUriLocator implements UriLocator { @Override public InputStream locate(String uri) throws IOException { StringBuilder javascript = new StringBuilder("goog.addDependency('"); int state = 0; for (String part : uri.split("@@")) { switch (state) { case 0: final String path = part.substring(URI_PREFIX.length()); javascript.append(PATH_TO_WEBAPP_BASE_FROM_CLOSURE_BASE_JS_FILE); if (!path.startsWith("/")) { javascript.append("/"); } javascript.append(path).append("', ['"); break; case 1: javascript.append(part).append("'], ["); break; default: if (javascript.charAt(javascript.length() - 1) != '[') { javascript.append(','); } javascript.append("'").append(part).append("'"); } state++; } javascript.append("]);\n"); return new ByteArrayInputStream(javascript.toString().getBytes("UTF-8")); }  @Override InputStream locate(String uri); @Override boolean accept(String uri); static final String URI_PREFIX; static final String URI_LOCATOR_ID; }
@Test public void testLocate() throws Exception { final ClosureDependencyUriLocator locator = new ClosureDependencyUriLocator(); final Resource resource = new Resource(); resource.setUri(ClosureDependencyUriLocator.URI_PREFIX + "/abc.js@@a"); assertTrue(locator.accept(resource.getUri())); final String actual = IOUtils.toString(locator.locate(resource.getUri())); assertEquals("goog.addDependency('" + PATH_TO_WEBAPP_BASE_FROM_CLOSURE_BASE_JS_FILE + "/abc.js', ['a'], []);\n", actual); }