Package com.google.caja.lexer

Examples of com.google.caja.lexer.CharProducer


        extRef, scheduling, el, t);
  }

  private EmbeddedContent fromElementBody(
      Element el, ContentType t, EmbeddedContent.Scheduling scheduling) {
    final CharProducer cp = textNodesToCharProducer(el, t == ContentType.JS);
    return new EmbeddedContent(
        this, cp.filePositionForOffsets(0, cp.getLimit()),
        new Function<UriFetcher, CharProducer>() {
          public CharProducer apply(UriFetcher fetcher) { return cp.clone(); }
        },
        null, scheduling, el, t);
  }
View Full Code Here


        this, Nodes.getFilePositionForValue(a),
        new Function<UriFetcher, CharProducer>() {
          CharProducer cp;
          public CharProducer apply(UriFetcher fetcher) {
            if (this.cp == null) {
              CharProducer cp;
              String rawText = rawValue;
              if (rawText != null) {
                int n = rawText.length();
                if (n >= 2) {  // Strip quotes
                  char lastCh = rawText.charAt(n - 1);
View Full Code Here

  public static ParseTreeNode parse(String src) throws Exception {
    MessageContext mc = new MessageContext();
    MessageQueue mq = TestUtil.createTestMessageQueue(mc);
    InputSource is = new InputSource(new URI("file:///no/input/source"));
    CharProducer cp = CharProducer.Factory.create(new StringReader(src), is);
    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, is, JsTokenQueue.NO_COMMENT);
    Parser p = new Parser(tq, mq);
    Statement stmt = p.parse();
    p.getTokenQueue().expectEmpty();
View Full Code Here

   *     content fetching.
   */
  public ParseTreeNode parse(UriFetcher fetcher, MessageQueue mq)
      throws ParseException {
    if (type == null) { return null; // Malformed content
    CharProducer cp = getContent(fetcher);
    FilePosition p = cp.filePositionForOffsets(cp.getOffset(), cp.getLimit());
    switch (type) {
      case JS: {
        Parser parser = finder.makeJsParser(cp, mq);
        if (parser.getTokenQueue().isEmpty()) { return new Block(p); }
        return parser.parse();
View Full Code Here

    if (null != sourceMap && sourceMap.containsKey(is)) {
      return CharProducer.Factory.fromString(sourceMap.get(is), is);
    }

    if (null == stream && null != is) {
      CharProducer candidate = guessCharProducer(is, meta);
      if (null != candidate) {
        return candidate;
      }
    }
View Full Code Here

      throws UriFetchException {
    URI uri = ref.getUri();
    File f = uriToFile.apply(uri);
    if (f == null) { throw new UriFetchException(ref, mimeType); }
    try {
      CharProducer cp = CharProducer.Factory.create(
          newReader(f), new InputSource(uri));
      ContentType ct = GuessContentType.guess(null, f.getName(), cp);
      return FetchedData.fromCharProducer(
          cp, ct != null ? ct.mimeType : "", Charsets.UTF_8.name());
    } catch (IOException ex) {
View Full Code Here

          break;
      }
    }
    if (contentType == null && code != null) {
      // Try and lex and see what happens.
      CharProducer cp = CharProducer.Factory.fromString(
          code, FilePosition.UNKNOWN);
      boolean sawColon = false;
      try {
        CssLexer cssLexer = new CssLexer(
            cp, DevNullMessageQueue.singleton(), false);
View Full Code Here

      return;
    }
    assert absUri != null// because absUri == null  ->  importUrl == null

    // Import it and recursively import its imports
    CharProducer cp;
    try {
      cp = fetcher.fetch(importUrl, "text/css").getTextualContent();
    } catch (UriFetcher.UriFetchException ex) {
      mq.addMessage(PluginMessageType.FAILED_TO_LOAD_EXTERNAL_URL,
                    MessageLevel.ERROR, ex.ref.getReferencePosition(),
View Full Code Here

         "              ^^^^"),
        s.getSnippet(msg));
  }

  public final void testGetSnippetTwoPos() {
    CharProducer cp = CharProducer.Factory.create(
        new StringReader(F1_TEXT), f1);
    cp.consume(cp.length());

    Message msg = new Message(
        TestMessageType.TWO,
        FilePosition.instance(f2, 1, 1, 1, 2),
        // Starts on a newline to test that we use the line with text.
        cp.getSourceBreaks(0).toFilePosition(
            1 + F1_TEXT.indexOf("\r\nf1 line 3"),
            1 + F1_TEXT.indexOf(" line 3"))
        );
    assertEquals(
        ("f2:1: f2      line 1\n" +
View Full Code Here

  private double runCajoledES53(String filename) throws Exception {
    PluginMeta meta = new PluginMeta();
    MessageQueue mq = new SimpleMessageQueue();
    PluginCompiler pc = new PluginCompiler(new TestBuildInfo(), meta, mq);
    CharProducer src = fromString(plain(fromResource(filename)));
    pc.addInput(js(src), is.getUri());

    if (!pc.run()) {
      return -1;
    }
View Full Code Here

TOP

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

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.