Search in sources :

Example 1 with StoredFile

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);
        }
    }
}
Also used : StoredFile(org.apache.openmeetings.util.StoredFile) StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) RoomFile(org.apache.openmeetings.db.entity.room.RoomFile) IOException(java.io.IOException)

Example 2 with StoredFile

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);
}
Also used : File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) StoredFile(org.apache.openmeetings.util.StoredFile)

Example 3 with StoredFile

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;
}
Also used : StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile)

Example 4 with StoredFile

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());
    }
}
Also used : ProcessResult(org.apache.openmeetings.util.process.ProcessResult) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) StoredFile(org.apache.openmeetings.util.StoredFile)

Example 5 with StoredFile

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;
}
Also used : UnsupportedFormatException(org.apache.tika.exception.UnsupportedFormatException) StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) StoredFile(org.apache.openmeetings.util.StoredFile) UnsupportedFormatException(org.apache.tika.exception.UnsupportedFormatException) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList)

Aggregations

File (java.io.File)6 StoredFile (org.apache.openmeetings.util.StoredFile)6 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)4 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)2 IOException (java.io.IOException)1 RoomFile (org.apache.openmeetings.db.entity.room.RoomFile)1 ProcessResult (org.apache.openmeetings.util.process.ProcessResult)1 ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)1 UnsupportedFormatException (org.apache.tika.exception.UnsupportedFormatException)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)1 UploadProgressBar (org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar)1 Form (org.apache.wicket.markup.html.form.Form)1 FileUpload (org.apache.wicket.markup.html.form.upload.FileUpload)1