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.util.Validator;
019    import com.liferay.portal.model.Image;
020    import com.liferay.portal.service.ImageLocalServiceUtil;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.webserver.WebServerServletTokenUtil;
023    
024    import java.util.Date;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Juan Fern??ndez
029     */
030    public class BlogsEntryImpl extends BlogsEntryBaseImpl {
031    
032            @Override
033            public String getEntryImageURL(ThemeDisplay themeDisplay) {
034                    if (!isSmallImage()) {
035                            return null;
036                    }
037    
038                    if (Validator.isNotNull(getSmallImageURL())) {
039                            return getSmallImageURL();
040                    }
041    
042                    return
043                            themeDisplay.getPathImage() + "/blogs/entry?img_id=" +
044                                    getSmallImageId() + "&t=" +
045                                            WebServerServletTokenUtil.getToken(getSmallImageId());
046            }
047    
048            @Override
049            public String getSmallImageType() throws PortalException {
050                    if ((_smallImageType == null) && isSmallImage()) {
051                            Image smallImage = ImageLocalServiceUtil.getImage(
052                                    getSmallImageId());
053    
054                            _smallImageType = smallImage.getType();
055                    }
056    
057                    return _smallImageType;
058            }
059    
060            @Override
061            public boolean isVisible() {
062                    Date displayDate = getDisplayDate();
063    
064                    if (isApproved() && displayDate.before(new Date())) {
065                            return true;
066                    }
067                    else {
068                            return false;
069                    }
070            }
071    
072            @Override
073            public void setSmallImageType(String smallImageType) {
074                    _smallImageType = smallImageType;
075            }
076    
077            private String _smallImageType;
078    
079    }