001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.exception.SystemException;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.model.Image;
021    import com.liferay.portal.service.ImageLocalServiceUtil;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.webserver.WebServerServletTokenUtil;
024    import com.liferay.portlet.trash.model.TrashEntry;
025    import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
026    
027    import java.util.Date;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Juan Fern??ndez
032     */
033    public class BlogsEntryImpl extends BlogsEntryBaseImpl {
034    
035            public BlogsEntryImpl() {
036            }
037    
038            @Override
039            public String getEntryImageURL(ThemeDisplay themeDisplay) {
040                    if (!isSmallImage()) {
041                            return null;
042                    }
043    
044                    if (Validator.isNotNull(getSmallImageURL())) {
045                            return getSmallImageURL();
046                    }
047    
048                    return
049                            themeDisplay.getPathImage() + "/blogs/entry?img_id=" +
050                                    getSmallImageId() + "&t=" +
051                                            WebServerServletTokenUtil.getToken(getSmallImageId());
052            }
053    
054            @Override
055            public String getSmallImageType() throws PortalException, SystemException {
056                    if ((_smallImageType == null) && isSmallImage()) {
057                            Image smallImage = ImageLocalServiceUtil.getImage(
058                                    getSmallImageId());
059    
060                            _smallImageType = smallImage.getType();
061                    }
062    
063                    return _smallImageType;
064            }
065    
066            @Override
067            public boolean isInTrashExplicitly() throws SystemException {
068                    if (!isInTrash()) {
069                            return false;
070                    }
071    
072                    TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(
073                            getModelClassName(), getTrashEntryClassPK());
074    
075                    if (trashEntry != null) {
076                            return true;
077                    }
078    
079                    return false;
080            }
081    
082            @Override
083            public boolean isVisible() {
084                    Date displayDate = getDisplayDate();
085    
086                    if (isApproved() && displayDate.before(new Date())) {
087                            return true;
088                    }
089                    else {
090                            return false;
091                    }
092            }
093    
094            @Override
095            public void setSmallImageType(String smallImageType) {
096                    _smallImageType = smallImageType;
097            }
098    
099            private String _smallImageType;
100    
101    }