List of usage examples for org.springframework.mail.javamail ConfigurableMimeFileTypeMap ConfigurableMimeFileTypeMap
ConfigurableMimeFileTypeMap
From source file:org.sventon.web.ctrl.template.ShowFileControllerTest.java
@Before public void setUp() throws Exception { final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap(); fileTypeMap.afterPropertiesSet();/*from w w w . j a v a2 s . co m*/ ctrl = new ShowFileController(fileTypeMap); ctrl.setArchiveFileExtensionPattern("(jar|zip|war|ear)"); }
From source file:org.sventon.web.ctrl.template.ShowThumbnailsControllerTest.java
@Test public void testSvnHandle() throws Exception { final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap(); fileTypeMap.afterPropertiesSet();// www . j a va 2 s .com final MultipleEntriesCommand command = new MultipleEntriesCommand(); final ShowThumbnailsController ctrl = new ShowThumbnailsController(fileTypeMap); final String[] pathEntries = new String[] { "file1.gif@123", "file2.jpg@123", "file.abc@123" }; command.setEntries(PathRevision.parse(pathEntries)); final MockHttpServletRequest req = new MockHttpServletRequest(); req.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.CONTENT_DISPOSITION_INLINE); final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, req, null, null); final Map model = modelAndView.getModel(); final List entries = (List) model.get("thumbnailentries"); assertEquals(2, entries.size()); final PathRevision entry0 = (PathRevision) entries.get(0); assertEquals("file1.gif", entry0.getPath()); assertEquals(123, entry0.getRevision().getNumber()); }
From source file:org.sventon.web.ctrl.template.ShowFileControllerTest.java
@Test public void testConfigurableMimeFileTypeMap() { final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap(); fileTypeMap.afterPropertiesSet();/*w ww . java 2 s .c o m*/ assertEquals("application/octet-stream", fileTypeMap.getContentType("file.abc")); assertEquals("application/zip", fileTypeMap.getContentType("file.zip")); assertEquals("image/jpeg", fileTypeMap.getContentType("file.jpg")); assertEquals("image/jpeg", fileTypeMap.getContentType("file.jpe")); assertEquals("image/jpeg", fileTypeMap.getContentType("file.jpeg")); assertEquals("image/gif", fileTypeMap.getContentType("file.gif")); assertEquals("image/x-png", fileTypeMap.getContentType("file.png")); assertEquals("application/octet-stream", fileTypeMap.getContentType("filenamejpg")); assertEquals("image/gif", fileTypeMap.getContentType("/dir/file.gif")); }
From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java
@Test public void testSvnHandleGetImageAsInline() throws Exception { final BaseCommand command = new BaseCommand(); command.setName(repositoryName);/*from w ww .j a v a 2 s . c o m*/ command.setPath("/testimage.gif"); final GetFileController ctrl = new GetFileController(); ctrl.setApplication(application); ctrl.setRepositoryService(mock(RepositoryService.class)); final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap(); mftm.afterPropertiesSet(); ctrl.setMimeFileTypeMap(mftm); final ModelAndView modelAndView; request.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.CONTENT_DISPOSITION_INLINE); final MockHttpServletResponse res = new MockHttpServletResponse(); modelAndView = ctrl.svnHandle(null, command, 100, null, request, res, null); assertNull(modelAndView); assertEquals("image/gif", res.getContentType()); assertTrue(((String) res.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).startsWith("inline")); }
From source file:com.netsteadfast.greenstep.util.FSUtils.java
public static String getMimeType(String filename) throws Exception { ConfigurableMimeFileTypeMap mfm = new ConfigurableMimeFileTypeMap(); return mfm.getContentType(filename); }
From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java
@Test public void testCacheNotUsed() throws Exception { final RepositoryService repositoryServiceMock = EasyMock.createMock(RepositoryService.class); final GetFileController ctrl = new GetFileController(); repositoryConfiguration.setCacheUsed(false); final ImageScaler imageScaler = new ImageScaler() { @Override//from w ww. j a v a 2s . co m public BufferedImage getThumbnail(BufferedImage image, int maxSize) { return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); } }; final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap(); mftm.afterPropertiesSet(); ctrl.setApplication(application); ctrl.setRepositoryService(repositoryServiceMock); ctrl.setMimeFileTypeMap(mftm); ctrl.setImageScaler(imageScaler); ctrl.setImageFormatName("jpg"); final BaseCommand command = new BaseCommand(); command.setName(repositoryName); command.setPath("/test/target.jpg"); request.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.DISPLAY_TYPE_THUMBNAIL); repositoryServiceMock.getFileContents((SVNConnection) EasyMock.isNull(), EasyMock.matches(command.getPath()), EasyMock.eq(-1L), (OutputStream) EasyMock.anyObject()); assertEquals(0, response.getContentAsByteArray().length); EasyMock.replay(repositoryServiceMock); ctrl.svnHandle(null, command, 100, null, request, response, null); EasyMock.verify(repositoryServiceMock); assertTrue(((String) response.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).contains("target.jpg")); assertEquals(622, response.getContentAsByteArray().length); }
From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java
@Test public void testCacheUsed() throws Exception { final RepositoryService repositoryServiceMock = EasyMock.createMock(RepositoryService.class); final ObjectCacheManager objectCacheManager = new ObjectCacheManager(configDirectory, 0, false, false, 0, 0, false, 0) {//from w ww .j a v a2 s. c om @Override protected ObjectCache createCache(RepositoryName cacheName) throws CacheException { return new DefaultObjectCache(cacheName.toString(), null, 1000, false, false, 0, 0, false, 0); } }; objectCacheManager.register(repositoryName); final GetFileController ctrl = new GetFileController(); repositoryConfiguration.setCacheUsed(true); final ImageScaler imageScaler = new ImageScaler() { @Override public BufferedImage getThumbnail(BufferedImage image, int maxSize) { return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); } }; final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap(); mftm.afterPropertiesSet(); ctrl.setApplication(application); ctrl.setRepositoryService(repositoryServiceMock); ctrl.setMimeFileTypeMap(mftm); ctrl.setImageScaler(imageScaler); ctrl.setImageFormatName("png"); ctrl.setObjectCacheManager(objectCacheManager); final BaseCommand command = new BaseCommand(); command.setName(repositoryName); command.setPath("/test/target.png"); request.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.DISPLAY_TYPE_THUMBNAIL); repositoryServiceMock.getFileContents((SVNConnection) EasyMock.isNull(), EasyMock.matches(command.getPath()), EasyMock.eq(-1L), (OutputStream) EasyMock.anyObject()); assertEquals(0, response.getContentAsByteArray().length); EasyMock.replay(repositoryServiceMock); ctrl.svnHandle(null, command, 100, null, request, response, null); EasyMock.verify(repositoryServiceMock); assertTrue(((String) response.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).contains("target.png")); assertEquals(68, response.getContentAsByteArray().length); EasyMock.reset(repositoryServiceMock); // Thumbnail is now cached - verify that it's used EasyMock.replay(repositoryServiceMock); ctrl.svnHandle(null, command, 100, null, request, response, null); EasyMock.verify(repositoryServiceMock); }
From source file:com.wavemaker.runtime.FileController.java
protected void setContentType(HttpServletResponse response, File file) { ConfigurableMimeFileTypeMap mimeFileTypeMap = new ConfigurableMimeFileTypeMap(); mimeFileTypeMap.setMappings(new String[] { "text/css css CSS", "application/json json JSON smd SMD" }); response.setContentType(mimeFileTypeMap.getContentType(file)); }
From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java
@Test public void testSvnHandleGetFile() throws Exception { final BaseCommand command = new BaseCommand(); command.setName(repositoryName);//from w ww . j a va2s . c o m command.setPath("/testfile.txt"); final GetFileController ctrl = new GetFileController(); ctrl.setApplication(application); ctrl.setRepositoryService(mock(RepositoryService.class)); final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap(); mftm.afterPropertiesSet(); ctrl.setMimeFileTypeMap(mftm); final ModelAndView modelAndView; final MockHttpServletResponse res = new MockHttpServletResponse(); ctrl.setServletContext(mockServletContext); modelAndView = ctrl.svnHandle(null, command, 100, null, request, res, null); assertNull(modelAndView); assertEquals("text/plain", res.getContentType()); assertTrue(((String) res.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).startsWith("attachment")); }
From source file:eionet.webq.web.controller.FileDownloadController.java
/** * Writes project file to response./* w w w. j av a2 s . co m*/ * * @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); }