Package com.google.caja.lexer

Examples of com.google.caja.lexer.CharProducer


             html.getElementsByTagNameNS(HTML_NS, "script"), Element.class)) {
      scripts.add(script);
    }
    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;
      Block js = parseJavascript(scriptBody, mq);
      // 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);
      scriptContent.add(Pair.pair(scriptText, js.getFilePosition().source()));
      mc.addInputSource(js.getFilePosition().source());
      script.getParentNode().removeChild(script);
    }
View Full Code Here


      FilePosition childPos = Nodes.getFilePositionFor(child);
      switch (child.getNodeType()) {
        case Node.TEXT_NODE:
          String rawText = Nodes.getRawText((Text) child);
          String decodedText = child.getNodeValue();
          CharProducer cp = null;
          if (rawText != null) {
            cp = CharProducer.Factory.fromHtmlAttribute(
                CharProducer.Factory.create(
                    new StringReader(rawText), childPos));
            if (!String.valueOf(cp.getBuffer(), cp.getOffset(), cp.getLength())
                .equals(decodedText)) {  // XHTML
              cp = null;
            }
          }
          if (cp == null) {
View Full Code Here

        HtmlSchema.getDefault(mq), is.getUri(), mq, mc);
    Iterator<EmbeddedContent> iterator = f.findEmbeddedContent(
        htmlFragment(fromString(htmlText))).iterator();
    assertTrue(iterator.hasNext());
    EmbeddedContent content = iterator.next();
    CharProducer cp = content.getContent(UriFetcher.NULL_NETWORK);
    FilePosition pos = content.getPosition();
    assertEquals(" foo() ", cp.toString());
    assertEquals("testFilePositionOfAttrib:1+13@13 - 20@20", pos.toString());
    assertFalse(iterator.hasNext());
  }
View Full Code Here

        HtmlSchema.getDefault(mq), is.getUri(), mq, mc);
    Iterator<EmbeddedContent> iterator = f.findEmbeddedContent(
        htmlFragment(fromString(htmlText))).iterator();
    assertTrue(iterator.hasNext());
    EmbeddedContent content = iterator.next();
    CharProducer cp = content.getContent(UriFetcher.NULL_NETWORK);
    FilePosition pos = content.getPosition();
    //            'javascript:foo()'
    assertEquals("            foo() ", cp.toString());
    assertEquals("testFilePositionOfJsUrl:1+9@9 - 27@27", pos.toString());
    assertFalse(iterator.hasNext());
  }
View Full Code Here

   * @throws IOException when in raises an exception during read.
   */
  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
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.