Package com.google.caja.plugin

Examples of com.google.caja.plugin.Job


    List<ScriptPlaceholder> js = Lists.newArrayList();
    URI baseUriForJsModules = null;

    for (Iterator<JobEnvelope> it = jobs.getJobs().iterator(); it.hasNext();) {
      JobEnvelope env = it.next();
      Job job = env.job;
      switch (env.sourceType) {
        case CSS:
          if (!env.fromCache) {
            css.add(new ValidatedStylesheet(
                env, (CssTree.StyleSheet) job.getRoot(), job.getBaseUri()));
            it.remove();
          }
          break;
        case HTML:
          html.add(new IhtmlRoot(
              env, ((Dom) job.getRoot()).getValue(), job.getBaseUri()));
          // Module loading in embedded <script>s should use the URI of the
          // HTML file as the base URI. We use a heuristic that there's only
          // one HTML file per compilation task, and use the URI of that.
          if (baseUriForJsModules == null) {
            baseUriForJsModules = job.getBaseUri();
          }
          it.remove();
          break;
        case JS:
          if (env.placeholderId != null) {
            js.add(new ScriptPlaceholder(env, env.job.getRoot()));
            it.remove();
          }
          break;
        default: break;
      }
    }

    // TODO(ihab.awad): We do *not* want to support multiple HTML files
    // being cajoled at once since this can be mis-used for modularity
    // and we set up expectations on the part of our users to
    // maintain this behavior, regardless of whatever complexity that
    // might entail.

    MessageQueue mq = jobs.getMessageQueue();

    TemplateSanitizer ts = new TemplateSanitizer(htmlSchema, mq);
    for (IhtmlRoot ihtmlRoot : html) {
      ts.sanitize(ihtmlRoot.root);
    }

    TemplateCompiler tc = new TemplateCompiler(
        html, css, js, cssSchema, htmlSchema,
        jobs.getPluginMeta(), jobs.getMessageContext(), mq);
    Pair<List<SafeHtmlChunk>, List<SafeJsChunk>> htmlAndJs = tc.getSafeHtml(
        DomParser.makeDocument(null, null));

    for (SafeHtmlChunk outputHtml : htmlAndJs.a) {
      Job outJob = makeJobFromHtml(outputHtml.root, outputHtml.baseUri);
      if (outJob != null) {
        jobs.getJobs().add(outputHtml.source.withJob(outJob));
      }
    }

