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

br.com.objectos.jabuticava.duplicata.Duplicatas Maven / Gradle / Ivy

The newest version!
/*
 * Duplicatas.java criado em 06/05/2013
 * 
 * Propriedade de Objectos Fábrica de Software LTDA.
 * Reprodução parcial ou total proibida.
 */
package br.com.objectos.jabuticava.duplicata;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.MustacheFactory;
import com.google.common.io.Files;
import com.google.common.io.Resources;

import org.joda.time.LocalDate;

/**
 * @author [email protected] (Edenir Norberto Anschau)
 */
public class Duplicatas {

  private Duplicatas() {
  }

  public static ConstrutorDeDuplicata novaDuplicata(DuplicataTipo tipo) {
    return new ConstrutorDeDuplicata()
        .tipo(tipo);
  }

  static MustacheFactory resourcesMf() {
    try {
      File tempDir = Files.createTempDir();
      return newMustacheFactoryAt(tempDir);
    } catch (IOException e) {
      return new DefaultMustacheFactory();
    }
  }

  static String toString(LocalDate data) {
    return data != null ? data.toString("dd/MM/yyyy") : null;
  }

  private static MustacheFactory newMustacheFactoryAt(File dir) throws IOException {
    copyMustache("duplicata.mustache", dir);
    copyMustache("duplicata-page.mustache", dir);

    return new DefaultMustacheFactory(dir);
  }

  private static File copyMustache(String from, File to) throws IOException {
    URL url = Resources.getResource(Styles.class, String.format("/template/%s", from));
    File dest = new File(to, from);
    FileOutputStream out = new FileOutputStream(dest);
    Resources.copy(url, out);
    return dest;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy