public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
/** * Write the object to the output stream. */ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (dch != null) dch.writeTo(obj, mimeType, os); else throw new UnsupportedDataTypeException( "no DCH for content type " + ds.getContentType()); } }
/** * Returns content type of {@link DataSource}. * * @return content type of {@link DataSource}. */ public String getContentType() { return dataSource.getContentType(); }
public JAXBElement<DataHandler> standardClassDataHandler() { DataSource dataSource = new URLDataSource(getClass().getResource("spring-ws.png")); DataHandler dataHandler = new DataHandler(dataSource); return new JAXBElement<>(NAME, DataHandler.class, dataHandler); }
@Override public String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName) { ByteArrayDataSource dataSource = new ByteArrayDataSource(mimeType, data, offset, length); return addMtomAttachment(new DataHandler(dataSource), elementNamespace, elementLocalName); }
/** * Returns an <code>InputStream</code> representing this object. * @return the <code>InputStream</code> */ public InputStream getInputStream() throws IOException { return dataHandler.getInputStream(); }
/** * Add an attachment to the MimeMessage, taking the content from a * {@code java.io.File}. * <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)! * @param attachmentFilename the name of the attachment as it will * appear in the mail * @param file the File resource to take the content from * @throws MessagingException in case of errors * @see #addAttachment(String, org.springframework.core.io.InputStreamSource) * @see #addAttachment(String, javax.activation.DataSource) */ public void addAttachment(String attachmentFilename, File file) throws MessagingException { Assert.notNull(file, "File must not be null"); FileDataSource dataSource = new FileDataSource(file); dataSource.setFileTypeMap(getFileTypeMap()); addAttachment(attachmentFilename, dataSource); }
public Object getContent(DataSource ds) throws IOException { if (dch != null) return dch.getContent(ds); else return ds.getInputStream(); }
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(); }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(String fileName) { return getFileTypeMap().getContentType(fileName); }
/** * Returns the MIME type of the data represented by this object. * @return the MIME type */ public String getContentType() { return dataHandler.getContentType(); }
/** * Determine if the primary and sub type of this object is * the same as the content type described in rawdata. * * @param rawdata the MIME type string to compare with * @return true if they match */ public boolean match(String rawdata) throws MimeTypeParseException { return match(new MimeType(rawdata)); }
private String getHost(String elementNamespace, DataHandler dataHandler) { try { URI uri = new URI(elementNamespace); return uri.getHost(); } catch (URISyntaxException ex) { // ignore } return dataHandler.getName(); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
@Override public Object encode(final Object value, final MappedField optionalExtraInfo) { return ((MimeType) value).getBaseType(); } }
/** * Default constructor. */ public MimeType() { primaryType = "application"; subType = "*"; parameters = new MimeTypeParameterList(); }
@Override public byte[] getAttachmentAsByteArray(String cid) { try { DataHandler dataHandler = getAttachmentAsDataHandler(cid); return FileCopyUtils.copyToByteArray(dataHandler.getInputStream()); } catch (IOException ex) { throw new UnmarshallingFailureException("Couldn't read attachment", ex); } }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(File file) { return getFileTypeMap().getContentType(file); }
@Override public String addSwaRefAttachment(DataHandler dataHandler) { String contentId = UUID.randomUUID() + "@" + dataHandler.getName(); this.mimeContainer.addAttachment(contentId, dataHandler); return contentId; }
/** * 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); }