Package com.google.caja.lexer

Examples of com.google.caja.lexer.CharProducer


    compiler.setMessageContext(mc);

    // Parse the javascript
    try {
      StringReader strReader = new StringReader(resp.getContent());
      CharProducer cp = CharProducer.Factory.create(strReader, is);
      JsTokenQueue tq = new JsTokenQueue(new JsLexer(cp), is);
      ParseTreeNode input = new Parser(tq, mq).parse();
      tq.expectEmpty();

      compiler.addInput(AncestorChain.instance(input).node, contextUri.toJavaUri());
View Full Code Here


      UriFetcher fetcher = makeFetcher(uri, container);
      ExternalReference extRef = new ExternalReference(javaUri,
          FilePosition.instance(is, /*lineNo*/ 1, /*charInFile*/ 1, /*charInLine*/ 1));
      // If the fetch fails, a UriFetchException is thrown and serialized as part of the
      // message queue.
      CharProducer cp = fetcher.fetch(extRef, mime).getTextualContent();
      ParseTreeNode ptn = parse(is, cp, mime, mq);
      return rewrite(uri, container, ptn, es53, debug);
    } catch (UnsupportedEncodingException e) {
      LOG.severe("Unexpected inability to recognize mime type: " + mime);
      mq.addMessage(ServiceMessageType.UNEXPECTED_INPUT_MIME_TYPE,
View Full Code Here

      BuildInfo bi = BuildInfo.getInstance();
      DefaultGadgetRewriter rw = new DefaultGadgetRewriter(bi, mq);
      rw.setValijaMode(true);
      InputSource is = new InputSource(retrievedUri);
      String origContent = content.getContent();
      CharProducer input = CharProducer.Factory.create(
          new StringReader(origContent),
          FilePosition.instance(is, 5, 5, 5));
      StringBuilder output = new StringBuilder();

      // Secure default to remove content in case there
View Full Code Here

    return parsedCss;
  }

  private CssTree.StyleSheet parseImpl(String css) throws ParseException {
    InputSource inputSource = new InputSource(FAKE_SOURCE);
    CharProducer producer = CharProducer.Factory.create(new StringReader(css),
        inputSource);
    TokenStream<CssTokenType> lexer = new CssLexer(producer);
    TokenQueue<CssTokenType> queue = new TokenQueue<CssTokenType>(lexer, inputSource,
        new Criterion<Token<CssTokenType>>() {
          public boolean accept(Token<CssTokenType> t) {
View Full Code Here

    return parsedCss;
  }

  List<Object> parseImpl(String content) throws GadgetException {
    List<Object> parsedCss = Lists.newArrayList();
    CharProducer producer = CharProducer.Factory.create(new StringReader(content),
        new InputSource(DUMMY_SOURCE));
    CssLexer lexer = new CssLexer(producer);
    try {
      StringBuilder builder = new StringBuilder();
      boolean inImport = false;
View Full Code Here

    return parsedCss;
  }

  private CssTree.StyleSheet parseImpl(String css) throws ParseException {
    InputSource inputSource = new InputSource(FAKE_SOURCE);
    CharProducer producer = CharProducer.Factory.create(new StringReader(css),
        inputSource);
    TokenStream<CssTokenType> lexer = new CssLexer(producer);
    TokenQueue<CssTokenType> queue = new TokenQueue<CssTokenType>(lexer, inputSource,
        new Criterion<Token<CssTokenType>>() {
          public boolean accept(Token<CssTokenType> t) {
View Full Code Here

    return parsedCss;
  }

  List<Object> parseImpl(String content) throws GadgetException {
    List<Object> parsedCss = Lists.newArrayList();
    CharProducer producer = CharProducer.Factory.create(new StringReader(content),
        new InputSource(DUMMY_SOURCE));
    CssLexer lexer = new CssLexer(producer);
    try {
      StringBuilder builder = new StringBuilder();
      boolean inImport = false;
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

    System.out.println(
        " VarZ:" + getClass().getName() + ".msPerRun=" + microsPerRun);
  }

  private int benchmark(int nRuns) throws IOException, ParseException {
    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);
View Full Code Here

        }
      }
    }
    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;
      InputSource isrc = scriptBody.getSourceBreaks(0).source();
      // 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, isrc));
      mc.addInputSource(isrc);
      script.getParentNode().removeChild(script);
    }
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.