Search in sources :

Example 1 with FileVersion

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

the class WebServerServlet method getLastModified.

@Override
protected long getLastModified(HttpServletRequest request) {
    try {
        Date modifiedDate = null;
        Image image = getImage(request, true);
        if (image != null) {
            modifiedDate = image.getModifiedDate();
        } else {
            String path = HttpUtil.fixPath(request.getPathInfo());
            String[] pathArray = StringUtil.split(path, CharPool.SLASH);
            if (pathArray.length == 0) {
                return -1;
            }
            if (pathArray[0].equals("language")) {
                return -1;
            }
            FileEntry fileEntry = null;
            try {
                fileEntry = getFileEntry(pathArray);
            } catch (Exception e) {
            }
            if (fileEntry == null) {
                return -1;
            } else {
                String version = ParamUtil.getString(request, "version");
                if (Validator.isNotNull(version)) {
                    FileVersion fileVersion = fileEntry.getFileVersion(version);
                    modifiedDate = fileVersion.getModifiedDate();
                } else {
                    modifiedDate = fileEntry.getModifiedDate();
                }
            }
        }
        if (modifiedDate == null) {
            modifiedDate = PortalUtil.getUptime();
        }
        return (modifiedDate.getTime() / 1000) * 1000;
    } catch (PrincipalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn(pe, pe);
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
    return -1;
}
Also used : PrincipalException(com.liferay.portal.security.auth.PrincipalException) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Image(com.liferay.portal.model.Image) RenderedImage(java.awt.image.RenderedImage) Date(java.util.Date) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 2 with FileVersion

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

the class LiferayMediaItemService method toMediaItem.

protected MediaItem toMediaItem(FileEntry fileEntry, Set<String> fields, SecurityToken securityToken) throws Exception {
    MediaItem mediaItem = new MediaItemImpl();
    mediaItem.setAlbumId(String.valueOf(fileEntry.getFolderId()));
    mediaItem.setCreated(String.valueOf(fileEntry.getCreateDate()));
    mediaItem.setDescription(fileEntry.getDescription());
    mediaItem.setId(String.valueOf(fileEntry.getFileEntryId()));
    mediaItem.setLastUpdated(String.valueOf(fileEntry.getModifiedDate()));
    mediaItem.setMimeType(MimeTypesUtil.getContentType(StringPool.PERIOD.concat(fileEntry.getExtension())));
    mediaItem.setNumViews(String.valueOf(fileEntry.getReadCount()));
    mediaItem.setTitle(fileEntry.getTitle());
    mediaItem.setType(toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension())));
    String fileEntryURL = ShindigUtil.getFileEntryURL(securityToken.getDomain(), fileEntry.getFileEntryId());
    mediaItem.setUrl(fileEntryURL);
    FileVersion fileVersion = fileEntry.getLatestFileVersion();
    SerializerUtil.copyProperties(fileVersion.getAttributes(), mediaItem, _MEDIA_ITEM_FIELDS);
    return mediaItem;
}
Also used : MediaItemImpl(org.apache.shindig.social.core.model.MediaItemImpl) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion)

Example 3 with FileVersion

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

the class DLPreviewableProcessor method exportPreview.

protected void exportPreview(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathSuffix, String previewType, int fileIndex) throws Exception {
    if (portletDataContext.isPerformDirectBinaryImport()) {
        return;
    }
    FileVersion fileVersion = fileEntry.getFileVersion();
    if (!hasPreview(fileVersion, previewType)) {
        if (_log.isWarnEnabled()) {
            _log.warn("No preview found for file entry " + fileEntry.getFileEntryId());
        }
        return;
    }
    String binPathSegment = null;
    if (fileIndex < 0) {
        binPathSegment = previewType;
    } else {
        binPathSegment = Integer.toString(fileIndex + 1);
    }
    String binPath = getBinPath(portletDataContext, fileEntry, binPathSegment);
    StringBundler sb = new StringBundler(4);
    sb.append("bin-path-preview-");
    sb.append(binPathSegment);
    sb.append("-");
    sb.append(binPathSuffix);
    String binPathName = sb.toString();
    fileEntryElement.addAttribute(binPathName, binPath);
    InputStream is = null;
    try {
        if (fileIndex < 0) {
            is = doGetPreviewAsStream(fileVersion, previewType);
        } else {
            is = doGetPreviewAsStream(fileVersion, fileIndex + 1, previewType);
        }
        exportBinary(portletDataContext, fileEntryElement, fileVersion, is, binPath, binPathName);
    } finally {
        StreamUtil.cleanUp(is);
    }
}
Also used : InputStream(java.io.InputStream) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 4 with FileVersion

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

the class DLPreviewableProcessor method importThumbnail.

protected void importThumbnail(PortletDataContext portletDataContext, FileEntry fileEntry, FileEntry importedFileEntry, Element fileEntryElement, String binPathName, int index) throws Exception {
    if (!isThumbnailEnabled(index)) {
        return;
    }
    if (!portletDataContext.isPerformDirectBinaryImport()) {
        importThumbnailFromLAR(portletDataContext, importedFileEntry, fileEntryElement, binPathName, index);
    } else {
        FileVersion fileVersion = fileEntry.getFileVersion();
        if (!hasThumbnail(fileVersion, index)) {
            return;
        }
        InputStream is = null;
        try {
            is = doGetThumbnailAsStream(fileVersion, index);
            FileVersion importedFileVersion = importedFileEntry.getFileVersion();
            String thumbnailFilePath = getThumbnailFilePath(importedFileVersion, getThumbnailType(importedFileVersion), 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 5 with FileVersion

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

the class DLPreviewableProcessor method exportThumbnail.

protected void exportThumbnail(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathName, int index) throws PortalException, SystemException {
    if (!isThumbnailEnabled(index)) {
        return;
    }
    FileVersion fileVersion = fileEntry.getFileVersion();
    if (!hasThumbnail(fileVersion, index)) {
        if (_log.isWarnEnabled()) {
            _log.warn("No thumbnail found for file entry " + fileEntry.getFileEntryId());
        }
        return;
    }
    InputStream is = null;
    try {
        is = doGetThumbnailAsStream(fileVersion, index);
        String binPath = getBinPath(portletDataContext, fileEntry, index);
        fileEntryElement.addAttribute(binPathName, binPath);
        exportBinary(portletDataContext, fileEntryElement, fileVersion, is, binPath, binPathName);
    } finally {
        StreamUtil.cleanUp(is);
    }
}
Also used : InputStream(java.io.InputStream) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion)

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