MediaFileDirectory mdir =
fileMgr.getMediaFileDirectoryByPath(website, justPath);
if (mdir.hasMediaFile(fileName)) {
throw new AtomException("Duplicate file name");
}
if (path.length() > 0) path = path + File.separator;
FileInputStream fis = new FileInputStream(tempFile);
MediaFile mf = new MediaFile();
mf.setDirectory(mdir);
mf.setWeblog(website);
mf.setName(fileName);
mf.setOriginalPath(justPath);
mf.setContentType(contentType);
mf.setInputStream(fis);
mf.setLength(tempFile.length());
RollerMessages errors = new RollerMessages();
fileMgr.createMediaFile(website, mf, errors);
if (errors.getErrorCount() > 0) {
throw new AtomException(errors.toString());
}
roller.flush();
fis.close();
MediaFile stored = fileMgr.getMediaFile(mf.getId());
Entry mediaEntry = createAtomResourceEntry(website, stored);
for (Iterator it = mediaEntry.getOtherLinks().iterator(); it.hasNext();) {
Link link = (Link)it.next();
if ("edit".equals(link.getRel())) {
log.debug("Exiting");
return mediaEntry;
}
}
log.error("ERROR: no edit link found in saved media entry");
} catch (FileIOException fie) {
throw new AtomException(
"File upload disabled, over-quota or other error", fie);
} finally {
if (tempFile != null) tempFile.delete();
}
}
throw new AtomException("Error saving media entry");
} catch (WebloggerException re) {
throw new AtomException("Posting media", re);
} catch (IOException ioe) {
throw new AtomException("Posting media", ioe);
}
}