Examples of PluginCompiler


Examples of com.google.caja.plugin.PluginCompiler

    PluginMeta meta = new PluginMeta(fetcher, null);
    if (opt_idClass != null && opt_idClass.length() != 0) {
      meta.setIdClass(opt_idClass);
    }
    PluginCompiler compiler = makePluginCompiler(meta, mq);
    compiler.setJobCache(new AppEngineJobCache());
    compiler.setMessageContext(mc);

    URI uri = guessURI(base, url);
    InputSource is = new InputSource(uri);
    CharProducer cp = CharProducer.Factory.fromString(input, is);
    boolean okToContinue = true;
    Dom inputNode = null;
    try {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      inputNode = Dom.transplant(p.parseDocument());
      p.getTokenQueue().expectEmpty();
    } catch (ParseException e) {
      mq.addMessage(e.getCajaMessage());
      okToContinue = false;
    }

    if (okToContinue && inputNode != null) {
      compiler.addInput(inputNode, uri);
      okToContinue &= compiler.run();
    }

    outputJs = okToContinue ? compiler.getJavascript() : null;
    outputHtml = okToContinue ? compiler.getStaticHtml() : null;

    String[] messages = formatMessages(originalSources, mc, mq);

    StringBuilder jsOut = new StringBuilder();
    TokenConsumer renderer = new JsPrettyPrinter(jsOut);
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    return BuildInfo.getInstance().getBuildInfo();
  }

  protected PluginCompiler makePluginCompiler(
      PluginMeta meta, MessageQueue mq) {
    PluginCompiler compiler = new PluginCompiler(
        BuildInfo.getInstance(), meta, mq);
    return compiler;
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

      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);

      /**
       * TODO(jasvir): This can provide support for debugging with
       * cajita-debugmode.js but cajita-debugmode.js should be loaded
       * iff url param debug=1
       *
       *      if (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");
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    LOG.info("Unable to cajole gadget: " + errbuilder);
  }
 
  protected PluginCompiler makePluginCompiler(
      PluginMeta meta, MessageQueue mq) {
    PluginCompiler compiler = new PluginCompiler(
        BuildInfo.getInstance(), meta, mq);
    return compiler;
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

  private void cajoleHtml(URI inputUri, CharProducer cp, PluginMeta meta,
                          String jsonpCallback,
                          boolean htmlInline, Appendable output,
                          boolean pretty, MessageQueue mq) {
    PluginCompiler compiler = null;
    boolean okToContinue = true;

    try {
      InputSource is = new InputSource (inputUri);
      compiler = new PluginCompiler(buildInfo, meta, mq);

      if (htmlInline) {
        compiler.setGoals(
            compiler.getGoals().without(PipelineMaker.HTML_SAFE_STATIC));
      }

      Dom html = null;
      try {
        html = (Dom) new ParserContext(mq)
            .withInput(cp)
            .withInput(is)
            .withInput(ContentType.HTML)
            .build();
      } catch (ParseException e) {
        okToContinue = false;
      }

      if (okToContinue) {
        compiler.addInput(html, inputUri);
        okToContinue &= compiler.run();
      }
    } catch (Exception e) {
      mq.addMessage(ServiceMessageType.EXCEPTION_IN_SERVICE,
          MessagePart.Factory.valueOf(e.getMessage()));
      okToContinue = false;
    }

    try {
      if (okToContinue && compiler != null) {
        renderAsJSON(
            compiler.getStaticHtml(),
            compiler.getJavascript(),
            jsonpCallback, mq, output, pretty);
      } else {
        renderAsJSON(
            (String)null,
            (String)null,
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

  }

  private double runCajoledES53(String filename) throws Exception {
    PluginMeta meta = new PluginMeta();
    MessageQueue mq = new SimpleMessageQueue();
    PluginCompiler pc = new PluginCompiler(new TestBuildInfo(), meta, mq);
    CharProducer src = fromString(plain(fromResource(filename)));
    pc.addInput(js(src), is.getUri());

    if (!pc.run()) {
      return -1;
    }
    String cajoledJs = render(pc.getJavascript());
    System.err.println("-- Cajoled:" + filename +
          "(es53: true" + ") --\n" + cajoledJs + "\n---\n");
    Number elapsed = (Number) RhinoTestBed.runJs(
        new Executor.Input(getClass(),
            "../../../../../js/json_sans_eval/json_sans_eval.js"),
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

  public CajoledModule es53(Block plain) {
    CajoledModule result = null;
    PluginMeta meta = new PluginMeta();
    MessageQueue mq = TestUtil.createTestMessageQueue(this.mc);
    PluginCompiler pc = new PluginCompiler(
        TestBuildInfo.getInstance(), meta, mq);
    pc.addInput(plain, null);
    if (pc.run()) {
      result = pc.getJavascript();
      return result;
    } else {
      return null;
    }
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    PluginMeta meta = new PluginMeta(fetcher, null);
    if (opt_idClass != null && opt_idClass.length() != 0) {
      meta.setIdClass(opt_idClass);
    }
    PluginCompiler compiler = makePluginCompiler(meta, mq);
    compiler.setJobCache(new AppEngineJobCache());
    compiler.setMessageContext(mc);

    URI uri = guessURI(base, url);
    InputSource is = new InputSource(uri);
    CharProducer cp = CharProducer.Factory.fromString(input, is);
    boolean okToContinue = true;
    Dom inputNode = null;
    try {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      inputNode = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    } catch (ParseException e) {
      mq.addMessage(e.getCajaMessage());
      okToContinue = false;
    }

    if (okToContinue && inputNode != null) {
      compiler.addInput(inputNode, uri);
      okToContinue &= compiler.run();
    }

    outputJs = okToContinue ? compiler.getJavascript() : null;
    outputHtml = okToContinue ? compiler.getStaticHtml() : null;

    String[] messages = formatMessages(originalSources, mc, mq);

    StringBuilder jsOut = new StringBuilder();
    TokenConsumer renderer = new JsPrettyPrinter(jsOut);
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    return BuildInfo.getInstance().getBuildInfo();
  }

  protected PluginCompiler makePluginCompiler(
      PluginMeta meta, MessageQueue mq) {
    PluginCompiler compiler = new PluginCompiler(
        BuildInfo.getInstance(), meta, mq);
    return compiler;
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

import com.google.caja.util.Join;

public class PrecajoledPipelineTest extends CajaTestCase {

  public final void testPretty() throws Exception {
    PluginCompiler compiler = makeCompiler(false);
    addHtml(compiler,
        "<script src='data:banana'></script>"
        + "<script src='data:capricorn'></script>"
        + "<script>cached:dalmatian</script>");
    assertTrue(compiler.run());
    String js = render(compiler.getJavascript());
    assertContains(js, "'precajoled': 'data:banana false'");
    assertContains(js, "'precajoled': 'data:capricorn false'");
    assertContains(js, "'precajoled': 'cached:dalmatian false'");
    assertNoWarnings();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.