* encoded Multipoart MIME
*/
private ContentItem createContentItem(UriRef id, MGraph metadata, FileItemStream content,Set<String> parsedContentParts) throws IOException, FileUploadException {
MediaType partContentType = MediaType.valueOf(content.getContentType());
ContentItem contentItem = null;
ContentItemFactory ciFactory = getContentItemFactory();
if(MULTIPART.isCompatible(partContentType)){
//multiple contentParts are parsed
FileItemIterator contentPartIterator = fu.getItemIterator(
new MessageBodyReaderContext(
content.openStream(), partContentType));
while(contentPartIterator.hasNext()){
FileItemStream fis = contentPartIterator.next();
if(contentItem == null){
log.debug("create ContentItem {} for content (type:{})",
id,content.getContentType());
contentItem = ciFactory.createContentItem(id,
new StreamSource(fis.openStream(),fis.getContentType()),
metadata);
} else {
Blob blob = ciFactory.createBlob(new StreamSource(fis.openStream(), fis.getContentType()));
UriRef contentPartId = null;
if(fis.getFieldName() != null && !fis.getFieldName().isEmpty()){
contentPartId = new UriRef(fis.getFieldName());
} else {
//generating a random ID might break metadata
//TODO maybe we should throw an exception instead
contentPartId = new UriRef("urn:contentpart:"+ randomUUID());
}
log.debug(" ... add Blob {} to ContentItem {} with content (type:{})",
new Object[]{contentPartId, id, fis.getContentType()});
contentItem.addPart(contentPartId, blob);
parsedContentParts.add(contentPartId.getUnicodeString());
}
}
} else {
log.debug("create ContentItem {} for content (type:{})",
id,content.getContentType());
contentItem = ciFactory.createContentItem(id,
new StreamSource(content.openStream(),content.getContentType()),
metadata);
}
//add the URI of the main content to the parsed contentParts
parsedContentParts.add(contentItem.getPartUri(0).getUnicodeString());