/** * This method returns the MIME type of the data in the form of a * string. This method uses the currently installed FileTypeMap. If * there is no FileTypeMap explictly set, the FileDataSource will * call the <code>getDefaultFileTypeMap</code> method on * FileTypeMap to acquire a default FileTypeMap. <i>Note: By * default, the FileTypeMap used will be a MimetypesFileTypeMap.</i> * * @return the MIME Type * @see javax.activation.FileTypeMap#getDefaultFileTypeMap */ public String getContentType() { // check to see if the type map is null? if (typeMap == null) return FileTypeMap.getDefaultFileTypeMap().getContentType(_file); else return typeMap.getContentType(_file); }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(File file) { return getFileTypeMap().getContentType(file); }
private static FileTypeMap loadFileTypeMapFromContextSupportModule() { // see if we can find the extended mime.types from the context-support module InputStream is = ClassLoader.getSystemResourceAsStream("com/sampullara/mustache/mimes.txt"); if (null != is) { return new MimetypesFileTypeMap(is); } return FileTypeMap.getDefaultFileTypeMap(); }
/** Be sure that the default FileTypeMap is a * {@link ContentFileTypeMap}. * * @return the default content type manager. */ public static ContentFileTypeMap ensureContentTypeManager() { FileTypeMap defaultMap = FileTypeMap.getDefaultFileTypeMap(); if (!(defaultMap instanceof ContentFileTypeMap)) { defaultMap = new ContentFileTypeMap(defaultMap); FileTypeMap.setDefaultFileTypeMap(defaultMap); } return (ContentFileTypeMap) defaultMap; }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(String fileName) { return getFileTypeMap().getContentType(fileName); }
final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER); try { this.contentTypes = FileTypeMap.getDefaultFileTypeMap(); } finally { getAndSetContextClassLoader(ccl);
/** * This method returns the MIME type of the data in the form of a * string. This method uses the currently installed FileTypeMap. If * there is no FileTypeMap explictly set, the FileDataSource will * call the <code>getDefaultFileTypeMap</code> method on * FileTypeMap to acquire a default FileTypeMap. <i>Note: By * default, the FileTypeMap used will be a MimetypesFileTypeMap.</i> * * @return the MIME Type * @see javax.activation.FileTypeMap#getDefaultFileTypeMap */ public String getContentType() { // check to see if the type map is null? if (typeMap == null) return FileTypeMap.getDefaultFileTypeMap().getContentType(_file); else return typeMap.getContentType(_file); }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(String fileName) { return getFileTypeMap().getContentType(fileName); }
final Object ccl = getAndSetContextClassLoader(MAILHANDLER_LOADER); try { this.contentTypes = FileTypeMap.getDefaultFileTypeMap(); } finally { getAndSetContextClassLoader(ccl);
final String mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(resourceLocation); final String resourceName = getResourceName(resourceLocation); final InputStream is = DataSourceClassPathResolver.class.getResourceAsStream(resourceName);
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(File file) { return getFileTypeMap().getContentType(file); }
/** Constructor. */ public ContentFileTypeMap() { this.parent = new SoftReference<>(FileTypeMap.getDefaultFileTypeMap()); }
/** * Returns the content type of the data source */ public String getContentType() { if (fileTypeMap == null) { return FileTypeMap.getDefaultFileTypeMap().getContentType(file); } else { return fileTypeMap.getContentType(file); } }
/** * Add an inline element to the MimeMessage, taking the content from a * {@code org.springframework.core.io.Resource}. * <p>The content type will be determined by the name of the given * content file. Do not use this for temporary files with arbitrary * filenames (possibly ending in ".tmp" or the like)! * <p>Note that the InputStream returned by the Resource implementation * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke * {@code getInputStream()} multiple times. * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText}; * else, mail readers might not be able to resolve inline references correctly. * @param contentId the content ID to use. Will end up as "Content-ID" header * in the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>". * Can be referenced in HTML source via src="cid:myId" expressions. * @param resource the resource to take the content from * @throws MessagingException in case of errors * @see #setText * @see #addInline(String, java.io.File) * @see #addInline(String, javax.activation.DataSource) */ public void addInline(String contentId, Resource resource) throws MessagingException { Assert.notNull(resource, "Resource must not be null"); String contentType = getFileTypeMap().getContentType(resource.getFilename()); addInline(contentId, resource, contentType); }
public GenericContext(Bundle bundle, String mountPoint) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("GenericContext(" + mountPoint + " )"); } this.bundle = bundle; if (!mountPoint.startsWith("/")) { mountPoint = "/" + mountPoint; } this.mountPoint = mountPoint; typeMap = (MimetypesFileTypeMap) getDefaultFileTypeMap(); typeMap.addMimeTypes("text/css css"); }
/** * Returns the content type of the data source */ public String getContentType() { if (fileTypeMap == null) { return FileTypeMap.getDefaultFileTypeMap().getContentType(file); } else { return fileTypeMap.getContentType(file); } }
/** * Add an attachment to the MimeMessage, taking the content from an * {@code org.springframework.core.io.InputStreamResource}. * <p>The content type will be determined by the given filename for * the attachment. Thus, any content source will be fine, including * temporary files with arbitrary filenames. * <p>Note that the InputStream returned by the InputStreamSource * implementation needs to be a <i>fresh one on each call</i>, as * JavaMail will invoke {@code getInputStream()} multiple times. * @param attachmentFilename the name of the attachment as it will * appear in the mail * @param inputStreamSource the resource to take the content from * (all of Spring's Resource implementations can be passed in here) * @throws MessagingException in case of errors * @see #addAttachment(String, java.io.File) * @see #addAttachment(String, javax.activation.DataSource) * @see org.springframework.core.io.Resource */ public void addAttachment(String attachmentFilename, InputStreamSource inputStreamSource) throws MessagingException { String contentType = getFileTypeMap().getContentType(attachmentFilename); addAttachment(attachmentFilename, inputStreamSource, contentType); }
private static FileTypeMap loadFileTypeMapFromContextSupportModule() { // See if we can find the extended mime.types from the context-support module... Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types"); if (mappingLocation.exists()) { InputStream inputStream = null; try { inputStream = mappingLocation.getInputStream(); return new MimetypesFileTypeMap(inputStream); } catch (IOException ex) { // ignore } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ex) { // ignore } } } } return FileTypeMap.getDefaultFileTypeMap(); }
public ERMailDataAttachment(String fileName, String id, DataHandler aHandler) { super(null); _fileName = fileName; _contentID = id; _dataHandler = aHandler; _mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(fileName); }
/** * Add an inline element to the MimeMessage, taking the content from a * {@code org.springframework.core.io.Resource}. * <p>The content type will be determined by the name of the given * content file. Do not use this for temporary files with arbitrary * filenames (possibly ending in ".tmp" or the like)! * <p>Note that the InputStream returned by the Resource implementation * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke * {@code getInputStream()} multiple times. * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText}; * else, mail readers might not be able to resolve inline references correctly. * @param contentId the content ID to use. Will end up as "Content-ID" header * in the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>". * Can be referenced in HTML source via src="cid:myId" expressions. * @param resource the resource to take the content from * @throws MessagingException in case of errors * @see #setText * @see #addInline(String, java.io.File) * @see #addInline(String, javax.activation.DataSource) */ public void addInline(String contentId, Resource resource) throws MessagingException { Assert.notNull(resource, "Resource must not be null"); String contentType = getFileTypeMap().getContentType(resource.getFilename()); addInline(contentId, resource, contentType); }