throws GadgetException {
// TODO: If there isn't any js in the document, we can skip this. Unfortunately, that means
// both script tags (easy to detect) and event handlers (much more complex).
GadgetContext context = gadget.getContext();
String repository = getFeatureRepositoryId(gadget);
FeatureRegistry featureRegistry = featureRegistryProvider.get(repository);
checkRequiredFeatures(gadget, featureRegistry);
//Check to make sure all the required features that are about to be injected are allowed
if(!gadgetAdminStore.checkFeatureAdminInfo(gadget)) {
throw new GadgetException(Code.GADGET_ADMIN_FEATURE_NOT_ALLOWED);
}
// Set of extern libraries requested by the container
Set<String> externForcedLibs = defaultExternLibs;
// gather the libraries we'll need to generate the extern script for
String externParam = context.getParameter("libs");
if (StringUtils.isNotBlank(externParam)) {
externForcedLibs = Sets.newTreeSet(Splitter.on(':').split(externParam));
}
// Inject extern script
if (!externForcedLibs.isEmpty()) {
injectScript(externForcedLibs, null, false, gadget, headTag, firstHeadChild, "");
}
Collection<String> gadgetLibs = Lists.newArrayList(gadget.getDirectFeatureDeps());
List<Feature> gadgetFeatures = gadget.getSpec().getModulePrefs().getAllFeatures();
for(Feature feature : gadgetFeatures) {
if(!feature.getRequired() &&
!gadgetAdminStore.isAllowedFeature(feature, gadget)) {
//If the feature is optional and the admin has not allowed it don't include it
gadgetLibs.remove(feature.getName());
}
}
// Get config for all features
Set<String> allLibs = ImmutableSet.<String>builder()
.addAll(externForcedLibs).addAll(gadgetLibs).build();
String libraryConfig =
getLibraryConfig(gadget, featureRegistry.getFeatures(allLibs));
// Inject internal script
injectScript(gadgetLibs, externForcedLibs, !externalizeFeatures,
gadget, headTag, firstHeadChild, libraryConfig);
}