View Full Code Here


    MessageQueue mq = jobs.getMessageQueue();
    for (ListIterator<JobEnvelope> it = jobs.getJobs().listIterator();
         it.hasNext();) {
      JobEnvelope env = it.next();
      if (env.fromCache) { continue; }
      Job job = env.job;
      if (job.getType() != ContentType.HTML) { continue; }
      Dom dom = (Dom) job.getRoot();
      Node node = dom.getValue();
      URI baseUri = baseUri(node, job.getBaseUri(), dom.getFilePosition());
      if (baseUri != null) {
        try {
          baseUri = URI.create(UriUtil.normalizeUri(baseUri.toString()));
        } catch (URISyntaxException ex) {
          mq.addMessage(
View Full Code Here

*/
public final class RewriteCssStage implements Pipeline.Stage<Jobs> {
  public boolean apply(Jobs jobs) {
    for (JobEnvelope env : jobs.getJobsByType(ContentType.CSS)) {
      if (env.fromCache) { continue; }
      Job job = env.job;

      new CssDynamicExpressionRewriter(jobs.getPluginMeta()).rewriteCss(
          (CssTree.StyleSheet) job.getRoot());
    }
    return jobs.hasNoFatalErrors();
  }
View Full Code Here

    for (ListIterator<JobEnvelope> it = jobs.getJobs().listIterator();
         it.hasNext();) {
      JobEnvelope env = it.next();

      if (env.fromCache) { continue; }
      Job job = env.job;
      if (job.getType() != ContentType.JS) { continue; }

      URI baseUri = job.getBaseUri();
      Statement s = (Statement) job.getRoot();
      ParseTreeNode result = new ExpressionSanitizerCaja(mgr, baseUri)
          .sanitize(UncajoledModule.of(s));
      if (!(result instanceof CajoledModule)) {
        // Rewriter failed to rewrite so returned its input.
        // There should be details on the message queue.
View Full Code Here

      // we lookup pre-optimized version of JS jobs from the cache.
      if (env.fromCache || env.job.getType() != ContentType.JS
          || env.job.getRoot().getAttributes().is(JobCache.NO_CACHE)) {
        continue;
      }
      Job job = env.job;
      JobCache.Key key = cache.forJob(job.getType(), job.getRoot());
      List<? extends Job> fromCache = cache.fetch(key);
      if (fromCache != null) {
        System.out.println("jobcache hit " + key);
        it.remove();
        for (Job cacheJob : fromCache) {
View Full Code Here

* @author mikesamuel@gmail.com (Mike Samuel)
*/
public class InlineCssImportsStage implements Pipeline.Stage<Jobs> {
  public boolean apply(Jobs jobs) {
    for (JobEnvelope env : jobs.getJobsByType(ContentType.CSS)) {
      Job job = env.job;
      if (env.fromCache) { continue; }
      inlineImports((CssTree.StyleSheet) job.getRoot(),
                    job.getBaseUri(), MAXIMUM_IMPORT_DEPTH,
                    jobs.getPluginMeta().getUriFetcher(),
                    jobs.getMessageQueue());
    }
    return jobs.hasNoErrors();
  }
View Full Code Here

      parent.appendChild(placeholder);
    } else {
      parent.replaceChild(placeholder, el);
    }

    Job job = Job.cajoledJob(pre);
    jobs.getJobs().add(
        new JobEnvelope(id, JobCache.none(), ContentType.JS, true, job));
  }
View Full Code Here

    List<ScriptPlaceholder> js = Lists.newArrayList();
    URI baseUriForJsModules = null;

    for (Iterator<JobEnvelope> it = jobs.getJobs().iterator(); it.hasNext();) {
      JobEnvelope env = it.next();
      Job job = env.job;
      switch (env.sourceType) {
        case CSS:
          if (!env.fromCache) {
            css.add(new ValidatedStylesheet(
                env, (CssTree.StyleSheet) job.getRoot(), job.getBaseUri()));
            it.remove();
          }
          break;
        case HTML:
          html.add(new IhtmlRoot(
              env, ((Dom) job.getRoot()).getValue(), job.getBaseUri()));
          // Module loading in embedded <script>s should use the URI of the
          // HTML file as the base URI. We use a heuristic that there's only
          // one HTML file per compilation task, and use the URI of that.
          if (baseUriForJsModules == null) {
            baseUriForJsModules = job.getBaseUri();
          }
          it.remove();
          break;
        case JS:
          if (env.placeholderId != null) {
            js.add(new ScriptPlaceholder(env, env.job.getRoot()));
            it.remove();
          }
          break;
        default: break;
      }
    }

    // TODO(ihab.awad): We do *not* want to support multiple HTML files
    // being cajoled at once since this can be mis-used for modularity
    // and we set up expectations on the part of our users to
    // maintain this behavior, regardless of whatever complexity that
    // might entail.

    MessageQueue mq = jobs.getMessageQueue();

    TemplateSanitizer ts = new TemplateSanitizer(htmlSchema, mq);
    for (IhtmlRoot ihtmlRoot : html) {
      ts.sanitize(ihtmlRoot.root);
    }

    TemplateCompiler tc = new TemplateCompiler(
        html, css, js, cssSchema, htmlSchema,
        jobs.getPluginMeta(), jobs.getMessageContext(), mq);
    Pair<List<SafeHtmlChunk>, List<SafeJsChunk>> htmlAndJs = tc.getSafeHtml(
        DomParser.makeDocument(null, null));

    for (SafeHtmlChunk outputHtml : htmlAndJs.a) {
      Job outJob = makeJobFromHtml(outputHtml.root, outputHtml.baseUri);
      if (outJob != null) {
        jobs.getJobs().add(outputHtml.source.withJob(outJob));
      }
    }

View Full Code Here

        && discardBoilerPlate(jobs);
  }

  private boolean discardBoilerPlate(Jobs jobs) {
    for (JobEnvelope env : jobs.getJobsByType(ContentType.JS)) {
      Job job = env.job;
      if (job.getRoot() instanceof CajoledModule) {
        jobs.getJobs().remove(env);
        ObjectConstructor cs = ((CajoledModule) job.getRoot()).getModuleBody();
        FunctionConstructor instantiate = (FunctionConstructor)
            ((ValueProperty) cs.propertyWithName("instantiate")).getValueExpr();
        jobs.getJobs().add(
            JobEnvelope.of(Job.jsJob(instantiate.getBody(), null)));
      }
View Full Code Here

TOP

Related Classes of com.google.caja.plugin.Job

Copyright © 2018 www.massapicom. 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.