Search in sources :

Example 6 with FileVersion

use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.

the class DLPreviewableProcessor method importPreview.

protected void importPreview(PortletDataContext portletDataContext, FileEntry fileEntry, FileEntry importedFileEntry, Element fileEntryElement, String binPathSuffix, String previewType, int fileIndex) throws Exception {
    if (!portletDataContext.isPerformDirectBinaryImport()) {
        importPreviewFromLAR(portletDataContext, importedFileEntry, fileEntryElement, binPathSuffix, previewType, fileIndex);
    } else {
        FileVersion importedFileVersion = importedFileEntry.getFileVersion();
        String previewFilePath = getPreviewFilePath(importedFileVersion, previewType);
        FileVersion fileVersion = fileEntry.getFileVersion();
        if (!hasPreview(fileVersion, previewType)) {
            return;
        }
        InputStream is = null;
        try {
            if (fileIndex < 0) {
                is = doGetPreviewAsStream(fileVersion, previewType);
            } else {
                is = doGetPreviewAsStream(fileVersion, fileIndex, previewType);
            }
            addFileToStore(portletDataContext.getCompanyId(), PREVIEW_PATH, previewFilePath, is);
        } finally {
            StreamUtil.cleanUp(is);
        }
    }
}
Also used : InputStream(java.io.InputStream) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion)

Example 7 with FileVersion

use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.

the class DLPreviewableProcessor method importThumbnailFromLAR.

protected void importThumbnailFromLAR(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathName, int index) throws Exception {
    FileVersion fileVersion = fileEntry.getFileVersion();
    String binPath = fileEntryElement.attributeValue(binPathName);
    InputStream is = null;
    try {
        is = portletDataContext.getZipEntryAsInputStream(binPath);
        if (is == null) {
            return;
        }
        String thumbnailFilePath = getThumbnailFilePath(fileVersion, getThumbnailType(fileVersion), index);
        addFileToStore(portletDataContext.getCompanyId(), THUMBNAIL_PATH, thumbnailFilePath, is);
    } finally {
        StreamUtil.cleanUp(is);
    }
}
Also used : InputStream(java.io.InputStream) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion)

Example 8 with FileVersion

use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.

the class DLPreviewableProcessor method exportThumbnails.

protected void exportThumbnails(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathSuffix) throws PortalException, SystemException {
    FileVersion fileVersion = fileEntry.getFileVersion();
    if (!isSupported(fileVersion)) {
        return;
    }
    if (!portletDataContext.isPerformDirectBinaryImport()) {
        exportThumbnail(portletDataContext, fileEntry, fileEntryElement, "bin-path-thumbnail-default-" + binPathSuffix, THUMBNAIL_INDEX_DEFAULT);
        exportThumbnail(portletDataContext, fileEntry, fileEntryElement, "bin-path-thumbnail-custom-1-" + binPathSuffix, THUMBNAIL_INDEX_CUSTOM_1);
        exportThumbnail(portletDataContext, fileEntry, fileEntryElement, "bin-path-thumbnail-custom-2-" + binPathSuffix, THUMBNAIL_INDEX_CUSTOM_2);
    }
}
Also used : FileVersion(com.liferay.portal.kernel.repository.model.FileVersion)

Example 9 with FileVersion

use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-blade-samples by liferay.

the class BladeActionConfigurationIcon method getURL.

