Example usage for javax.mail.internet ContentDisposition getParameter

List of usage examples for javax.mail.internet ContentDisposition getParameter

Introduction

In this page you can find the example usage for javax.mail.internet ContentDisposition getParameter.

Prototype

public String getParameter(String name) 

Source Link

Document

Return the specified parameter value.

Usage

From source file:com.adaptris.core.mail.attachment.MimeMailCreator.java

private String getAttachmentFileName(MimeBodyPart p) throws Exception {
    String filename = null;/*from   w w w. j a v  a 2  s.c  o m*/
    String[] hdr = p.getHeader("Content-Disposition");
    if (hdr != null) {
        ContentDisposition cd = new ContentDisposition(hdr[0]);
        filename = cd.getParameter("filename");
    }
    if (filename == null) {
        hdr = p.getHeader("Content-Type");
        if (hdr != null) {
            ContentType ct = new ContentType(hdr[0]);
            filename = ct.getParameter("name");
        }
    }
    if (filename == null) {
        filename = idGenerator.create(p);
        logR.warn("Could not determine filename for MimeBodyPart, assigning unique filename of {}", filename);

    }
    return filename;
}

From source file:org.apache.tika.server.resource.TikaResource.java

public static String detectFilename(MultivaluedMap<String, String> httpHeaders) {

    String disposition = httpHeaders.getFirst("Content-Disposition");
    if (disposition != null) {
        try {/* ww  w .j av  a2  s.c  om*/
            ContentDisposition c = new ContentDisposition(disposition);

            // only support "attachment" dispositions
            if ("attachment".equals(c.getDisposition())) {
                String fn = c.getParameter("filename");
                if (fn != null) {
                    return fn;
                }
            }
        } catch (ParseException e) {
            // not a valid content-disposition field
            LOG.warn("Parse exception {} determining content disposition", e.getMessage(), e);
        }
    }

    // this really should not be used, since it's not an official field
    return httpHeaders.getFirst("File-Name");
}

From source file:uk.co.techblue.alfresco.resteasy.providers.DocumentContentProvider.java

/**
 * Gets the file prefix.//w  w w.ja v  a  2  s .  c  o  m
 * 
 * @param contentDisposition the content disposition
 * @return the file prefix
 */
private String getFilePrefix(final ContentDisposition contentDisposition) {
    final String fileName = contentDisposition.getParameter(PARAM_FILENAME);
    return StringUtils.substringBeforeLast(fileName, ".");
}

From source file:uk.co.techblue.alfresco.resteasy.providers.DocumentContentProvider.java

/**
 * Gets the file suffix.//w  ww  . j a v  a 2  s .c  o  m
 * 
 * @param contentDisposition the content disposition
 * @param mediaType the media type
 * @return the file suffix
 */
private String getFileSuffix(final ContentDisposition contentDisposition, final MediaType mediaType) {
    final String fileName = contentDisposition.getParameter(PARAM_FILENAME);
    return getFileSuffix(mediaType, fileName);
}

From source file:uk.co.techblue.docusign.resteasy.providers.DocumentFileProvider.java

private String getFilePrefix(ContentDisposition contentDisposition) {
    String fileName = contentDisposition.getParameter(PARAM_FILENAME);
    return StringUtils.substringBeforeLast(fileName, ".");
}

From source file:uk.co.techblue.docusign.resteasy.providers.DocumentFileProvider.java

private void setDocumentAttributes(ContentDisposition contentDisposition, DocumentFile documentFile) {
    documentFile.setDocumentId(contentDisposition.getParameter(PARAM_DOCUMENT_ID));
    documentFile.setName(contentDisposition.getParameter(PARAM_FILENAME));
}

From source file:uk.co.techblue.docusign.resteasy.providers.DocumentFileProvider.java

private String getFileSuffix(ContentDisposition contentDisposition, MediaType mediaType) {
    String fileName = contentDisposition.getParameter(PARAM_FILENAME);
    return getFileSuffix(mediaType, fileName);
}