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

com.google.sitebricks.rendering.control.TextWidget 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.ThreadSafe;

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

/**
 * @author Dhanji R. Prasanna ([email protected])
 */
@ThreadSafe @SelfRendering
class TextWidget implements Renderable {
    private final List tokenizedTemplate;     //TODO store some metrics to allocate buffers later

    TextWidget(String template, EvaluatorCompiler compiler) throws ExpressionCompileException {

        //compile token stream
        tokenizedTemplate = compiler.tokenizeAndCompile(template);
    }

    public void render(Object bound, Respond respond) {

        //render template from tokens
        StringBuilder builder = new StringBuilder();
        for (Token token : tokenizedTemplate) {
            builder.append(token.render(bound));
        }

        respond.write(builder.toString());
    }


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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy