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