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