Search in sources :

Example 1 with Image

use of com.liferay.portal.model.Image 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 Image

use of com.liferay.portal.model.Image in project liferay-ide by liferay.

the class WebServerServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    User user = null;
    try {
        user = _getUser(request);
        PrincipalThreadLocal.setName(user.getUserId());
        PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(request));
        PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, true);
        PermissionThreadLocal.setPermissionChecker(permissionChecker);
        if (_lastModified) {
            long lastModified = getLastModified(request);
            if (lastModified > 0) {
                long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
                if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) {
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
            }
            if (lastModified > 0) {
                response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified);
            }
        }
        String path = HttpUtil.fixPath(request.getPathInfo());
        String[] pathArray = StringUtil.split(path, CharPool.SLASH);
        if (pathArray.length == 0) {
            sendGroups(response, user, request.getServletPath() + StringPool.SLASH + path);
        } else {
            if (_PATH_DDL.equals(pathArray[0])) {
                sendDDLRecordFile(request, response, pathArray);
            } else if (Validator.isNumber(pathArray[0])) {
                sendFile(request, response, user, pathArray);
            } else {
                if (isLegacyImageGalleryImageId(request, response)) {
                    return;
                }
                Image image = getImage(request, true);
                if (image != null) {
                    writeImage(image, request, response);
                } else {
                    sendDocumentLibrary(request, response, user, request.getServletPath() + StringPool.SLASH + path, pathArray);
                }
            }
        }
    } catch (NoSuchFileEntryException nsfee) {
        PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response);
    } catch (PrincipalException pe) {
        processPrincipalException(pe, user, request, response);
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);
    }
}
Also used : User(com.liferay.portal.model.User) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) Image(com.liferay.portal.model.Image) RenderedImage(java.awt.image.RenderedImage) 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 3 with Image

use of com.liferay.portal.model.Image in project liferay-ide by liferay.

the class WebServerServlet method convertFileEntry.

protected Image convertFileEntry(boolean smallImage, FileEntry fileEntry) throws PortalException, SystemException {
    try {
        Image image = new ImageImpl();
        image.setModifiedDate(fileEntry.getModifiedDate());
        InputStream is = null;
        if (smallImage) {
            is = ImageProcessorUtil.getThumbnailAsStream(fileEntry.getFileVersion(), ImageProcessorImpl.THUMBNAIL_INDEX_DEFAULT);
        } else {
            is = fileEntry.getContentStream();
        }
        byte[] bytes = FileUtil.getBytes(is);
        image.setTextObj(bytes);
        image.setType(fileEntry.getExtension());
        return image;
    } catch (PortalException pe) {
        throw pe;
    } catch (SystemException se) {
        throw se;
    } catch (Exception e) {
        throw new SystemException(e);
    }
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) InputStream(java.io.InputStream) PortalException(com.liferay.portal.kernel.exception.PortalException) Image(com.liferay.portal.model.Image) RenderedImage(java.awt.image.RenderedImage) ImageImpl(com.liferay.portal.model.impl.ImageImpl) 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 4 with Image

use of com.liferay.portal.model.Image in project liferay-ide by liferay.

the class WebServerServlet method getImage.

protected Image getImage(HttpServletRequest request, boolean getDefault) throws PortalException, SystemException {
    Image image = null;
    long imageId = getImageId(request);
    if (imageId > 0) {
        image = ImageServiceUtil.getImage(imageId);
        String path = GetterUtil.getString(request.getPathInfo());
        if (path.startsWith("/user_female_portrait") || path.startsWith("/user_male_portrait") || path.startsWith("/user_portrait")) {
            image = getUserPortraitImageResized(image, imageId);
        }
    } else {
        String uuid = ParamUtil.getString(request, "uuid");
        long groupId = ParamUtil.getLong(request, "groupId");
        boolean igSmallImage = ParamUtil.getBoolean(request, "igSmallImage");
        java.lang.Object[] test;
        if (Validator_IW.isNotNull(test) && (groupId > 0)) {
            try {
                FileEntry fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
                image = convertFileEntry(igSmallImage, fileEntry);
            } catch (Exception e) {
            }
        }
    }
    if (getDefault) {
        if (image == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Get a default image for " + imageId);
            }
            image = getDefaultImage(request, imageId);
        }
    }
    return image;
}
Also used : 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) 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)

Aggregations

NoSuchGroupException (com.liferay.portal.NoSuchGroupException)4 PortalException (com.liferay.portal.kernel.exception.PortalException)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)4 Image (com.liferay.portal.model.Image)4 PrincipalException (com.liferay.portal.security.auth.PrincipalException)4 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)4 NoSuchFolderException (com.liferay.portlet.documentlibrary.NoSuchFolderException)4 RenderedImage (java.awt.image.RenderedImage)4 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)2 FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)1 User (com.liferay.portal.model.User)1 ImageImpl (com.liferay.portal.model.impl.ImageImpl)1 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1