Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  import org.slf4j.Logger;
Created with IntelliJ IDEA. User: mati Date: 22/06/2013 Time: 17:00 A default implementation of TemplateRenderer, which using a print writer writes to a servlet output. The implementation will set all required objects if available on renderer, e.g. SoyMsgBundle, IjData (Injected Data) before rendering to servlet output stream. Note: in order to support "an early head flush" performance recommendation and "progressive rendering" a subclass of this class needs to be developed and an implementation needs to inspect a passed in model object, cast it accordingly and flush to system out, after rendering it. A default implementation will flush to a servlet output stream once all model objects are resolved and converted to SoyMapData, an important thing to notice here is that converting from model object to SoyMapData may be expensive depending on an implementation, i.e. if model objects have been resolved in a controller or if for instance they were wrapped in a Callable object.
 public class DefaultTemplateRenderer implements TemplateRenderer {
     private static final Logger logger = LoggerFactory.getLogger(DefaultTemplateRenderer.class);
     protected ToSoyDataConverter toSoyDataConverter = new DefaultToSoyDataConverter();

whether debug is on, in case it is on - Soy's Renderer Don't Add To Cache will be turned on, which means renderer caching will be disabled
     public void render(final RenderRequest renderRequestthrows Exception {
         if (!renderRequest.getCompiledTemplates().isPresent()) {
             .warn("compiled templates are not present, nothing to render!");
         final SoyTofu compiledTemplates = renderRequest.getCompiledTemplates().get();
         final String templateName = renderRequest.getTemplateName();
         final SoyTofu.Renderer renderer = compiledTemplates.newRenderer(templateName);
         final Optional<SoyMapDatasoyModel = .toSoyMap(renderRequest.getModel());
     protected void setupRenderer(final SoyTofu.Renderer rendererfinal RenderRequest renderRequestfinal Optional<SoyMapDatamodelthrows Exception {
         if (model.isPresent()) {
         final Optional<SoyMapDataglobalModel = renderRequest.getGlobalRuntimeModel();
         if (globalModel.isPresent()) {
         final Optional<SoyMsgBundlesoyMsgBundleOptional = renderRequest.getSoyMsgBundle();
         if (soyMsgBundleOptional.isPresent()) {
             if (isHotReloadModeOff()) {
                 if (renderRequest.getCompiledTemplates().isPresent()) {
                     renderRequest.getCompiledTemplates().get().addToCache(soyMsgBundleOptional.get(), null);
         if (isHotReloadMode()) {
     protected void writeResponse(final SoyTofu.Renderer rendererfinal RenderRequest renderRequestthrows IOException {
         final HttpServletResponse response = renderRequest.getResponse();
         final SoyView soyView = renderRequest.getSoyView();
         final PrintWriter writer = response.getWriter();
    public void setToSoyDataConverter(final ToSoyDataConverter toSoyDataConverter) {
        this. = toSoyDataConverter;
    public void setHotReloadMode(boolean hotReloadMode) {
        this. = hotReloadMode;
    public boolean isHotReloadMode() {
        return ;
    public boolean isHotReloadModeOff() {
        return !;
New to GrepCode? Check out our FAQ X