Package com.google.caja.lexer

Examples of com.google.caja.lexer.InputSource


      assertTrue(e instanceof IllegalStateException);
    }
  }

  public final void testContentCache() throws Exception {
    InputSource is = new InputSource(URI.create("test:///foo.js"));
    Map<InputSource, CharSequence> sourceMap = Maps.newHashMap();
    @SuppressWarnings("unused")
    ParseTreeNode node = new ParserContext(DevNullMessageQueue.singleton())
      .withSourceMap(sourceMap)
      .withInput(is)
View Full Code Here


    for (Element script : scripts) {
      Attr src = script.getAttributeNodeNS(HTML_NS, "src");
      CharProducer scriptBody;
      if (src != null) {
        String resourcePath = src.getNodeValue();
        InputSource resource;
        if (resourcePath.startsWith("/")) {
          try {
            resource = new InputSource(
                RhinoTestBed.class.getResource(resourcePath).toURI());
          } catch (URISyntaxException ex) {
            throw new SomethingWidgyHappenedError(
                "java.net.URL is not a valid java.net.URI", ex);
          }
        } else {
          InputSource baseUri = Nodes.getFilePositionFor(html).source();
          resource = new InputSource(baseUri.getUri().resolve(resourcePath));
        }
        scriptBody = loadResource(resource);
      } else {
        scriptBody = textContentOf(script);
      }
      String scriptText;
      InputSource isrc = scriptBody.getSourceBreaks(0).source();
      // Add blank lines at the front so that Rhino stack traces have correct
      // line numbers.
      scriptText = prefixWithBlankLines(
        scriptBody.toString(0, scriptBody.getLimit()),
        Nodes.getFilePositionFor(script).startLineNo() - 1);
View Full Code Here

*/
@SuppressWarnings("static-method")
public class QuasiBuilderTest extends CajaTestCase {
  public final void testParseDoesNotFail() throws Exception {
    QuasiNode n = QuasiBuilder.parseQuasiNode(
        new InputSource(URI.create("built-in:///js-quasi-literals")),
        "function @a() { @b.@c = @d; @e = @f; }");
    assertTrue(n instanceof SimpleQuasiNode);
  }
View Full Code Here

    return FetchedData.fromBytes(
        intermediateResponse.toByteArray(),
        contentInfo.a,
        contentInfo.b,
        new InputSource(inputUri));
  }
View Full Code Here

    UriFetcher fetcher = new UriFetcher() {
        public FetchedData fetch(ExternalReference ref, String mimeType)
            throws UriFetchException {
          URI uri = ref.getUri();
          uri = ref.getReferencePosition().source().getUri().resolve(uri);
          InputSource is = new InputSource(uri);

          try {
            if (!canonFiles.contains(new File(uri).getCanonicalFile())) {
              throw new UriFetchException(ref, mimeType);
            }
          } catch (IllegalArgumentException ex) {
            throw new UriFetchException(ref, mimeType, ex);
          } catch (IOException ex) {
            throw new UriFetchException(ref, mimeType, ex);
          }

          try {
            String content = getSourceContent(is);
            if (content == null) {
              throw new UriFetchException(ref, mimeType);
            }
            return FetchedData.fromCharProducer(
                CharProducer.Factory.fromString(content, is),
                mimeType, Charsets.UTF_8.name());
          } catch (IOException ex) {
            throw new UriFetchException(ref, mimeType, ex);
          }
        }
      };

    UriPolicy policy;
    final UriPolicy prePolicy = new UriPolicy() {
      public String rewriteUri(
          ExternalReference u, UriEffect effect, LoaderType loader,
          Map<String, ?> hints) {
        // TODO(ihab.awad): Need to pass in the URI rewriter from the build
        // file somehow (as a Cajita program?). The below is a stub.
        return URI.create(
            "http://example.com/"
            + "?effect=" + effect + "&loader=" + loader
            + "&uri=" + UriUtil.encode("" + u.getUri()))
            .toString();
      }
    };
    final Set<?> lUrls = (Set<?>) options.get("canLink");
    if (!lUrls.isEmpty()) {
      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);
        }
      };
    } else {
      policy = prePolicy;
    }

    MessageContext mc = new MessageContext();

    String language = (String) options.get("language");
    String rendererType = (String) options.get("renderer");

    if ("javascript".equals(language) && "concat".equals(rendererType)) {
      return concat(inputs, output, logger);
    }

    boolean passed = true;
    ParseTreeNode outputJs;
    if ("caja".equals(language)) {
      throw new IllegalArgumentException("language=caja no longer supported");
    } else if ("javascript".equals(language)) {
      PluginMeta meta = new PluginMeta(fetcher, policy);
      passed = true;
      JsOptimizer optimizer = new JsOptimizer(mq);
      for (File f : inputs) {
        try {
          if (f.getName().endsWith(".env.json")) {
            loadEnvJsonFile(f, optimizer, mq);
          } else {
            ParseTreeNode parsedInput = new ParserContext(mq)
            .withInput(new InputSource(f.getCanonicalFile().toURI()))
            .withConfig(meta)
            .build();
            if (parsedInput != null) {
              optimizer.addInput((Statement) parsedInput);
            }
View Full Code Here

      Map<String, Object> options) {
    try {
      List<Pair<InputSource, File>> inputSources = Lists.newArrayList();
      for (File f : inputs) {
        inputSources.add(
            Pair.pair(new InputSource(f.getAbsoluteFile().toURI()), f));
      }
      Writer outputWriter = new OutputStreamWriter(
          new FileOutputStream(output), Charsets.UTF_8);
      try {
        return Minify.minify(inputSources, outputWriter, logger);
View Full Code Here

    // Parse each input, and find annotations.
    for (File inp : inputs) {
      CharProducer cp = CharProducer.Factory.fromFile(inp, "UTF-8");
      if (cp.isEmpty()) { continue; }

      InputSource src = cp.getCurrentPosition().source();
      mc.addInputSource(src);
      contents.put(src, new FileContent(cp));

      JsTokenQueue tq = new JsTokenQueue(new JsLexer(cp), src);
      try {
View Full Code Here

    }
    return compUnits;
  }

  public static LintJob makeLintJob(Block program, MessageQueue mq) {
    InputSource src = program.getFilePosition().source();
    List<Token<?>> tokens = program.getComments();
    return new LintJob(
        src,
        parseIdentifierListFromComment("requires", tokens, mq),
        parseIdentifierListFromComment("provides", tokens, mq),
View Full Code Here

    }
    // Check that two files do not provide the same thing.
    Map<String, InputSource> providedBy = Maps.newHashMap();
    for (LintJob job : jobs) {
      for (String symbolName : job.provides) {
        InputSource originallyDefinedIn = providedBy.put(symbolName, job.src);
        if (originallyDefinedIn != null) {
          mq.addMessage(
              LinterMessageType.MULTIPLY_PROVIDED_SYMBOL,
              job.src, originallyDefinedIn,
              MessagePart.Factory.valueOf(symbolName));
View Full Code Here

  public FetchedData fetch(ExternalReference ref, String mimeType)
      throws UriFetchException {
    byte[] raw = fetchBinary(ref, mimeType);
    return FetchedData.fromBytes(raw, mimeType,
        charsetFromMime(mimeType), new InputSource(ref.getUri()));
  }
View Full Code Here

TOP

Related Classes of com.google.caja.lexer.InputSource

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.