Examples of PluginCompiler


Examples of com.google.caja.plugin.PluginCompiler

    UriPolicy policy = makePolicy(gadgetUri);
    URI javaGadgetUri = gadgetUri.toJavaUri();
    MessageQueue mq = new SimpleMessageQueue();
    MessageContext context = new MessageContext();
    PluginMeta meta = new PluginMeta(fetcher, policy);
    PluginCompiler compiler = makePluginCompiler(meta, mq);
    compiler.setMessageContext(context);
    if (moduleCache != null) {
      compiler.setJobCache(new ModuleCache(moduleCache));
    }

    if (debug) {
      compiler.setGoals(compiler.getGoals()
          .without(PipelineMaker.ONE_CAJOLED_MODULE)
          .with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG));
    }

    compiler.addInput(root, javaGadgetUri);

    boolean hasErrors = false;
    if (!compiler.run()) {
      hasErrors = true;
    }

    return new CajoledResult(compiler.getStaticHtml(),
        compiler.getJavascript(),
        compiler.getMessageQueue().getMessages(),
        hasErrors);
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    }
  }

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

Examples of com.google.caja.plugin.PluginCompiler

        expect(bi.getBuildInfo()).andReturn("bi").anyTimes();
        expect(bi.getBuildTimestamp()).andReturn("0").anyTimes();
        expect(bi.getBuildVersion()).andReturn("0").anyTimes();
        expect(bi.getCurrentTime()).andReturn(0L).anyTimes();
        replay(bi);
        return new PluginCompiler(bi, m, q);
      }
    };
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

        expect(bi.getBuildInfo()).andReturn("bi").anyTimes();
        expect(bi.getBuildTimestamp()).andReturn("0").anyTimes();
        expect(bi.getBuildVersion()).andReturn("0").anyTimes();
        expect(bi.getCurrentTime()).andReturn(0L).anyTimes();
        replay(bi);
        return new PluginCompiler(bi, m, q);
      }
    };

    // we don't really care what the result looks like, we just want to check the issued request
    String markup = "<script type=\"text/javascript\" src=\"http://www.example.com/scripts/scriptFile.js\"></script>";
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    UriPolicy policy = makePolicy(gadgetUri);
    URI javaGadgetUri = gadgetUri.toJavaUri();
    MessageQueue mq = new SimpleMessageQueue();
    MessageContext context = new MessageContext();
    PluginMeta meta = new PluginMeta(fetcher, policy);
    PluginCompiler compiler = makePluginCompiler(meta, mq);
    compiler.setMessageContext(context);
    if (moduleCache != null) {
      compiler.setJobCache(new ModuleCache(moduleCache));
    }

    if (debug) {
      compiler.setGoals(compiler.getGoals()
          .without(PipelineMaker.ONE_CAJOLED_MODULE)
          .with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG));
    }

    compiler.addInput(root, javaGadgetUri);

    boolean hasErrors = false;
    if (!compiler.run()) {
      hasErrors = true;
    }

    return new CajoledResult(compiler.getStaticHtml(),
        compiler.getJavascript(),
        compiler.getMessageQueue().getMessages(),
        hasErrors);
  }
View Full Code Here

Examples of com.google.caja.plugin.PluginCompiler

    }
  }

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

Examples of com.google.caja.plugin.PluginCompiler

    Uri contextUri = req.getUri();
    InputSource is = new InputSource(contextUri.toJavaUri());

    PluginMeta pluginMeta = new PluginMeta(
            proxyFetcher(req, contextUri), proxyUriPolicy(req));
    PluginCompiler compiler = new PluginCompiler(BuildInfo.getInstance(),
            pluginMeta, mq);
    compiler.setMessageContext(mc);

    // Parse the javascript
    try {
      StringReader strReader = new StringReader(resp.getContent());
      CharProducer cp = CharProducer.Factory.create(strReader, is);
      JsTokenQueue tq = new JsTokenQueue(new JsLexer(cp), is);
      ParseTreeNode input = new Parser(tq, mq).parse();
      tq.expectEmpty();

      compiler.addInput(AncestorChain.instance(input).node, contextUri.toJavaUri());
    } catch (ParseException e) {
      // Don't bother continuing.
      resp.setContent("");
      return;
    }

    try {
      if (RewriterUtils.isJavascript(req, resp)) {
        compiler.setGoals(
            compiler.getGoals().without(PipelineMaker.HTML_SAFE_STATIC));
      }
      passed = compiler.run();

      CajoledModule outputJs = passed ? compiler.getJavascript() : null;

      StringBuilder jsOut = new StringBuilder();
      TokenConsumer printer;
      if ("1".equals(req.getParam("debug"))) {
        printer = new JsPrettyPrinter(new Concatenator(jsOut));
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);

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

    Uri contextUri = req.getUri();
    InputSource is = new InputSource(contextUri.toJavaUri());

    PluginMeta pluginMeta = new PluginMeta(
            proxyFetcher(req, contextUri), proxyUriPolicy(req));
    PluginCompiler compiler = new PluginCompiler(BuildInfo.getInstance(),
            pluginMeta, mq);
    compiler.setMessageContext(mc);

    // Parse the javascript
    try {
      StringReader strReader = new StringReader(resp.getContent());
      CharProducer cp = CharProducer.Factory.create(strReader, is);
      JsTokenQueue tq = new JsTokenQueue(new JsLexer(cp), is);
      ParseTreeNode input = new Parser(tq, mq).parse();
      tq.expectEmpty();

      compiler.addInput(AncestorChain.instance(input).node, contextUri.toJavaUri());
    } catch (ParseException e) {
      // Don't bother continuing.
      resp.setContent("");
      return;
    }

    try {
      if (RewriterUtils.isJavascript(req, resp)) {
        compiler.setGoals(
            compiler.getGoals().without(PipelineMaker.HTML_SAFE_STATIC));
      }
      passed = compiler.run();

      CajoledModule outputJs = passed ? compiler.getJavascript() : null;

      StringBuilder jsOut = new StringBuilder();
      TokenConsumer printer;
      if ("1".equals(req.getParam("debug"))) {
        printer = new JsPrettyPrinter(new Concatenator(jsOut));
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.