com.liferay.blogs.model.impl.BlogsEntryImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.blogs.model.impl.BlogsEntryImpl.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.blogs.model.impl;

import com.liferay.document.library.kernel.util.DLUtil;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Image;
import com.liferay.portal.kernel.portletfilerepository.PortletFileRepositoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.service.ImageLocalServiceUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.webserver.WebServerServletTokenUtil;

import java.util.Date;

/**
 * @author Brian Wing Shun Chan
 * @author Juan Fernndez
 */
public class BlogsEntryImpl extends BlogsEntryBaseImpl {

    @Override
    public String getCoverImageURL(ThemeDisplay themeDisplay) throws PortalException {

        long coverImageFileEntryId = getCoverImageFileEntryId();

        if (coverImageFileEntryId == 0) {
            return null;
        }

        FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(coverImageFileEntryId);

        return DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK);
    }

    /**
     * @deprecated As of 1.1.0, replaced by {@link
     *             #getSmallImageURL(ThemeDisplay)}
     */
    @Deprecated
    @Override
    public String getEntryImageURL(ThemeDisplay themeDisplay) {
        if (!isSmallImage()) {
            return null;
        }

        if (Validator.isNotNull(getSmallImageURL())) {
            return getSmallImageURL();
        }

        return StringBundler.concat(themeDisplay.getPathImage(), "/blogs/entry?img_id=",
                String.valueOf(getSmallImageId()), "&t=", WebServerServletTokenUtil.getToken(getSmallImageId()));
    }

    @Override
    public String getSmallImageType() throws PortalException {
        if ((_smallImageType == null) && isSmallImage()) {
            Image smallImage = ImageLocalServiceUtil.getImage(getSmallImageId());

            _smallImageType = smallImage.getType();
        }

        return _smallImageType;
    }

    @Override
    public String getSmallImageURL(ThemeDisplay themeDisplay) throws PortalException {

        if (Validator.isNotNull(getSmallImageURL())) {
            return getSmallImageURL();
        }

        long smallImageFileEntryId = getSmallImageFileEntryId();

        if (smallImageFileEntryId != 0) {
            FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(smallImageFileEntryId);

            return DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK);
        }

        long smallImageId = getSmallImageId();

        if (smallImageId != 0) {
            return StringBundler.concat(themeDisplay.getPathImage(), "/blogs/entry?img_id=",
                    String.valueOf(getSmallImageId()), "&t=",
                    WebServerServletTokenUtil.getToken(getSmallImageId()));
        }

        return getCoverImageURL(themeDisplay);
    }

    @Override
    public boolean isVisible() {
        Date displayDate = getDisplayDate();

        if (isApproved() && displayDate.before(new Date())) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void setSmallImageType(String smallImageType) {
        _smallImageType = smallImageType;
    }

    private String _smallImageType;

}