this.compiler = compiler;
}
public boolean process(JsRequest request, JsResponseBuilder builder) throws JsException {
// Get JavaScript content from features aliases request.
JsUri jsUri = request.getJsUri();
GadgetContext ctx = new JsGadgetContext(jsUri);
FeatureRegistry registry;
try {
registry = registryProvider.get(jsUri.getRepository());
} catch (GadgetException e) {
throw new JsException(e.getHttpStatusCode(), e.getMessage());
}
// TODO: possibly warn on unknown/unrecognized libs.
List<FeatureBundle> requestedBundles = registry.getFeatureResources(
ctx, jsUri.getLibs(), null).getBundles();
List<FeatureBundle> loadedBundles = registry.getFeatureResources(
ctx, jsUri.getLoadedLibs(), null).getBundles();
Set<String> loadedFeatures = Sets.newHashSet();
for (FeatureBundle bundle : loadedBundles) {
loadedFeatures.add(bundle.getName());
builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, true));
builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, false));
}
// Collate all JS desired for the current request.
boolean isProxyCacheable = true;
for (FeatureBundle bundle : requestedBundles) {
// Exclude all transitively-dependent loaded features.
if (loadedFeatures.contains(bundle.getName())) {
continue;
}
builder.appendAllJs(compiler.getJsContent(jsUri, bundle));
for (FeatureResource featureResource : bundle.getResources()) {
isProxyCacheable = isProxyCacheable && featureResource.isProxyCacheable();
}
}
builder.setProxyCacheable(isProxyCacheable);
UriStatus uriStatus = jsUri.getStatus();
setResponseCacheTtl(builder, uriStatus != null ? uriStatus : UriStatus.VALID_UNVERSIONED);
return true;
}