WaveletName waveletName, String fileName, ParticipantId creator) throws IOException {
AttachmentData data = store.getAttachment(attachmentId);
if (data == null) {
throw new IOException("No such atachment " + attachmentId.serialise());
}
AttachmentMetadata metadata = new AttachmentMetadataImpl();
metadata.setAttachmentId(attachmentId.serialise());
metadata.setAttachmentUrl(AttachmentServlet.ATTACHMENT_URL + "/" + attachmentId.serialise());
metadata.setThumbnailUrl(AttachmentServlet.THUMBNAIL_URL + "/" + attachmentId.serialise());
metadata.setWaveRef(waveletName2WaveRef(waveletName));
metadata.setFileName(fileName);
String contentType = getMimeType(fileName);
metadata.setMimeType(contentType);
metadata.setSize(data.getSize());
metadata.setCreator((creator != null) ? creator.getAddress() : "");
BufferedImage image = null;
try {
image = ImageIO.read(data.getInputStream());
} catch (IOException ex) {
LOG.log(Level.SEVERE, "Identifying attachment", ex);
}
if (image != null) {
ImageMetadata imageMetadata = new ImageMetadataImpl();
imageMetadata.setWidth(image.getWidth());
imageMetadata.setHeight(image.getHeight());
metadata.setImageMetadata(imageMetadata);
try {
BufferedImage thumbnail = makeThumbnail(image);
storeThumbnail(attachmentId, thumbnail);
ImageMetadata thumbnailMetadata = new ImageMetadataImpl();
thumbnailMetadata.setWidth(thumbnail.getWidth());
thumbnailMetadata.setHeight(thumbnail.getHeight());
metadata.setThumbnailMetadata(thumbnailMetadata);
} catch (IOException ex) {
LOG.log(Level.SEVERE, "Building attachment thumbnail", ex);
}
} else {
ImageMetadata thumbnailMetadata = new ImageMetadataImpl();
thumbnailMetadata.setWidth(THUMBNAIL_PATTERN_WIDTH);
thumbnailMetadata.setHeight(THUMBNAIL_PATTERN_HEIGHT);
metadata.setThumbnailMetadata(thumbnailMetadata);
}
store.storeMetadata(attachmentId, metadata);
return metadata;
}