myValidate();
if (!hasActionErrors()) {
MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
RollerMessages errors = new RollerMessages();
List<MediaFile> uploaded = new ArrayList();
File[] uploads = getUploadedFiles();
if (uploads != null && uploads.length > 0) {
// loop over uploaded files and try saving them
for (int i = 0; i < uploads.length; i++) {
// skip null files
if (uploads[i] == null || !uploads[i].exists()) {
continue;
}
try {
MediaFile mediaFile = new MediaFile();
bean.copyTo(mediaFile);
String fileName = getUploadedFilesFileName()[i];
int terminated = fileName.indexOf("\000");
if (terminated != -1) {
// disallow sneaky null terminated strings
fileName = fileName.substring(0, terminated).trim();
}
// make sure fileName is valid
if (fileName.indexOf("/") != -1 ||
fileName.indexOf("\\") != -1 ||
fileName.indexOf("..") != -1) {
addError("uploadFiles.error.badPath", fileName);
continue;
}
mediaFile.setName( fileName);
mediaFile.setDirectory( getDirectory());
mediaFile.setWeblog( getActionWeblog());
mediaFile.setLength( this.uploadedFiles[i].length());
mediaFile.setInputStream(new FileInputStream(this.uploadedFiles[i]));
mediaFile.setContentType(this.uploadedFilesContentType[i]);
// insome cases Struts2 is not able to guess the content
// type correctly and assigns the default, which is
// octet-stream. So in cases where we see octet-stream
// we double check and see if we can guess the content
// type via the Java MIME type facilities.
mediaFile.setContentType(this.uploadedFilesContentType[i]);
if (mediaFile.getContentType() == null
|| mediaFile.getContentType().endsWith("/octet-stream")) {
String ctype = Utilities.getContentTypeFromFileName(mediaFile.getName());
if (null != ctype) {
mediaFile.setContentType(ctype);
}
}
manager.createMediaFile(getActionWeblog(), mediaFile, errors);
WebloggerFactory.getWeblogger().flush();
if (mediaFile.isImageFile()) {
newImages.add(mediaFile);
} else {