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    
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            @Override
037            public String getEntryImageURL(ThemeDisplay themeDisplay) {
038                    if (!isSmallImage()) {
039                            return null;
040                    }
041    
042                    if (Validator.isNotNull(getSmallImageURL())) {
043                            return getSmallImageURL();
044                    }
045    
046                    return
047                            themeDisplay.getPathImage() + "/blogs/entry?img_id=" +
048                                    getSmallImageId() + "&t=" +
049                                            WebServerServletTokenUtil.getToken(getSmallImageId());
050            }
051    
052            @Override
053            public String getSmallImageType() throws PortalException, SystemException {
054                    if ((_smallImageType == null) && isSmallImage()) {
055                            Image smallImage = ImageLocalServiceUtil.getImage(
056                                    getSmallImageId());
057    
058                            _smallImageType = smallImage.getType();
059                    }
060    
061                    return _smallImageType;
062            }
063    
064            @Override
065            public boolean isVisible() {
066                    Date displayDate = getDisplayDate();
067    
068                    if (isApproved() && displayDate.before(new Date())) {
069                            return true;
070                    }
071                    else {
072                            return false;
073                    }
074            }
075    
076            @Override
077            public void setSmallImageType(String smallImageType) {
078                    _smallImageType = smallImageType;
079            }
080    
081            private String _smallImageType;
082    
083    }