Package com.google.caja.plugin

Examples of com.google.caja.plugin.JobEnvelope


  public boolean apply(Jobs jobs) {
    Multimap<JobCache.Key, Job> byKey = Multimaps.newListHashMultimap();
    for (ListIterator<JobEnvelope> it = jobs.getJobs().listIterator();
         it.hasNext();) {
      JobEnvelope env = it.next();
      if (!env.fromCache) {
        for (JobCache.Key key : env.cacheKeys) {
          byKey.put(key, env.job);
        }
      }
      // Reset the fromCache marker, since any job that came from the cache is
      // now at the same level of processing as any jobs that did not come from
      // the cache; and release any cache keys for GC.
      if (env.fromCache || env.cacheKeys.iterator().hasNext()) {
        it.set(new JobEnvelope(
            env.placeholderId, JobCache.none(), env.sourceType, false,
            env.job));
      }
    }
    for (JobCache.Key key : byKey.keySet()) {
View Full Code Here


  public boolean apply(Jobs jobs) {
    Map<String, JobCache.Keys> keys = Maps.newHashMap();
    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.
        it.remove();
        continue;
      }
      CajoledModule validated = (CajoledModule) result;
      it.set(env.withJob(Job.cajoledJob(validated)));

      if (env.cacheKeys.iterator().hasNext()) {
        ArrayConstructor deps = validated.getInlinedModules();
        if (deps != null) {
          for (Expression moduleName : deps.children()) {
View Full Code Here

  }

  public boolean apply(Jobs jobs) {
    for (ListIterator<JobEnvelope> it = jobs.getJobs().listIterator();
         it.hasNext();) {
      JobEnvelope env = it.next();
      // The JS optimization stage is the computationally expensive stage, so
      // 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) {
          JobEnvelope replacement = new JobEnvelope(
              // Use the placeholder from the original.
              // Placeholders are not part of the cache.
              env.placeholderId,
              // For cached jobs, we don't need a key since we're not going to
              // put them back.
              env.cacheKeys,
              // The source type from the original.
              env.sourceType,
              // It came from the cache.
              true,
              // The cache is responsible for returning a copy that we can
              // mutate.
              cacheJob);
          it.add(replacement);
        }
      } else {
        it.set(new JobEnvelope(
            env.placeholderId, key.asSingleton(), env.sourceType, false, job));
      }
    }
    return jobs.hasNoFatalErrors();
  }
View Full Code Here

      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<ValidatedStylesheet> css = Lists.newArrayList();
    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(
View Full Code Here

      List<ValidatedStylesheet> cssOut,
      List<ScriptPlaceholder> extractedScripts)
      throws ParseException {
    n = extractScripts(n, extractedScripts);
    htmlOut.add(new IhtmlRoot(
        new JobEnvelope(null, JobCache.none(), ContentType.HTML, false, null),
        n, baseUri));
    extractStyles(n, cssOut);
  }
View Full Code Here

      }
      FilePosition pos = Nodes.getFilePositionFor(n);
      String text = n.getFirstChild().getNodeValue();
      Block js = js(fromString(text, pos));
      extractedScripts.add(new ScriptPlaceholder(
          new JobEnvelope(id, JobCache.none(), ContentType.JS, false, null),
          js));
      Nodes.setFilePositionFor(placeholder, Nodes.getFilePositionFor(n));
      return placeholder;
    }
    for (Node child : Nodes.childrenOf(n)) {
View Full Code Here

        CssDynamicExpressionRewriter rrw =
            new CssDynamicExpressionRewriter(meta);
        rrw.rewriteCss(css);
        assertMessagesLessSevereThan(MessageLevel.ERROR);
        styles.add(new ValidatedStylesheet(
            new JobEnvelope(
                null, JobCache.none(), ContentType.CSS, false, null),
            css, is.getUri()));
      }
      n.getParentNode().removeChild(n);
      return;
View Full Code Here

TOP

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

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.