secure-files

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

SecureFilesApplication.java (1494B)


      1 package xyz.kebigon.securefiles;
      2 
      3 import java.io.File;
      4 
      5 import org.springframework.beans.factory.annotation.Value;
      6 import org.springframework.boot.SpringApplication;
      7 import org.springframework.boot.autoconfigure.SpringBootApplication;
      8 import org.springframework.context.annotation.Bean;
      9 import org.springframework.context.annotation.PropertySource;
     10 import org.springframework.core.env.Environment;
     11 
     12 import com.samskivert.mustache.Mustache;
     13 import com.samskivert.mustache.Mustache.TemplateLoader;
     14 
     15 import lombok.extern.slf4j.Slf4j;
     16 
     17 @Slf4j
     18 @SpringBootApplication
     19 @PropertySource("classpath:securefiles_required.cfg")
     20 @PropertySource("classpath:securefiles_custom.cfg")
     21 public class SecureFilesApplication
     22 {
     23 	public static void main(final String[] args)
     24 	{
     25 		SpringApplication.run(SecureFilesApplication.class, args);
     26 	}
     27 
     28 	@Value("${filedrop.directory}")
     29 	public void setDirectory(final File directory)
     30 	{
     31 		createDirectoryIfAbsent(directory);
     32 	}
     33 
     34 	@Value("${securefiles.database}")
     35 	public void setDatabaseFile(final File file)
     36 	{
     37 		createDirectoryIfAbsent(file.getParentFile());
     38 	}
     39 
     40 	private void createDirectoryIfAbsent(final File directory)
     41 	{
     42 		if (directory.exists())
     43 			return;
     44 
     45 		log.info("Creating directory {}", directory);
     46 		directory.mkdirs();
     47 	}
     48 
     49 	@Bean
     50 	public Mustache.Compiler mustacheCompiler(final TemplateLoader mustacheTemplateLoader, final Environment environment)
     51 	{
     52 		return Mustache.compiler().withLoader(mustacheTemplateLoader).defaultValue("N/A").nullValue("N/A");
     53 	}
     54 }