Package com.google.caja.parser.html

Examples of com.google.caja.parser.html.DomParser


    try {
      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


  private DomParser getDomParser(String source, final MessageQueue mq) throws ParseException {
    InputSource is = getInputSource();
    HtmlLexer lexer = new HtmlLexer(CharProducer.Factory.fromString(source, is));
    final Namespaces ns = Namespaces.HTML_DEFAULT;  // Includes OpenSocial
    final boolean needsDebugData = needsDebugData();
    DomParser parser = new DomParser(lexer, /* wantsComments */ true, is, ns, mq);
    parser.setDomImpl(documentFactory);
    parser.setNeedsDebugData(needsDebugData);
    return parser;
  }
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 = Dom.transplant(p.parseDocument());
      p.getTokenQueue().expectEmpty();
    } catch (ParseException e) {
      mq.addMessage(e.getCajaMessage());
      okToContinue = false;
    }
View Full Code Here

      CssParser p = new CssParser(tq, mq, MessageLevel.WARNING);
      input = p.parseStyleSheet();
      tq.expectEmpty();
    } else if (ContentType.HTML == type) {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      //if (p.getTokenQueue().isEmpty()) { return null; }
      input = Dom.transplant(p.parseDocument());
      p.getTokenQueue().expectEmpty();
    } else {
      throw new SomethingWidgyHappenedError("Can't classify input " + is);
    }
    return input;
View Full Code Here

      CssParser p = new CssParser(tq, mq, MessageLevel.WARNING);
      input = p.parseStyleSheet();
      tq.expectEmpty();
    } else if (ContentType.HTML == type) {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      //if (p.getTokenQueue().isEmpty()) { return null; }
      input = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    } else {
      throw new SomethingWidgyHappenedError("Can't classify input " + is);
    }
    return input;
View Full Code Here

      }
    };
    TokenQueue<HtmlTokenType> tq = new TokenQueue<HtmlTokenType>(
        str, pos.source(), DomParser.SKIP_COMMENTS);
    tq.setInputRange(pos);
    return new DomParser(
        tq, true, DevNullMessageQueue.singleton()).parseFragment(sourceDoc);
  }
View Full Code Here

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

  }

  private void runTest(
      String goldenIhtml, String inputIhtml, Message... expectedMessages)
      throws Exception {
    Element ihtmlRoot = new DomParser(
        DomParser.makeTokenQueue(
            FilePosition.startOfFile(is), new StringReader(inputIhtml), true,
            false),
        true, mq)
        .parseDocument();
View Full Code Here

TOP

Related Classes of com.google.caja.parser.html.DomParser

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.