public String getURL(PortletRequest portletRequest, PortletResponse portletResponse) {
    HttpServletRequest servletRequest = _portal.getHttpServletRequest(portletRequest);
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    FileEntry fileEntry = _retrieveFile(servletRequest);
    PortletURL portletURL = PortletURLFactoryUtil.create(servletRequest, "blade_document_action_portlet_BladeDocumentActionPortlet", themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
    String fileName = fileEntry.getFileName();
    String mimeType = fileEntry.getMimeType();
    String version = fileEntry.getVersion();
    String createdDate = String.valueOf(fileEntry.getCreateDate());
    String createdUserName = fileEntry.getUserName();
    String statusLabel = null;
    try {
        FileVersion fileVersion = fileEntry.getLatestFileVersion();
        int status = fileVersion.getStatus();
        statusLabel = WorkflowConstants.getStatusLabel(status);
    } catch (PortalException pe) {
        _log.log(LogService.LOG_ERROR, pe.getMessage(), pe);
    }
    portletURL.setParameter("fileName", fileName);
    portletURL.setParameter("mimeType", mimeType);
    portletURL.setParameter("version", version);
    portletURL.setParameter("statusLabel", statusLabel);
    portletURL.setParameter("createdDate", createdDate);
    portletURL.setParameter("createdUserName", createdUserName);
    try {
        portletURL.setWindowState(LiferayWindowState.POP_UP);
    } catch (WindowStateException wse) {
        _log.log(LogService.LOG_ERROR, wse.getMessage(), wse);
    }
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("javascript:Liferay.Util.openWindow(");
    stringBuilder.append("{dialog: {cache: false,width:800,modal: true},");
    stringBuilder.append("title: 'basic information',id: ");
    stringBuilder.append("'testPopupIdUnique',uri: '");
    stringBuilder.append(portletURL.toString() + "'});");
    return stringBuilder.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WindowStateException(javax.portlet.WindowStateException) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PortalException(com.liferay.portal.kernel.exception.PortalException) ThemeDisplay(com.liferay.portal.kernel.theme.ThemeDisplay) PortletURL(javax.portlet.PortletURL)

Example 10 with FileVersion

use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.

the class WebServerServlet method sendFile.

protected void sendFile(HttpServletRequest request, HttpServletResponse response, User user, String[] pathArray) throws Exception {
    FileEntry fileEntry = getFileEntry(pathArray);
    if (fileEntry == null) {
        throw new NoSuchFileEntryException();
    }
    String version = ParamUtil.getString(request, "version");
    if (Validator.isNull(version)) {
        if (Validator.isNotNull(fileEntry.getVersion())) {
            version = fileEntry.getVersion();
        }
    }
    String tempFileId = DLUtil.getTempFileId(fileEntry.getFileEntryId(), version);
    FileVersion fileVersion = fileEntry.getFileVersion(version);
    String fileName = fileVersion.getTitle();
    String extension = fileVersion.getExtension();
    if (Validator.isNotNull(extension) && !fileName.endsWith(StringPool.PERIOD + extension)) {
        fileName += StringPool.PERIOD + extension;
    }
    boolean converted = false;
    String targetExtension = ParamUtil.getString(request, "targetExtension");
    int imageThumbnail = ParamUtil.getInteger(request, "imageThumbnail");
    int documentThumbnail = ParamUtil.getInteger(request, "documentThumbnail");
    int previewFileIndex = ParamUtil.getInteger(request, "previewFileIndex");
    boolean audioPreview = ParamUtil.getBoolean(request, "audioPreview");
    boolean videoPreview = ParamUtil.getBoolean(request, "videoPreview");
    int videoThumbnail = ParamUtil.getInteger(request, "videoThumbnail");
    InputStream inputStream = null;
    long contentLength = 0;
    if ((imageThumbnail > 0) && (imageThumbnail <= 3)) {
        fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(fileVersion.getExtension());
        int thumbnailIndex = imageThumbnail - 1;
        inputStream = ImageProcessorUtil.getThumbnailAsStream(fileVersion, thumbnailIndex);
        contentLength = ImageProcessorUtil.getThumbnailFileSize(fileVersion, thumbnailIndex);
        converted = true;
    } else if ((documentThumbnail > 0) && (documentThumbnail <= 3)) {
        fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(PDFProcessorImpl.THUMBNAIL_TYPE);
        int thumbnailIndex = documentThumbnail - 1;
        inputStream = PDFProcessorUtil.getThumbnailAsStream(fileVersion, thumbnailIndex);
        contentLength = PDFProcessorUtil.getThumbnailFileSize(fileVersion, thumbnailIndex);
        converted = true;
    } else if (previewFileIndex > 0) {
        fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(PDFProcessorImpl.PREVIEW_TYPE);
        inputStream = PDFProcessorUtil.getPreviewAsStream(fileVersion, previewFileIndex);
        contentLength = PDFProcessorUtil.getPreviewFileSize(fileVersion, previewFileIndex);
        converted = true;
    } else if (audioPreview) {
        fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(AudioProcessor.PREVIEW_TYPE);
        inputStream = AudioProcessorUtil.getPreviewAsStream(fileVersion);
        contentLength = AudioProcessorUtil.getPreviewFileSize(fileVersion);
        converted = true;
    } else if (videoPreview) {
        String type = ParamUtil.getString(request, "type");
        fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(type);
        inputStream = VideoProcessorUtil.getPreviewAsStream(fileVersion, type);
        contentLength = VideoProcessorUtil.getPreviewFileSize(fileVersion, type);
        response.setHeader(HttpHeaders.ACCEPT_RANGES, HttpHeaders.ACCEPT_RANGES_BYTES_VALUE);
        List<Range> ranges = null;
        try {
            ranges = ServletResponseUtil.getRanges(request, response, contentLength);
        } catch (IOException ioe) {
            if (_log.isErrorEnabled()) {
                _log.error(ioe);
            }
            response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes */" + contentLength);
            response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
            return;
        }
        if ((ranges != null) && (ranges.size() > 0)) {
            if (_log.isDebugEnabled()) {
                _log.debug("Video range requested");
            }
            String contentType = MimeTypesUtil.getContentType(fileName);
            ServletResponseUtil.write(request, response, fileName, ranges, inputStream, contentLength, contentType);
            return;
        }
        converted = true;
    } else if ((videoThumbnail > 0) && (videoThumbnail <= 3)) {
        fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(VideoProcessorImpl.THUMBNAIL_TYPE);
        int thumbnailIndex = videoThumbnail - 1;
        inputStream = VideoProcessorUtil.getThumbnailAsStream(fileVersion, thumbnailIndex);
        contentLength = VideoProcessorUtil.getThumbnailFileSize(fileVersion, thumbnailIndex);
        converted = true;
    } else {
        inputStream = fileVersion.getContentStream(true);
        contentLength = fileVersion.getSize();
        if (Validator.isNotNull(targetExtension)) {
            File convertedFile = DocumentConversionUtil.convert(tempFileId, inputStream, extension, targetExtension);
            if (convertedFile != null) {
                fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(targetExtension);
                inputStream = Files.newInputStream(convertedFile.toPath());
                contentLength = convertedFile.length();
                converted = true;
            }
        }
    }
    String contentType = null;
    if (converted) {
        contentType = MimeTypesUtil.getContentType(fileName);
    } else {
        contentType = fileVersion.getMimeType();
    }
    ServletResponseUtil.sendFile(request, response, fileName, inputStream, contentLength, contentType);
}
Also used : InputStream(java.io.InputStream) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) IOException(java.io.IOException) Range(com.liferay.portal.kernel.servlet.Range) File(java.io.File)

Aggregations

FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)11 InputStream (java.io.InputStream)7 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2 StringBundler (com.liferay.portal.kernel.util.StringBundler)2 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)2 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)2 IOException (java.io.IOException)2 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)1 Range (com.liferay.portal.kernel.servlet.Range)1 ThemeDisplay (com.liferay.portal.kernel.theme.ThemeDisplay)1 Image (com.liferay.portal.model.Image)1 PrincipalException (com.liferay.portal.security.auth.PrincipalException)1 NoSuchFolderException (com.liferay.portlet.documentlibrary.NoSuchFolderException)1 RenderedImage (java.awt.image.RenderedImage)1 File (java.io.File)1 Date (java.util.Date)1 PortletURL (javax.portlet.PortletURL)1