Search in sources :

Example 1 with FormBodyPartBuilder

use of org.apache.http.entity.mime.FormBodyPartBuilder in project jackrabbit by apache.

the class Utils method addPart.

/**
     *
     * @param paramName
     * @param value
     * @param resolver
     * @throws RepositoryException
     */
static void addPart(String paramName, QValue value, NamePathResolver resolver, List<FormBodyPart> parts, List<QValue> binaries) throws RepositoryException {
    FormBodyPartBuilder builder = FormBodyPartBuilder.create().setName(paramName);
    ContentType ctype = ContentType.create(JcrValueType.contentTypeFromType(value.getType()), DEFAULT_CHARSET);
    FormBodyPart part;
    switch(value.getType()) {
        case PropertyType.BINARY:
            binaries.add(value);
            part = builder.setBody(new InputStreamBody(value.getStream(), ctype)).build();
            break;
        case PropertyType.NAME:
            part = builder.setBody(new StringBody(resolver.getJCRName(value.getName()), ctype)).build();
            break;
        case PropertyType.PATH:
            part = builder.setBody(new StringBody(resolver.getJCRPath(value.getPath()), ctype)).build();
            break;
        default:
            part = builder.setBody(new StringBody(value.getString(), ctype)).build();
    }
    parts.add(part);
}
Also used : FormBodyPart(org.apache.http.entity.mime.FormBodyPart) FormBodyPartBuilder(org.apache.http.entity.mime.FormBodyPartBuilder) ContentType(org.apache.http.entity.ContentType) StringBody(org.apache.http.entity.mime.content.StringBody) InputStreamBody(org.apache.http.entity.mime.content.InputStreamBody)

Aggregations

ContentType (org.apache.http.entity.ContentType)1 FormBodyPart (org.apache.http.entity.mime.FormBodyPart)1 FormBodyPartBuilder (org.apache.http.entity.mime.FormBodyPartBuilder)1 InputStreamBody (org.apache.http.entity.mime.content.InputStreamBody)1 StringBody (org.apache.http.entity.mime.content.StringBody)1