private void _generateImages(FileVersion sourceFileVersion, FileVersion destinationFileVersion) throws Exception { InputStream inputStream = null; try { if (sourceFileVersion != null) { copy(sourceFileVersion, destinationFileVersion); return; } if (_hasImages(destinationFileVersion)) { return; } String extension = destinationFileVersion.getExtension(); if (extension.equals("pdf")) { if (destinationFileVersion instanceof LiferayFileVersion) { try { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) destinationFileVersion; File file = liferayFileVersion.getFile(false); _generateImages(destinationFileVersion, file); return; } catch (UnsupportedOperationException uoe) { } } inputStream = destinationFileVersion.getContentStream(false); _generateImages(destinationFileVersion, inputStream); } else if (DocumentConversionUtil.isEnabled()) { inputStream = destinationFileVersion.getContentStream(false); String tempFileId = DLUtil.getTempFileId( destinationFileVersion.getFileEntryId(), destinationFileVersion.getVersion()); File file = DocumentConversionUtil.convert(tempFileId, inputStream, extension, "pdf"); _generateImages(destinationFileVersion, file); } } catch (NoSuchFileEntryException nsfee) { } finally { StreamUtil.cleanUp(inputStream); _fileVersionIds.remove(destinationFileVersion.getFileVersionId()); } }
private void _generateImages(FileVersion fileVersion) throws Exception { try { if (_hasImages(fileVersion)) { return; } String extension = fileVersion.getExtension(); if (extension.equals("pdf")) { if (fileVersion instanceof LiferayFileVersion) { try { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion; File file = liferayFileVersion.getFile(false); _generateImages(fileVersion, file); return; } catch (UnsupportedOperationException uoe) { } } InputStream inputStream = fileVersion.getContentStream(false); _generateImages(fileVersion, inputStream); } else if (DocumentConversionUtil.isEnabled()) { InputStream inputStream = fileVersion.getContentStream(false); String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion()); File file = DocumentConversionUtil.convert(tempFileId, inputStream, extension, "pdf"); _generateImages(fileVersion, file); } } catch (NoSuchFileEntryException nsfee) { } finally { _fileVersionIds.remove(fileVersion.getFileVersionId()); } }
@Override public Object clone() { LiferayFileVersion liferayFileVersion = new LiferayFileVersion(_dlFileVersion, _escapedModel); liferayFileVersion.setCompanyId(getCompanyId()); liferayFileVersion.setCreateDate(getCreateDate()); liferayFileVersion.setGroupId(getGroupId()); liferayFileVersion.setPrimaryKey(getPrimaryKey()); liferayFileVersion.setUserId(getUserId()); liferayFileVersion.setUserName(getUserName()); try { liferayFileVersion.setUserUuid(getUserUuid()); } catch (Exception e) { } liferayFileVersion.setUuid(getUuid()); return liferayFileVersion; }
private void _generateVideo(FileVersion sourceFileVersion, FileVersion destinationFileVersion) throws Exception { if (!XugglerUtil.isEnabled() || _hasVideo(destinationFileVersion)) { return; } InputStream inputStream = null; File[] previewTempFiles = new File[_PREVIEW_TYPES.length]; File videoTempFile = null; try { if (sourceFileVersion != null) { copy(sourceFileVersion, destinationFileVersion); return; } File file = null; if (!hasPreviews(destinationFileVersion) || !hasThumbnails(destinationFileVersion)) { if (destinationFileVersion instanceof LiferayFileVersion) { try { LiferayFileVersion liferayFileVersion = (LiferayFileVersion) destinationFileVersion; file = liferayFileVersion.getFile(false); } catch (UnsupportedOperationException uoe) { } } if (file == null) { inputStream = destinationFileVersion.getContentStream(false); videoTempFile = FileUtil.createTempFile(destinationFileVersion.getExtension()); FileUtil.write(videoTempFile, inputStream); file = videoTempFile; } } if (!hasPreviews(destinationFileVersion)) { String tempFileId = DLUtil.getTempFileId( destinationFileVersion.getFileEntryId(), destinationFileVersion.getVersion()); for (int i = 0; i < _PREVIEW_TYPES.length; i++) { previewTempFiles[i] = getPreviewTempFile(tempFileId, _PREVIEW_TYPES[i]); } try { _generateVideoXuggler(destinationFileVersion, file, previewTempFiles); } catch (Exception e) { _log.error(e, e); } } if (!hasThumbnails(destinationFileVersion)) { try { _generateThumbnailXuggler( destinationFileVersion, file, PropsValues.DL_FILE_ENTRY_PREVIEW_VIDEO_HEIGHT, PropsValues.DL_FILE_ENTRY_PREVIEW_VIDEO_WIDTH); } catch (Exception e) { _log.error(e, e); } } } catch (NoSuchFileEntryException nsfee) { if (_log.isDebugEnabled()) { _log.debug(nsfee, nsfee); } } finally { StreamUtil.cleanUp(inputStream); _fileVersionIds.remove(destinationFileVersion.getFileVersionId()); for (int i = 0; i < previewTempFiles.length; i++) { FileUtil.delete(previewTempFiles[i]); } FileUtil.delete(videoTempFile); } }