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.assetpublisher.util;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.portlet.asset.model.AssetEntry;
024    import com.liferay.portlet.asset.model.AssetRenderer;
025    import com.liferay.portlet.asset.model.AssetRendererFactory;
026    
027    import javax.portlet.PortletURL;
028    
029    /**
030     * @author Juan Fern??ndez
031     */
032    public class AssetPublisherHelperImpl implements AssetPublisherHelper {
033    
034            @Override
035            public String getAssetViewURL(
036                    LiferayPortletRequest liferayPortletRequest,
037                    LiferayPortletResponse liferayPortletResponse, AssetEntry assetEntry) {
038    
039                    PortletURL viewURL = liferayPortletResponse.createRenderURL();
040    
041                    viewURL.setParameter("struts_action", "/asset_publisher/view_content");
042    
043                    String currentURL = PortalUtil.getCurrentURL(liferayPortletRequest);
044    
045                    viewURL.setParameter("redirect", currentURL);
046    
047                    viewURL.setParameter(
048                            "assetEntryId", String.valueOf(assetEntry.getEntryId()));
049    
050                    AssetRendererFactory assetRendererFactory =
051                            assetEntry.getAssetRendererFactory();
052    
053                    AssetRenderer assetRenderer = assetEntry.getAssetRenderer();
054    
055                    viewURL.setParameter("type", assetRendererFactory.getType());
056    
057                    if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
058                            ThemeDisplay themeDisplay =
059                                    (ThemeDisplay)liferayPortletRequest.getAttribute(
060                                            WebKeys.THEME_DISPLAY);
061    
062                            if (assetRenderer.getGroupId() != themeDisplay.getScopeGroupId()) {
063                                    viewURL.setParameter(
064                                            "groupId", String.valueOf(assetRenderer.getGroupId()));
065                            }
066    
067                            viewURL.setParameter("urlTitle", assetRenderer.getUrlTitle());
068                    }
069    
070                    return viewURL.toString();
071            }
072    
073    }