1 package org.imageconverter.config; 2 3 import java.nio.file.Files; 4 import java.nio.file.Paths; 5 6 import org.imageconverter.util.BeanUtil; 7 import org.springframework.cloud.context.config.annotation.RefreshScope; 8 import org.springframework.context.annotation.Bean; 9 import org.springframework.context.annotation.Configuration; 10 11 import net.sourceforge.tess4j.ITesseract; 12 import net.sourceforge.tess4j.Tesseract; 13 14 /** 15 * Tesseract configuration bean. 16 * 17 * @author Fernando Romulo da Silva 18 */ 19 @Configuration 20 public class ImageConfig { 21 22 /** 23 * Create a valid tesseract object or return a <code>null</code> if it was not possible. 24 * 25 * @return A {@link Tesseract} object or null 26 */ 27 @Bean 28 @RefreshScope 29 ITesseract tesseractTess4j() { 30 31 final var path = Paths.get(BeanUtil.getPropertyValue("tesseract.folder")); 32 33 final ITesseract tesseract; 34 35 if (Files.notExists(path)) { 36 37 tesseract = null; 38 39 } else { 40 41 tesseract = new Tesseract(); 42 tesseract.setDatapath(BeanUtil.getPropertyValue("tesseract.folder")); 43 tesseract.setLanguage(BeanUtil.getPropertyValue("tesseract.language")); 44 tesseract.setVariable("user_defined_dpi", BeanUtil.getPropertyValue("tesseract.dpi")); 45 } 46 47 return tesseract; 48 } 49 50 // @Bean 51 // @Primary 52 // public Validator validator() { 53 // final var factory = Validation.buildDefaultValidatorFactory(); 54 // return factory.getValidator(); 55 // } 56 57 // @Autowired 58 // private MultipartProperties multipartProperties; 59 60 // @Bean 61 // @ConditionalOnMissingBean({ MultipartConfigElement.class, CommonsMultipartResolver.class }) 62 // @Description("MultipartConfig for file posting") 63 // public MultipartConfigElement multipartConfigElement() { 64 // multipartProperties.setEnabled(true); 65 // multipartProperties.setMaxFileSize(ofMegabytes(20)); 66 // multipartProperties.setMaxRequestSize(ofMegabytes(20)); 67 // return multipartProperties.createMultipartConfig(); 68 // } 69 // 70 // @Bean 71 // @Order(0) 72 // @Description("Multipart filter for file posting") 73 // public MultipartFilter multipartFile() { 74 // final MultipartFilter multipartFilter = new MultipartFilter(); 75 // // same name's request parameter => final @RequestParam MultipartFile file 76 // multipartFilter.setMultipartResolverBeanName("file"); 77 // return multipartFilter; 78 // } 79 80 // @Bean 81 // public CommonsMultipartResolver multipartResolver(){ 82 // CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(); 83 //// commonsMultipartResolver.setMaxInMemorySize(); 84 //// commonsMultipartResolver.setMaxUploadSize(ofMegabytes(20)); 85 // return commonsMultipartResolver; 86 // } 87 88 // @Bean 89 // public RestTemplate restTemplate() { 90 // SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); 91 // Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("localhost", 8888)); 92 // requestFactory.setProxy(proxy); 93 // return new RestTemplate(requestFactory); 94 // } 95 // 96 // @Bean 97 // public ClientHttpRequestFactory clientHttpRequestFactory() { 98 // 99 // List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(); 100 // 101 // SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); 102 // 103 // Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("localhost", 8888)); 104 // 105 // requestFactory.setProxy(proxy); 106 // 107 // return new InterceptingClientHttpRequestFactory(requestFactory, interceptors); 108 // } 109 // 110 // @Bean 111 // public RestTemplateBuilder restTemplateBuilder() { 112 // return new RestTemplateBuilder(); 113 // } 114 }