Search in sources :

Example 1 with Header

use of org.apache.http.entity.mime.Header in project manifoldcf by apache.

the class ModifiedHttpMultipart method doWriteTo.

private void doWriteTo(final HttpMultipartMode mode, final OutputStream out, boolean writeContent) throws IOException {
    ByteArrayBuffer boundary = encode(this.charset, getBoundary());
    for (FormBodyPart part : this.parts) {
        writeBytes(TWO_DASHES, out);
        writeBytes(boundary, out);
        writeBytes(CR_LF, out);
        Header header = part.getHeader();
        switch(mode) {
            case STRICT:
                for (MinimalField field : header) {
                    writeField(field, this.charset, out);
                }
                break;
            case BROWSER_COMPATIBLE:
                // Only write Content-Disposition
                // Use content charset
                MinimalField cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION);
                writeField(cd, this.charset, out);
                String filename = part.getBody().getFilename();
                if (filename != null) {
                    MinimalField ct = part.getHeader().getField(MIME.CONTENT_TYPE);
                    writeField(ct, this.charset, out);
                }
                break;
        }
        writeBytes(CR_LF, out);
        if (writeContent) {
            part.getBody().writeTo(out);
        }
        writeBytes(CR_LF, out);
    }
    writeBytes(TWO_DASHES, out);
    writeBytes(boundary, out);
    writeBytes(TWO_DASHES, out);
    writeBytes(CR_LF, out);
}
Also used : FormBodyPart(org.apache.http.entity.mime.FormBodyPart) Header(org.apache.http.entity.mime.Header) MinimalField(org.apache.http.entity.mime.MinimalField) ByteArrayBuffer(org.apache.http.util.ByteArrayBuffer)

Example 2 with Header

use of org.apache.http.entity.mime.Header in project iaf by ibissource.

the class MultipartEntityBuilder method addPart.

public MultipartEntityBuilder addPart(FormBodyPart bodyPart) {
    if (bodyPart == null) {
        return this;
    }
    if (this.bodyParts == null) {
        this.bodyParts = new ArrayList<FormBodyPart>();
    }
    if (mtom) {
        Header header = bodyPart.getHeader();
        String contentID;
        String fileName = bodyPart.getBody().getFilename();
        header.removeFields("Content-Disposition");
        if (fileName == null) {
            contentID = "<" + bodyPart.getName() + ">";
        } else {
            bodyPart.addField("Content-Disposition", "attachment; name=\"" + bodyPart.getName() + "\"; filename=\"" + fileName + "\"");
            contentID = "<" + fileName + ">";
        }
        bodyPart.addField("Content-ID", contentID);
        if (firstPart == null)
            firstPart = contentID;
    }
    this.bodyParts.add(bodyPart);
    return this;
}
Also used : FormBodyPart(org.apache.http.entity.mime.FormBodyPart) Header(org.apache.http.entity.mime.Header)

Aggregations

FormBodyPart (org.apache.http.entity.mime.FormBodyPart)2 Header (org.apache.http.entity.mime.Header)2 MinimalField (org.apache.http.entity.mime.MinimalField)1 ByteArrayBuffer (org.apache.http.util.ByteArrayBuffer)1