001    /**
002     * Copyright (c) 2000-2010 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.imagegallery.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortletKeys;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.asset.model.AssetRenderer;
026    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
027    import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
028    import com.liferay.portlet.imagegallery.model.IGImage;
029    import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
030    import com.liferay.portlet.imagegallery.service.permission.IGPermission;
031    
032    import javax.portlet.PortletURL;
033    
034    /**
035     * @author Julio Camarero
036     * @author Juan Fernández
037     */
038    public class IGImageAssetRendererFactory extends BaseAssetRendererFactory {
039    
040            public static final String CLASS_NAME = IGImage.class.getName();
041    
042            public static final String TYPE = "image";
043    
044            public AssetRenderer getAssetRenderer(long classPK, int type)
045                    throws PortalException, SystemException {
046    
047                    IGImage image = IGImageLocalServiceUtil.getImage(classPK);
048    
049                    return new IGImageAssetRenderer(image);
050            }
051    
052            public String getClassName() {
053                    return CLASS_NAME;
054            }
055    
056            public String getType() {
057                    return TYPE;
058            }
059    
060            public PortletURL getURLAdd(
061                    LiferayPortletRequest liferayPortletRequest,
062                    LiferayPortletResponse liferayPortletResponse) {
063    
064                    ThemeDisplay themeDisplay =
065                            (ThemeDisplay)liferayPortletRequest.getAttribute(
066                                    WebKeys.THEME_DISPLAY);
067    
068                    PortletURL addAssetURL = null;
069    
070                    if (IGPermission.contains(
071                                    themeDisplay.getPermissionChecker(),
072                                    themeDisplay.getScopeGroupId(), ActionKeys.ADD_IMAGE)) {
073    
074                            addAssetURL = liferayPortletResponse.createRenderURL(
075                                    PortletKeys.IMAGE_GALLERY);
076    
077                            addAssetURL.setParameter(
078                                    "struts_action", "/image_gallery/edit_image");
079                            addAssetURL.setParameter(
080                                    "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
081                            addAssetURL.setParameter(
082                                    "folderId",
083                                    String.valueOf(
084                                            AssetPublisherUtil.getRecentFolderId(
085                                                    liferayPortletRequest, CLASS_NAME)));
086                            addAssetURL.setParameter("uploader", "classic");
087                    }
088    
089                    return addAssetURL;
090            }
091    
092            protected String getIconPath(ThemeDisplay themeDisplay) {
093                    return themeDisplay.getPathThemeImages() + "/file_system/small/bmp.png";
094            }
095    
096    }