Package com.google.gwt.safehtml.rebind.ParsedHtmlTemplate

Examples of com.google.gwt.safehtml.rebind.ParsedHtmlTemplate.ParameterChunk


    assertEquals("[L(<foo>)]", parsed.toString());
  }

  public void testAddParameter() {
    ParsedHtmlTemplate parsed = new ParsedHtmlTemplate();
    parsed.addParameter(new ParameterChunk(new HtmlContext(
        HtmlContext.Type.TEXT), 0));

    List<TemplateChunk> chunks = parsed.getChunks();

    ParameterChunk chunk = (ParameterChunk) chunks.get(0);
    assertEquals(TemplateChunk.Kind.PARAMETER, chunk.getKind());
    assertEquals(HtmlContext.Type.TEXT, chunk.getContext().getType());
    assertNull(chunk.getContext().getTag());
    assertNull(chunk.getContext().getAttribute());
    assertEquals(0, chunk.getParameterIndex());
    assertEquals("P((TEXT,null,null),0)", chunk.toString());

    assertEquals("[P((TEXT,null,null),0)]", parsed.toString());
  }
View Full Code Here


   */
  public void testAddLiteralAddParameterSequence() {
    ParsedHtmlTemplate parsed = new ParsedHtmlTemplate();

    parsed.addLiteral("<foo>");
    parsed.addParameter(new ParameterChunk(new HtmlContext(
        HtmlContext.Type.TEXT), 0));
    parsed.addLiteral("</foo>");

    List<TemplateChunk> chunks = parsed.getChunks();
    assertEquals(3, chunks.size());
    Iterator<TemplateChunk> it = chunks.iterator();

    LiteralChunk litChunk;
    ParameterChunk paramChunk;

    litChunk = (LiteralChunk) it.next();
    assertEquals(TemplateChunk.Kind.LITERAL, litChunk.getKind());
    assertEquals("<foo>", litChunk.getLiteral());
    assertEquals("L(<foo>)", litChunk.toString());

    paramChunk = (ParameterChunk) it.next();
    assertEquals(TemplateChunk.Kind.PARAMETER, paramChunk.getKind());
    assertEquals(HtmlContext.Type.TEXT, paramChunk.getContext().getType());
    assertNull(paramChunk.getContext().getTag());
    assertNull(paramChunk.getContext().getAttribute());
    assertEquals(0, paramChunk.getParameterIndex());
    assertEquals("P((TEXT,null,null),0)", paramChunk.toString());

    litChunk = (LiteralChunk) it.next();
    assertEquals(TemplateChunk.Kind.LITERAL, litChunk.getKind());
    assertEquals("</foo>", litChunk.getLiteral());
    assertEquals("L(</foo>)", litChunk.toString());
View Full Code Here

   * only a single LiteralChunk.
   */
  public void testAddParameterAddLiteralSequence() {
    ParsedHtmlTemplate parsed = new ParsedHtmlTemplate();

    parsed.addParameter(new ParameterChunk(new HtmlContext(
        HtmlContext.Type.TEXT), 0));
    parsed.addLiteral("<a");
    parsed.addLiteral(" href=\"");
    parsed.addParameter(new ParameterChunk(new HtmlContext(
        HtmlContext.Type.URL_ATTRIBUTE_START, "a", "href"), 1));

    List<TemplateChunk> chunks = parsed.getChunks();
    assertEquals(3, chunks.size());
    Iterator<TemplateChunk> it = chunks.iterator();

    LiteralChunk litChunk;
    ParameterChunk paramChunk;

    paramChunk = (ParameterChunk) it.next();
    assertEquals(TemplateChunk.Kind.PARAMETER, paramChunk.getKind());
    assertEquals(HtmlContext.Type.TEXT, paramChunk.getContext().getType());
    assertNull(paramChunk.getContext().getTag());
    assertNull(paramChunk.getContext().getAttribute());
    assertEquals(0, paramChunk.getParameterIndex());
    assertEquals("P((TEXT,null,null),0)", paramChunk.toString());

    litChunk = (LiteralChunk) it.next();
    assertEquals(TemplateChunk.Kind.LITERAL, litChunk.getKind());
    assertEquals("<a href=\"", litChunk.getLiteral());
    assertEquals("L(<a href=\")", litChunk.toString());

    paramChunk = (ParameterChunk) it.next();
    assertEquals(TemplateChunk.Kind.PARAMETER, paramChunk.getKind());
    assertEquals(
        HtmlContext.Type.URL_ATTRIBUTE_START, paramChunk.getContext().getType());
    assertEquals("a", paramChunk.getContext().getTag());
    assertEquals("href", paramChunk.getContext().getAttribute());
    assertEquals(1, paramChunk.getParameterIndex());
    assertEquals("P((URL_ATTRIBUTE_START,a,href),1)", paramChunk.toString());

    assertEquals(
        "[P((TEXT,null,null),0), L(<a href=\"), "
            + "P((URL_ATTRIBUTE_START,a,href),1)]",
        parsed.toString());
View Full Code Here

      }

      int paramIndex = Integer.parseInt(match.group(1));
      parsePosition = match.end();
      parsedTemplate.addParameter(
          new ParameterChunk(getHtmlContextFromParseState(), paramIndex));

      endOfPreviousMatch = match.end();
    }

    // Add a literal chunk for the substring after the last match, if any.
View Full Code Here

    for (TemplateChunk chunk : parser.getParsedTemplate().getChunks()) {
      if (chunk.getKind() == TemplateChunk.Kind.LITERAL) {
        emitStringLiteral(((LiteralChunk) chunk).getLiteral());
      } else if (chunk.getKind() == TemplateChunk.Kind.PARAMETER) {
        ParameterChunk parameterChunk = (ParameterChunk) chunk;

        int formalParameterIndex = parameterChunk.getParameterIndex();
        if (formalParameterIndex < 0 || formalParameterIndex >= params.length) {
          throw error(logger, "Argument " + formalParameterIndex
              + " beyond range of arguments: " + template);
        }
        String formalParameterName = "arg" + formalParameterIndex;
        JType paramType = params[formalParameterIndex].getType();

        emitParameterExpression(logger, parameterChunk.getContext(),
                                formalParameterName, paramType);
      } else {
        throw error(logger, "Unexpected chunk kind in parsed template "
            + template);
      }
View Full Code Here

    for (TemplateChunk chunk : parser.getParsedTemplate().getChunks()) {
      if (chunk.getKind() == TemplateChunk.Kind.LITERAL) {
        emitStringLiteral(((LiteralChunk) chunk).getLiteral());
      } else if (chunk.getKind() == TemplateChunk.Kind.PARAMETER) {
        ParameterChunk parameterChunk = (ParameterChunk) chunk;

        int formalParameterIndex = parameterChunk.getParameterIndex();
        if (formalParameterIndex < 0 || formalParameterIndex >= params.length) {
          throw error(logger, "Argument " + formalParameterIndex + " beyond range of arguments: "
              + template);
        }
        String formalParameterName = "arg" + formalParameterIndex;
        JType paramType = params[formalParameterIndex].getType();

        emitParameterExpression(
            logger, parameterChunk.getContext(), formalParameterName, paramType);
      } else {
        throw error(logger, "Unexpected chunk kind in parsed template " + template);
      }
    }
    outdent();
View Full Code Here

TOP

Related Classes of com.google.gwt.safehtml.rebind.ParsedHtmlTemplate.ParameterChunk

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.