コード例 #1
0
  @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();
    }
  }
コード例 #2
0
  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();
  }
コード例 #3
0
    @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();
    }
コード例 #4
0
  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;
  }
コード例 #5
0
ファイル: ModulesHandler.java プロジェクト: robfig/plovr
 static {
   SoyFileSet.Builder builder = SoyFileSet.builder();
   builder.add(Resources.getResource(ModulesHandler.class, "modules.soy"));
   SoyFileSet fileSet = builder.build();
   TOFU = fileSet.compileToTofu();
 }