Package com.google.caja.reporting

Examples of com.google.caja.reporting.MessageContext


  public String toStringDeep() { return toStringDeep(0); }

  public String toStringDeep(int d) {
    StringBuilder sb = new StringBuilder();
    try {
      formatTree(new MessageContext(), d, sb);
    } catch (IOException ex) {
      throw new SomethingWidgyHappenedError(
          "StringBuilders shouldn't throw IOExceptions");
    }
    return sb.toString();
View Full Code Here


  /** debugging */
  private static String dump(ParseTreeNode node) {
    check(node);
    StringBuilder sb = new StringBuilder();
    MessageContext mc = new MessageContext();
    mc.relevantKeys
        = Collections.<SyntheticAttributeKey<Integer>>singleton(NUM);
    try {
      node.formatTree(mc, 2, sb);
    } catch (java.io.IOException ex) {
View Full Code Here

  // TODO(jasvir): The service like the gwt version should accumulate
  // input sources and use html snippet producer to produce messages
  private static String serializeMessageQueue(MessageQueue mq) {
    StringBuilder sb = new StringBuilder();
    MessageContext mc = new MessageContext();
    for (Message m : mq.getMessages()) {
      sb.append(m.getMessageLevel().name()).append(": ");
      Escaping.escapeXml(m.format(mc), false, sb);
      sb.append("\n");
    }
View Full Code Here

    }
  }

  private PluginCompilerMain() {
    mq = new SimpleMessageQueue();
    mc = new MessageContext();
  }
View Full Code Here

    }
  }

  private int runOnce(boolean writeFiles) {
    boolean success = false;
    MessageContext mc = null;
    CajoledModule compiledJsOutput = null;
    Node compiledDomOutput = null;
    String compiledHtmlOutput = null;
    File fileLimitAncestor = config.getFetcherBase();

    File jsOutputDest = config.getOutputJsFile();
    File htmlOutputDest = config.getOutputHtmlFile();

    try {
      UriFetcher fetcher;
      UriPolicy policy;
      try {
        if (fileLimitAncestor != null) {
          UriToFile u2f = new UriToFile(fileLimitAncestor);
          fetcher = ChainingUriFetcher.make(
              new DataUriFetcher(),
              new CachingUriFetcher(u2f));
          policy = new FileSystemUriPolicy(u2f);
        } else {
          fetcher = new DataUriFetcher();
          policy = UriPolicy.DENY_ALL;
        }
      } catch (IOException e) {  // Could not resolve file name
        fetcher = new DataUriFetcher();
        policy = UriPolicy.DENY_ALL;
      }
      final Set<String> lUrls = config.getLinkableUris();
      if (!lUrls.isEmpty()) {
        final UriPolicy prePolicy = policy;
        policy = new UriPolicy() {
          public String rewriteUri(
              ExternalReference u, UriEffect effect,
              LoaderType loader, Map<String, ?> hints) {
            String uri = u.getUri().toString();
            if (lUrls.contains(uri)) { return uri; }
            return prePolicy.rewriteUri(u, effect, loader, hints);
          }
        };
      }
      final Set<String> fUris = config.getFetchableUris();
      final boolean fUriAll = config.hasFetchableUriAll();
      if (fUriAll || !fUris.isEmpty()) {
        fetcher = ChainingUriFetcher.make(
            fetcher,
            new UriFetcher() {
              public FetchedData fetch(ExternalReference ref, String mimeType)
                  throws UriFetchException {
                String uri = ref.getUri().toString();
                if (!fUriAll && !fUris.contains(uri)) {
                  throw new UriFetchException(ref, mimeType);
                }
                try {
                  return FetchedData.fromConnection(
                      new URL(uri).openConnection());
                } catch (IOException ex) {
                  throw new UriFetchException(ref, mimeType, ex);
                }
              }
            });
      }

      if (config.hasLinkableUriAll()) {
        policy = UriPolicy.IDENTITY;
      } else if (config.hasLinkableUriRuntime()) {
        policy = null;
      }

      PluginMeta meta = new PluginMeta(fetcher, policy);
      meta.setIdClass(config.getIdClass());
      meta.setPrecajoleMinify(
          config.renderer() == Config.SourceRenderMode.MINIFY);
      if (config.hasNoPrecajoled()) {
        meta.setPrecajoleMap(null);
      }

      PluginCompiler compiler = new PluginCompiler(
          BuildInfo.getInstance(), meta, mq);
      compiler.setPreconditions(
          config.preconditions(compiler.getPreconditions()));
      compiler.setGoals(config.goals(compiler.getGoals()));

      mc = compiler.getMessageContext();
      compiler.setCssSchema(config.getCssSchema(mq));
      compiler.setHtmlSchema(config.getHtmlSchema(mq));

      success = parseInputs(meta, config.getInputUris(), compiler)
          && compiler.run();
      if (success) {
        compiledJsOutput = compiler.getJavascript();
        compiledDomOutput = compiler.getStaticHtml();
        compiledHtmlOutput = compiledDomOutput != null ?
            Nodes.render(compiledDomOutput) : "";
      }
    } finally {
      if (mc == null) { mc = new MessageContext(); }
      MessageLevel maxMessageLevel = dumpMessages(mq, mc, System.err);
      success &= MessageLevel.ERROR.compareTo(maxMessageLevel) > 0;
    }

    if (!writeFiles) {
View Full Code Here

  private Planner.PlanState goals;
  private final long t0 = System.nanoTime();

  public PluginCompiler(BuildInfo buildInfo, PluginMeta meta, MessageQueue mq) {
    this.buildInfo = buildInfo;
    this.jobs = new Jobs(new MessageContext(), mq, meta);
    this.cssSchema = CssSchema.getDefaultCss21Schema(mq);
    this.htmlSchema = HtmlSchema.getDefault(mq);
    this.jobCache = new StubJobCache();
    this.preconditions = PipelineMaker.DEFAULT_PRECONDS;
    this.goals = PipelineMaker.DEFAULT_GOALS;
View Full Code Here

      out.append(String.valueOf(this.endCharInLine()));
    }
  }

  public final void formatShort(Appendable out) throws IOException {
    MessageContext mc = new MessageContext();
    InputSource is = source();
    mc.addInputSource(is);
    out.append(mc.abbreviate(is))
        .append(":")
        .append(String.valueOf(this.startLineNo()));
  }
View Full Code Here

   *     that were used to generate the cajoled tokens. File positions in the
   *     'rewrittenFile' refer to positions in these files.
   */
  protected void runTest(String goldenFile, String rewrittenFile,
                         String... originalSourceFiles) throws Exception {
    final MessageContext mc = new MessageContext();

    Map<InputSource, String> originalSrcs = Maps.newHashMap();
    for (String originalSourceFile : originalSourceFiles) {
      URI resourceUri = TestUtil.getResource(getClass(), originalSourceFile);
      if (resourceUri == null) { throw new IOException(originalSourceFile); }
      InputSource is = new InputSource(resourceUri);
      originalSrcs.put(
          is, TestUtil.readResource(getClass(), originalSourceFile));
    }
    for (InputSource is : originalSrcs.keySet()) { mc.addInputSource(is); }

    StringBuilder actual = new StringBuilder();
    RenderContext rc = new RenderContext(new Concatenator(actual));
    TokenConsumer r = createRenderer(originalSrcs, mc, rc);
    for (String line
View Full Code Here

  @Override
  public void setUp() throws Exception {
    super.setUp();
    cssSchema = CssSchema.getDefaultCss21Schema(
        new EchoingMessageQueue(
            new PrintWriter(System.err), new MessageContext()));
  }
View Full Code Here

        // Make sure it shows up in the junit test runner trace.
        System.err.println("junit.seed=" + SEED);
      }
    }
    this.is = new InputSource(URI.create("http://example.org/" + getName()));
    this.mc = new MessageContext();
    mc.addInputSource(is);
    this.mq = TestUtil.createTestMessageQueue(this.mc);
  }
View Full Code Here

TOP

Related Classes of com.google.caja.reporting.MessageContext

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.