All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.sitebricks.rendering.control.RequireWidget Maven / Gradle / Ivy

package com.google.sitebricks.rendering.control;

import com.google.sitebricks.Renderable;
import com.google.sitebricks.Respond;
import com.google.sitebricks.compiler.EvaluatorCompiler;
import com.google.sitebricks.compiler.ExpressionCompileException;
import com.google.sitebricks.compiler.Token;
import com.google.sitebricks.rendering.SelfRendering;

import net.jcip.annotations.Immutable;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @author Dhanji R. Prasanna ([email protected])
 */
@Immutable
@SelfRendering
class RequireWidget implements Renderable {
  private final List template;

  public RequireWidget(String xml, EvaluatorCompiler compiler) throws ExpressionCompileException {
    this.template = compiler.tokenizeAndCompile(xml);
  }

  public void render(Object bound, Respond respond) {
    //rebuild template from tokens
    StringBuilder builder = new StringBuilder();
    for (Token token : template) {
      builder.append(token.render(bound));
    }

    //special method interns tokens
    respond.require(builder.toString());
  }

  public  Set collect(Class clazz) {
    return Collections.emptySet();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy