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

io.tesla.maven.plugins.resources.ResourceProcessor Maven / Gradle / Ivy

The newest version!
package io.tesla.maven.plugins.resources;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;

import javax.inject.Named;
import javax.inject.Singleton;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheException;

@Named
@Singleton
public class ResourceProcessor {

  public void testMavenDelimiter() throws IOException {
    DefaultMustacheFactory mf = new NoEncodingMustacheFactory();
    Mustache maven = mf.compile(new StringReader("Hello, ${foo}."), "maven", "${", "}");
    StringWriter sw = new StringWriter();
    maven.execute(sw, new Object() {
      String foo = "Jason";
    }).close();
  }

  public void testAntDelimiter() throws IOException {
    DefaultMustacheFactory mf = new NoEncodingMustacheFactory();
    Mustache maven = mf.compile(new StringReader("Hello, @foo@."), "maven", "@", "@");
    StringWriter sw = new StringWriter();
    maven.execute(sw, new Object() {
      String foo = "Jason";
    }).close();
  }

  private static class NoEncodingMustacheFactory extends DefaultMustacheFactory {
    @Override
    public void encode(String value, Writer writer) {
      // TODO: encoding rules
      try {
        writer.write(value);
      } catch (IOException e) {
        throw new MustacheException(e);
      }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy