001    /**
002     * Copyright (c) 2000-2013 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.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    }