public FileItemReader(Path inputDirectory, ConfigurableMimeFileTypeMap map) { Assert.notNull(inputDirectory); Assert.isTrue(isDirectory(inputDirectory)); Assert.isTrue(isReadable(inputDirectory)); this.map = map; this.inputDirectory = inputDirectory; }
public static String getMimeType(String filename) throws Exception { ConfigurableMimeFileTypeMap mfm = new ConfigurableMimeFileTypeMap(); return mfm.getContentType(filename); }
public JavaMailSenderImplBase() { ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap(); fileTypeMap.afterPropertiesSet(); _defaultFileTypeMap = fileTypeMap; }
@Bean public ItemReader<Path> reader() { return new FileItemReader(Paths.get(settings.directoryIn()), new ConfigurableMimeFileTypeMap()); }
public ConfigurableMimeFileTypeMap getFileTypeMap() { return fileTypeMap; }
public void setFileTypeMap(ConfigurableMimeFileTypeMap fileTypeMap) { this.fileTypeMap = fileTypeMap; }
/** * Writes project file to response. * * @param name file name * @param projectFile project file object * @param response http response * @param disposition inline or attachment */ private void writeProjectFileToResponse(String name, ProjectFile projectFile, HttpServletResponse response, String disposition, String format) { ConfigurableMimeFileTypeMap mimeTypesMap = new ConfigurableMimeFileTypeMap(); String contentType = mimeTypesMap.getContentType(name); // check if default if (mimeTypesMap.getContentType("").equals(contentType)) { if (name.endsWith(".xhtml")) { contentType = MediaType.APPLICATION_XHTML_XML_VALUE; } else if (name.endsWith(".js")) { contentType = "application/javascript"; } else if (name.endsWith(".json")) { contentType = MediaType.APPLICATION_JSON_VALUE; } else { contentType = MediaType.APPLICATION_XML_VALUE; } // TODO check if there are more missing mime types } byte[] fileContent = projectFile.getFileContent(); if ("json".equals(format)) { fileContent = jsonXMLConverter.convertXmlToJson(projectFile.getFileContent()); contentType = MediaType.APPLICATION_JSON_VALUE; disposition = "inline"; } if (contentType.startsWith("text") || contentType.startsWith("application")) { contentType += ";charset=UTF-8"; } response.setContentType(contentType); setContentDisposition(response, disposition + ";filename=" + name); if (projectFile.getUpdated() != null) { response.setDateHeader("Last-Modified", projectFile.getUpdated().getTime()); } else if (projectFile.getCreated() != null) { response.setDateHeader("Last-Modified", projectFile.getCreated().getTime()); } writeToResponse(response, fileContent); }