Package com.google.caja.parser.html

Examples of com.google.caja.parser.html.DomParser.parseFragment()


      Parser p = new Parser(tq, mq);
      ptn = p.parse();
      tq.expectEmpty();
    } else {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      ptn = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    }
    return ptn;
  }
View Full Code Here


  protected DocumentFragment parseFragmentImpl(String source)
      throws GadgetException {
    try {
      MessageQueue mq = makeMessageQueue();
      DomParser parser = getDomParser(source, mq);
      DocumentFragment fragment = parser.parseFragment();
      if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
        StringBuilder err = new StringBuilder();
        for (Message m : mq.getMessages()) {
          err.append(m.toString()).append("\n");
        }
View Full Code Here

    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();
    return t;
  }

  protected Element markup(CharProducer cp) throws ParseException {
View Full Code Here

      Parser p = new Parser(tq, mq);
      ptn = p.parse();
      tq.expectEmpty();
    } else {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      ptn = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    }
    return ptn;
  }
View Full Code Here

      throws GadgetException {
    try {
      MessageQueue mq = makeMessageQueue();

      DomParser parser = getDomParser(source, mq);
      DocumentFragment fragment = parser.parseFragment();

      if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
        StringBuilder err = new StringBuilder();
        for (Message m : mq.getMessages()) {
          err.append(m.toString()).append('\n');
View Full Code Here

      Parser p = new Parser(tq, mq);
      ptn = p.parse();
      tq.expectEmpty();
    } else {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      ptn = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    }
    return ptn;
  }
View Full Code Here

      Parser p = new Parser(tq, mq);
      ptn = p.parse();
      tq.expectEmpty();
    } else {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      ptn = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    }
    return ptn;
  }
View Full Code Here

      throws GadgetException {
    try {
      MessageQueue mq = makeMessageQueue();

      DomParser parser = getDomParser(source, mq);
      DocumentFragment fragment = parser.parseFragment();

      if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
        StringBuilder err = new StringBuilder();
        for (Message m : mq.getMessages()) {
          err.append(m.toString()).append('\n');
View Full Code Here

  }

  DomTree.Fragment getFragment(String content) throws GadgetException {
    DomParser parser = getParser(content);
    try {
      return parser.parseFragment();
    } catch (ParseException pe) {
      try {
        // Revert to nastiness
        DomTree.Fragment fragment = getParser("<HTML>" + content + "</HTML>").parseFragment();
        return new DomTree.Fragment(fragment.children().get(0).children());
View Full Code Here

      MessageQueue mq = makeMessageQueue();
      // Newline works around Caja parser issue with certain short-form
      // HTML - the internal Lexer gets confused. A bug has been filed w/ Caja.
      // Even so, adding the newline is innocuous for any HTML.
      DomParser parser = getDomParser(source + '\n', mq);
      DocumentFragment fragment = parser.parseFragment();
      // Get rid of the newline, if maintained.
      Node lastChild = fragment != null ? fragment.getLastChild() : null;
      if (lastChild != null && lastChild.getNodeType() == Node.TEXT_NODE) {
        String lastText = lastChild.getTextContent();
        if ("\n".equals(lastText)) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.