Example usage for com.liferay.portal.util PropsValues DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED

List of usage examples for com.liferay.portal.util PropsValues DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED.

Prototype

boolean DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED

To view the source code for com.liferay.portal.util PropsValues DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED.

Click Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.util.AudioProcessorImpl.java

License:Open Source License

private void _generateAudioXuggler(FileVersion fileVersion, File srcFile, File destFile) throws Exception {

    StopWatch stopWatch = null;/*from w  w w .  ja  va 2 s . c  om*/

    if (_log.isInfoEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();
    }

    try {
        if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) {
            ProcessCallable<String> processCallable = new LiferayAudioProcessCallable(
                    ServerDetector.getServerId(), PropsUtil.get(PropsKeys.LIFERAY_HOME),
                    Log4JUtil.getCustomLogSettings(), srcFile.getCanonicalPath(), destFile.getCanonicalPath());

            ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath());
        } else {
            LiferayConverter liferayConverter = new LiferayAudioConverter(srcFile.getCanonicalPath(),
                    destFile.getCanonicalPath());

            liferayConverter.convert();
        }
    } catch (Exception e) {
        _log.error(e, e);
    }

    addFileToStore(fileVersion.getCompanyId(), PREVIEW_PATH, getPreviewFilePath(fileVersion), destFile);

    if (_log.isInfoEnabled()) {
        _log.info("Xuggler generated a preview audio for " + fileVersion.getTitle() + " in " + stopWatch);
    }
}

From source file:com.liferay.portlet.documentlibrary.util.PDFProcessorImpl.java

License:Open Source License

private void _generateImagesIM(FileVersion fileVersion, File file, boolean thumbnail) throws Exception {

    // Generate images

    String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    IMOperation imOperation = new IMOperation();

    imOperation.alpha("off");

    imOperation.density(PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_DPI,
            PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_DPI);

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_HEIGHT != 0) {
        imOperation.adaptiveResize(PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_WIDTH,
                PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_HEIGHT);
    } else {/*from w ww  .  ja v a2s .co m*/
        imOperation.adaptiveResize(PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_WIDTH);
    }

    imOperation.depth(PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_DEPTH);

    if (thumbnail) {
        imOperation.addImage(file.getPath() + "[0]");
        imOperation.addImage(getThumbnailTempFilePath(tempFileId));
    } else {
        imOperation.addImage(file.getPath());
        imOperation.addImage(getPreviewTempFilePath(tempFileId, -1));
    }

    if (_log.isInfoEnabled()) {
        _log.info("Excecuting command 'convert " + imOperation + "'");
    }

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) {
        ProcessCallable<String> processCallable = new ImageMagickProcessCallable(_globalSearchPath,
                imOperation.getCmdArgs());

        ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath());
    } else {
        _convertCmd.run(imOperation);
    }

    // Store images

    if (thumbnail) {
        File thumbnailTempFile = getThumbnailTempFile(tempFileId);

        try {
            storeThumbnailImages(fileVersion, thumbnailTempFile);
        } finally {
            FileUtil.delete(thumbnailTempFile);
        }
    } else {

        // ImageMagick converts single page PDFs without appending an
        // index. Rename file for consistency.

        File singlePagePreviewFile = getPreviewTempFile(tempFileId, -1);

        if (singlePagePreviewFile.exists()) {
            singlePagePreviewFile.renameTo(getPreviewTempFile(tempFileId, 1));
        }

        int total = getPreviewTempFileCount(fileVersion);

        for (int i = 0; i < total; i++) {
            File previewTempFile = getPreviewTempFile(tempFileId, i + 1);

            try {
                addFileToStore(fileVersion.getCompanyId(), PREVIEW_PATH, getPreviewFilePath(fileVersion, i + 1),
                        previewTempFile);
            } finally {
                FileUtil.delete(previewTempFile);
            }
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java

License:Open Source License

private void _generateThumbnailXuggler(FileVersion fileVersion, File file, int height, int width)
        throws Exception {

    StopWatch stopWatch = null;//from  w w  w  . ja v  a 2s .  c o  m

    if (_log.isInfoEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();
    }

    String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    File thumbnailTempFile = getThumbnailTempFile(tempFileId);

    try {
        try {
            if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) {
                ProcessCallable<String> processCallable = new LiferayVideoThumbnailProcessCallable(
                        ServerDetector.getServerId(), PropsUtil.get(PropsKeys.LIFERAY_HOME),
                        Log4JUtil.getCustomLogSettings(), file.getCanonicalPath(), thumbnailTempFile,
                        THUMBNAIL_TYPE, height, width,
                        PropsValues.DL_FILE_ENTRY_THUMBNAIL_VIDEO_FRAME_PERCENTAGE);

                ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath());
            } else {
                LiferayConverter liferayConverter = new LiferayVideoThumbnailConverter(file.getCanonicalPath(),
                        thumbnailTempFile, THUMBNAIL_TYPE, height, width,
                        PropsValues.DL_FILE_ENTRY_THUMBNAIL_VIDEO_FRAME_PERCENTAGE);

                liferayConverter.convert();
            }
        } catch (Exception e) {
            _log.error(e, e);
        }

        storeThumbnailImages(fileVersion, thumbnailTempFile);

        if (_log.isInfoEnabled()) {
            _log.info("Xuggler generated a thumbnail for " + fileVersion.getTitle() + " in " + stopWatch);
        }
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        FileUtil.delete(thumbnailTempFile);
    }
}

From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java

License:Open Source License

private void _generateVideoXuggler(FileVersion fileVersion, File srcFile, File destFile, String containerType)
        throws Exception {

    if (!_isGeneratePreview(fileVersion, containerType)) {
        return;/* w  ww  . j  a  v  a2  s.  c  o  m*/
    }

    StopWatch stopWatch = null;

    if (_log.isInfoEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();
    }

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) {
        ProcessCallable<String> processCallable = new LiferayVideoProcessCallable(ServerDetector.getServerId(),
                PropsUtil.get(PropsKeys.LIFERAY_HOME), Log4JUtil.getCustomLogSettings(),
                srcFile.getCanonicalPath(), destFile.getCanonicalPath(), FileUtil.createTempFileName(),
                PropsUtil.getProperties(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO, false),
                PropsUtil.getProperties(PropsKeys.XUGGLER_FFPRESET, true));

        ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath());
    } else {
        LiferayConverter liferayConverter = new LiferayVideoConverter(srcFile.getCanonicalPath(),
                destFile.getCanonicalPath(), FileUtil.createTempFileName(),
                PropsUtil.getProperties(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO, false),
                PropsUtil.getProperties(PropsKeys.XUGGLER_FFPRESET, true));

        liferayConverter.convert();
    }

    addFileToStore(fileVersion.getCompanyId(), PREVIEW_PATH, getPreviewFilePath(fileVersion, containerType),
            destFile);

    if (_log.isInfoEnabled()) {
        _log.info("Xuggler generated a " + containerType + " preview video for " + fileVersion.getTitle()
                + " in " + stopWatch);
    }
}