UriPolicy policy = makePolicy(gadget);
URI javaGadgetUri = gadgetContext.getUrl().toJavaUri();
MessageQueue mq = new SimpleMessageQueue();
MessageContext context = new MessageContext();
PluginMeta meta = new PluginMeta(fetcher, policy);
PluginCompiler compiler = makePluginCompiler(meta, mq);
compiler.setMessageContext(context);
if (debug) {
// This will load cajita-debugmode.js
gadget.addFeature("caja-debug");
compiler.setGoals(compiler.getGoals()
.without(PipelineMaker.ONE_CAJOLED_MODULE)
.with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG));
}
InputSource is = new InputSource(javaGadgetUri);
boolean safe = false;
compiler.addInput(new Dom(root), javaGadgetUri);
try {
if (!compiler.run()) {
throw new GadgetRewriteException("Gadget has compile errors");
}
StringBuilder scriptBody = new StringBuilder();
CajoledModule cajoled = compiler.getJavascript();
TokenConsumer tc = debug
? new JsPrettyPrinter(new Concatenator(scriptBody))
: new JsMinimalPrinter(new Concatenator(scriptBody));
cajoled.render(new RenderContext(tc)
.withAsciiOnly(true)
.withEmbeddable(true));
tc.noMoreTokens();
Node html = compiler.getStaticHtml();
Element script = doc.createElementNS(
Namespaces.HTML_NAMESPACE_URI, "script");
script.setAttributeNS(
Namespaces.HTML_NAMESPACE_URI, "type", "text/javascript");