Package com.google.caja.lexer

Examples of com.google.caja.lexer.HtmlLexer


  public DocumentFragment substitute(
      Document sourceDoc, final PlaceholderHandler handler)
      throws ParseException {
    if (this.tokens == null) {
      List<Token<HtmlTokenType>> toks = new ArrayList<Token<HtmlTokenType>>();
      HtmlLexer lexer = new HtmlLexer(CharProducer.Factory.create(
          new StringReader(xhtml), pos));
      lexer.setTreatedAsXml(true);
      while (lexer.hasNext()) {
        toks.add(lexer.next());
      }
      this.tokens = toks;
    }
    // stitch together tokens from this.tokens with those from placeholders.
    TokenStream<HtmlTokenType> str = new TokenStream<HtmlTokenType>() {
View Full Code Here


                } else if (placeholderName.equals("endLink")) {
                  subst = "</button><br clear=\"all\" />";
                } else {
                  throw new IllegalArgumentException();
                }
                final HtmlLexer tokens = new HtmlLexer(
                    CharProducer.Factory.fromString(subst, is));
                return new Iterator<Token<HtmlTokenType>>() {
                  public boolean hasNext() {
                    try {
                      return tokens.hasNext();
                    } catch (ParseException ex) {
                      throw new SomethingWidgyHappenedError(ex);
                    }
                  }

                  public Token<HtmlTokenType> next() {
                    try {
                      return tokens.next();
                    } catch (ParseException ex) {
                      throw new SomethingWidgyHappenedError(ex);
                    }
                  }
View Full Code Here

    tq.expectEmpty();
    return t;
  }

  protected Element markup(CharProducer cp) throws ParseException {
    return new DomParser(new HtmlLexer(cp), false, sourceOf(cp), mq)
        .parseDocument();
  }
View Full Code Here

        .parseDocument();
  }

  protected DocumentFragment markupFragment(CharProducer cp)
      throws ParseException {
    return new DomParser(new HtmlLexer(cp), false, sourceOf(cp), mq)
        .parseFragment();
  }
View Full Code Here

    CharProducer testInput = fromResource("amazon.com.html");
    InputSource is = testInput.getSourceBreaks(0).source();
    MessageQueue mq = DevNullMessageQueue.singleton();
    long t0 = System.nanoTime();
    for (int i = nRuns; --i >= 0;) {
      HtmlLexer lexer = new HtmlLexer(testInput.clone());
      lexer.setTreatedAsXml(false);
      TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
          lexer, is, DomParser.SKIP_COMMENTS);
      DomParser p = new DomParser(tq, false, mq);
      p.setNeedsDebugData(false);
      p.parseDocument();
View Full Code Here

    if (asXml != null) {  // specified
      TokenQueue<HtmlTokenType> tq = tokenizeTestInput(
          Join.join("\n", htmlInput), asXml, wantsComments);
      p = new DomParser(tq, asXml, mq);
    } else {
      HtmlLexer lexer = new HtmlLexer(fromString(Join.join("\n", htmlInput)));
      p = new DomParser(lexer, wantsComments, is, mq);
      asXml = lexer.getTreatedAsXml();
    }
    Node tree = fragment ? p.parseFragment() : p.parseDocument();

    List<String> actualParseTree = formatLines(tree);
    MoreAsserts.assertListsEqual(expectedParseTree, actualParseTree);
View Full Code Here

    InputSource is = new InputSource(uri);
    CharProducer cp = CharProducer.Factory.fromString(input, is);
    boolean okToContinue = true;
    Dom inputNode = null;
    try {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      inputNode = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    } catch (ParseException e) {
      mq.addMessage(e.getCajaMessage());
      okToContinue = false;
View Full Code Here

   */
  public static TokenQueue<HtmlTokenType> makeTokenQueue(
      FilePosition pos, Reader in, boolean asXml, boolean wantsComments)
      throws IOException {
    CharProducer cp = CharProducer.Factory.create(in, pos);
    HtmlLexer lexer = new HtmlLexer(cp);
    lexer.setTreatedAsXml(asXml);
    return new TokenQueue<HtmlTokenType>(
        lexer, pos.source(),
        wantsComments
            ? Criterion.Factory.<Token<HtmlTokenType>>optimist()
            : SKIP_COMMENTS);
View Full Code Here

  }

  private Node parseMarkup(CharProducer cp, boolean asXml, boolean asDoc)
      throws ParseException {
    InputSource is = sourceOf(cp);
    HtmlLexer lexer = new HtmlLexer(cp);
    lexer.setTreatedAsXml(asXml);
    TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
        lexer, is, DomParser.SKIP_COMMENTS);
    DomParser p = new DomParser(tq, asXml, mq);
    Node t = asDoc ? p.parseDocument() : p.parseFragment();
    tq.expectEmpty();
View Full Code Here

TOP

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

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.