@Override protected void processTemplates(List<TemplateResource> templateResources, Writer writer) throws Exception { try { String namespace = GetterUtil.getString(get(TemplateConstants.NAMESPACE)); if (Validator.isNull(namespace)) { throw new TemplateException("No namespace specified."); } SoyFileSet soyFileSet = getSoyFileSet(templateResources); SoyTofu soyTofu = soyFileSet.compileToTofu(); Renderer renderer = soyTofu.newRenderer(namespace); renderer.setData(getSoyMapData()); boolean renderStrict = GetterUtil.getBoolean(get(TemplateConstants.RENDER_STRICT), true); if (renderStrict) { SanitizedContent sanitizedContent = renderer.renderStrict(); writer.write(sanitizedContent.stringValue()); } else { writer.write(renderer.render()); } } catch (PrivilegedActionException pae) { throw pae.getException(); } }
public DirectoryHandler(Config config) { this.config = config; SoyFileSet.Builder builder = new SoyFileSet.Builder(); builder.add(Resources.getResource(DirectoryHandler.class, "soyweb.soy")); SoyFileSet fileSet = builder.build(); soyWebTemplate = fileSet.compileToTofu(); }
@Override public SoyFileSet run() throws Exception { Builder builder = SoyFileSet.builder(); for (TemplateResource templateResource : _templateResources) { String templateContent = getTemplateContent(templateResource); builder.add(templateContent, templateResource.getTemplateId()); } return builder.build(); }
protected SoyFileSet getSoyFileSet(List<TemplateResource> templateResources) throws Exception { SoyFileSet soyFileSet = null; if (_privileged) { soyFileSet = AccessController.doPrivileged(new TemplatePrivilegedExceptionAction(templateResources)); } else { Builder builder = SoyFileSet.builder(); for (TemplateResource templateResource : templateResources) { String templateContent = getTemplateContent(templateResource); builder.add(templateContent, templateResource.getTemplateId()); } soyFileSet = builder.build(); } return soyFileSet; }
static { SoyFileSet.Builder builder = SoyFileSet.builder(); builder.add(Resources.getResource(ModulesHandler.class, "modules.soy")); SoyFileSet fileSet = builder.build(); TOFU = fileSet.compileToTofu(); }