mediaType.getType(),mediaType.getSubtype(),charset.toString(),CONTENT_ITEM_BOUNDARY);
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE,contentType);
HttpMultipart entity = new HttpMultipart("from-data", charset ,CONTENT_ITEM_BOUNDARY);
//(2) serialising the metadata
if(!isOmitMetadata(properties)){
entity.addBodyPart(new FormBodyPart("metadata", new ClerezzaContentBody(
ci.getUri().getUnicodeString(), ci.getMetadata(),
rdfFormat)));
}
//(3) serialising the Content (Bloby)
//(3.a) Filter based on parameter
List<Entry<UriRef,Blob>> includedBlobs = filterBlobs(ci, properties);
//(3.b) Serialise the filtered
if(!includedBlobs.isEmpty()) {
HttpMultipart content = new HttpMultipart("alternate", UTF8 ,"contentParts");
for(Entry<UriRef,Blob> entry : includedBlobs){
content.addBodyPart(new FormBodyPart(entry.getKey().getUnicodeString(),
new BlobContentBody(entry.getValue()))); //no file name
}
//add all the blobs
entity.addBodyPart(new FormBodyPart("content",new MultipartContentBody(content, null)));
} //else no content to include
Set<String> includeContentParts = getIncludedContentPartURIs(properties);
if(includeContentParts != null){
//(4) serialise EnhancementProperties
if(includeContentParts.isEmpty() || includeContentParts.contains(
ENHANCEMENT_PROPERTIES_URI.getUnicodeString())) {
JSONObject object;
try {
object = toJson(properties);
} catch (JSONException e) {
throw new WebApplicationException(e,
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Unable to convert EnhancementProperties to " +
"JSON (values : "+properties+")!").build());
}
entity.addBodyPart(new FormBodyPart(
ENHANCEMENT_PROPERTIES_URI.getUnicodeString(),
new StringBody(object.toString(),MediaType.APPLICATION_JSON,UTF8)));
}
//(5) additional RDF metadata stored in contentParts
for(Entry<UriRef,TripleCollection> entry : getContentParts(ci, TripleCollection.class).entrySet()){
if(includeContentParts.isEmpty() || includeContentParts.contains(
entry.getKey())){
entity.addBodyPart(new FormBodyPart(entry.getKey().getUnicodeString(),
new ClerezzaContentBody(null, //no file name
entry.getValue(),rdfFormat)));
} // else ignore this content part
}
}