use of org.apache.openmeetings.util.StoredFile in project openmeetings by apache.
the class BackupImport method convertOldPresentation.
private void convertOldPresentation(FileItem fi) {
File f = fi.getOriginal();
if (f != null && f.exists()) {
try {
StoredFile sf = new StoredFile(fi.getHash(), getFileExt(f.getName()), f);
docConverter.convertPDF(fi, sf);
} catch (Exception e) {
log.error("Unexpected exception while converting OLD format presentations", e);
}
}
}
use of org.apache.openmeetings.util.StoredFile in project openmeetings by apache.
the class DocumentConverter method convertPDF.
public ProcessResultList convertPDF(FileItem f, StoredFile sf, ProcessResultList logs) throws Exception {
boolean fullProcessing = !sf.isPdf();
File original = f.getFile(sf.getExt());
File pdf = f.getFile(EXTENSION_PDF);
log.debug("fullProcessing: " + fullProcessing);
if (fullProcessing) {
log.debug("-- running JOD --");
logs.add(doJodConvert(original, pdf));
} else if (!EXTENSION_PDF.equals(sf.getExt())) {
copyFile(original, pdf);
}
log.debug("-- generate page images --");
return imageConverter.convertDocument(f, pdf, logs);
}
use of org.apache.openmeetings.util.StoredFile in project openmeetings by apache.
the class ImageConverter method convertImage.
public ProcessResultList convertImage(BaseFileItem f, StoredFile sf, ProcessResultList logs) throws IOException {
File jpg = f.getFile(EXTENSION_JPG);
if (!sf.isJpg()) {
File img = f.getFile(sf.getExt());
log.debug("##### convertImage destinationFile: " + jpg);
logs.add(convertSingleJpg(img, jpg));
} else if (!jpg.exists()) {
copyFile(f.getFile(sf.getExt()), jpg);
}
logs.add(initSize(f, jpg, JPG_MIME_TYPE));
return logs;
}
use of org.apache.openmeetings.util.StoredFile in project openmeetings by apache.
the class FileProcessor method processFile.
private void processFile(FileItem f, StoredFile sf, File temp, ProcessResultList logs) throws Exception {
try {
File file = f.getFile(sf.getExt());
log.debug("writing file to: {}", file);
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
logs.add(new ProcessResult("Unable to create parent for file: " + file.getCanonicalPath()));
return;
}
switch(f.getType()) {
case Presentation:
log.debug("Office document: {}", file);
copyFile(temp, file);
// convert to pdf, thumbs, swf and xml-description
docConverter.convertPDF(f, sf, logs);
break;
case PollChart:
// NOT implemented yet
log.debug("uploaded chart file");
break;
case Image:
// convert it to JPG
log.debug("##### convert it to JPG: ");
copyFile(temp, file);
imageConverter.convertImage(f, sf);
break;
case Video:
copyFile(temp, file);
videoConverter.convertVideo(f, sf.getExt(), logs);
break;
default:
break;
}
} finally {
f = fileDao.update(f);
log.debug("fileId: {}", f.getId());
}
}
use of org.apache.openmeetings.util.StoredFile in project openmeetings by apache.
the class FileProcessor method processFile.
public ProcessResultList processFile(FileItem f, InputStream is) throws Exception {
ProcessResultList logs = new ProcessResultList();
// Generate a random string to prevent any problems with
// foreign characters and duplicates
String hash = UUID.randomUUID().toString();
File temp = null;
try {
temp = File.createTempFile(String.format("upload_%s", hash), ".tmp");
copyInputStreamToFile(is, temp);
String ext = getFileExt(f.getName());
log.debug("file extension: {}", ext);
// this method moves stream, so temp file MUST be created first
StoredFile sf = new StoredFile(hash, ext, temp);
log.debug("isAsIs: {}", sf.isAsIs());
if (sf.isImage()) {
f.setType(Type.Image);
} else if (sf.isVideo()) {
f.setType(Type.Video);
} else if (sf.isChart()) {
f.setType(Type.PollChart);
} else if (sf.isPdf() || sf.isOffice()) {
f.setType(Type.Presentation);
} else {
throw new UnsupportedFormatException("The file type cannot be converted :: " + f.getName());
}
f.setHash(hash);
processFile(f, sf, temp, logs);
} catch (Exception e) {
log.debug("Error while processing the file", e);
throw e;
} finally {
if (temp != null && temp.exists() && temp.isFile()) {
log.debug("Clean up was successful ? {}", temp.delete());
}
}
return logs;
}
Aggregations