001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.blogs.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.model.FileEntry;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.kernel.webserver.WebServerServletTokenUtil;
022    import com.liferay.portal.model.Image;
023    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
024    import com.liferay.portal.service.ImageLocalServiceUtil;
025    import com.liferay.portal.theme.ThemeDisplay;
026    import com.liferay.portlet.documentlibrary.util.DLUtil;
027    
028    import java.util.Date;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Juan Fern??ndez
033     */
034    public class BlogsEntryImpl extends BlogsEntryBaseImpl {
035    
036            @Override
037            public String getCoverImageURL(ThemeDisplay themeDisplay)
038                    throws PortalException {
039    
040                    long coverImageFileEntryId = getCoverImageFileEntryId();
041    
042                    if (coverImageFileEntryId == 0) {
043                            return null;
044                    }
045    
046                    FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(
047                            coverImageFileEntryId);
048    
049                    return DLUtil.getPreviewURL(
050                            fileEntry, fileEntry.getFileVersion(), themeDisplay,
051                            StringPool.BLANK);
052            }
053    
054            /**
055             * @deprecated As of 7.0.0, replaced by {@link
056             *             #getSmallImageURL(ThemeDisplay)}
057             */
058            @Deprecated
059            @Override
060            public String getEntryImageURL(ThemeDisplay themeDisplay) {
061                    if (!isSmallImage()) {
062                            return null;
063                    }
064    
065                    if (Validator.isNotNull(getSmallImageURL())) {
066                            return getSmallImageURL();
067                    }
068    
069                    return
070                            themeDisplay.getPathImage() + "/blogs/entry?img_id=" +
071                                    getSmallImageId() + "&t=" +
072                                            WebServerServletTokenUtil.getToken(getSmallImageId());
073            }
074    
075            @Override
076            public String getSmallImageType() throws PortalException {
077                    if ((_smallImageType == null) && isSmallImage()) {
078                            Image smallImage = ImageLocalServiceUtil.getImage(
079                                    getSmallImageId());
080    
081                            _smallImageType = smallImage.getType();
082                    }
083    
084                    return _smallImageType;
085            }
086    
087            @Override
088            public String getSmallImageURL(ThemeDisplay themeDisplay)
089                    throws PortalException {
090    
091                    if (Validator.isNotNull(getSmallImageURL())) {
092                            return getSmallImageURL();
093                    }
094    
095                    long smallImageFileEntryId = getSmallImageFileEntryId();
096    
097                    if (smallImageFileEntryId != 0) {
098                            FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(
099                                    smallImageFileEntryId);
100    
101                            return DLUtil.getPreviewURL(
102                                    fileEntry, fileEntry.getFileVersion(), themeDisplay,
103                                    StringPool.BLANK);
104                    }
105    
106                    long smallImageId = getSmallImageId();
107    
108                    if (smallImageId != 0) {
109                            return themeDisplay.getPathImage() + "/blogs/entry?img_id=" +
110                                    getSmallImageId() + "&t=" +
111                                            WebServerServletTokenUtil.getToken(getSmallImageId());
112                    }
113    
114                    return getCoverImageURL(themeDisplay);
115            }
116    
117            @Override
118            public boolean isVisible() {
119                    Date displayDate = getDisplayDate();
120    
121                    if (isApproved() && displayDate.before(new Date())) {
122                            return true;
123                    }
124                    else {
125                            return false;
126                    }
127            }
128    
129            @Override
130            public void setSmallImageType(String smallImageType) {
131                    _smallImageType = smallImageType;
132            }
133    
134            private String _smallImageType;
135    
136    }