001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }