Java Code Examples for javax.activation.DataHandler#getName()

The following examples show how to use javax.activation.DataHandler#getName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cxf   File: BookCatalog.java    License: Apache License 2.0 6 votes vote down vote up
@POST
@Consumes("multipart/form-data")
public Response addBook(final MultipartBody body) throws Exception {
    for (final Attachment attachment: body.getAllAttachments()) {
        final DataHandler handler = attachment.getDataHandler();

        if (handler != null) {
            final String source = handler.getName();
            final LuceneDocumentMetadata metadata = new LuceneDocumentMetadata()
                .withSource(source)
                .withField("modified", Date.class);

            final Document document = extractor.extract(handler.getInputStream(), metadata);
            if (document != null) {
                try (IndexWriter writer = getIndexWriter()) {
                    writer.addDocument(document);
                    writer.commit();
                }
            }
        }
    }

    return Response.ok().build();
}
 
Example 2
Source Project: spring-analysis-note   File: Jaxb2Marshaller.java    License: MIT License 5 votes vote down vote up
private String getHost(String elementNamespace, DataHandler dataHandler) {
	try {
		URI uri = new URI(elementNamespace);
		return uri.getHost();
	}
	catch (URISyntaxException ex) {
		// ignore
	}
	return dataHandler.getName();
}
 
Example 3
Source Project: mail-micro-service   File: MailUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 追加附件
 * @author hf-hf
 * @date 2018/12/27 16:53
 * @param attachments
 * @param wrapPart
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 */
private void addAttachments(File[] attachments, MimeMultipart wrapPart)
        throws MessagingException, UnsupportedEncodingException {
    if (null != attachments && attachments.length > 0) {
        for (int i = 0; i < attachments.length; i++) {
            MimeBodyPart attachmentBodyPart = new MimeBodyPart();
            DataHandler dataHandler = new DataHandler(new FileDataSource(attachments[i]));
            String fileName = dataHandler.getName();
            attachmentBodyPart.setDataHandler(dataHandler);
            // 显示指定文件名(防止文件名乱码)
            attachmentBodyPart.setFileName(MimeUtility.encodeText(fileName));
            wrapPart.addBodyPart(attachmentBodyPart);
        }
    }
}
 
Example 4
Source Project: java-technology-stack   File: Jaxb2Marshaller.java    License: MIT License 5 votes vote down vote up
private String getHost(String elementNamespace, DataHandler dataHandler) {
	try {
		URI uri = new URI(elementNamespace);
		return uri.getHost();
	}
	catch (URISyntaxException ex) {
		// ignore
	}
	return dataHandler.getName();
}
 
Example 5
Source Project: mail-micro-service   File: MailUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 追加附件
 * @author hf-hf
 * @date 2018/12/27 16:53
 * @param attachments
 * @param wrapPart
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 */
private void addAttachments(File[] attachments, MimeMultipart wrapPart)
        throws MessagingException, UnsupportedEncodingException {
    if (null != attachments && attachments.length > 0) {
        for (int i = 0; i < attachments.length; i++) {
            MimeBodyPart attachmentBodyPart = new MimeBodyPart();
            DataHandler dataHandler = new DataHandler(new FileDataSource(attachments[i]));
            String fileName = dataHandler.getName();
            attachmentBodyPart.setDataHandler(dataHandler);
            // 显示指定文件名(防止文件名乱码)
            attachmentBodyPart.setFileName(MimeUtility.encodeText(fileName));
            wrapPart.addBodyPart(attachmentBodyPart);
        }
    }
}
 
Example 6
private String getHost(String elementNamespace, DataHandler dataHandler) {
	try {
		URI uri = new URI(elementNamespace);
		return uri.getHost();
	}
	catch (URISyntaxException e) {
		// ignore
	}
	return dataHandler.getName();
}
 
Example 7
Source Project: spring-analysis-note   File: Jaxb2Marshaller.java    License: MIT License 4 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler dataHandler) {
	String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
	this.mimeContainer.addAttachment(contentId, dataHandler);
	return contentId;
}
 
Example 8
Source Project: java-technology-stack   File: Jaxb2Marshaller.java    License: MIT License 4 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler dataHandler) {
	String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
	this.mimeContainer.addAttachment(contentId, dataHandler);
	return contentId;
}
 
Example 9
@Override
public String addSwaRefAttachment(DataHandler dataHandler) {
	String contentId = UUID.randomUUID() + "@" + dataHandler.getName();
	this.mimeContainer.addAttachment(contentId, dataHandler);
	return contentId;
}